xref: /libCEED/backends/magma/ceed-magma-det.c (revision e64bb3f3ed2986a0c10dec3b47522d734c6e367d)
1 // Copyright (c) 2017-2022, Lawrence Livermore National Security, LLC and other CEED contributors.
2 // All Rights Reserved. See the top-level LICENSE and NOTICE files for details.
3 //
4 // SPDX-License-Identifier: BSD-2-Clause
5 //
6 // This file is part of CEED:  http://github.com/ceed
7 
8 #include <ceed.h>
9 #include <ceed/backend.h>
10 #include <stdlib.h>
11 #include <string.h>
12 
13 #include "ceed-magma-common.h"
14 
15 //------------------------------------------------------------------------------
16 // Backend Init
17 //------------------------------------------------------------------------------
18 static int CeedInit_Magma_Det(const char *resource, Ceed ceed) {
19   const int nrc = 18;  // number of characters in resource
20   CeedCheck(!strncmp(resource, "/gpu/cuda/magma/det", nrc) || !strncmp(resource, "/gpu/hip/magma/det", nrc), ceed, CEED_ERROR_BACKEND,
21             "Magma backend cannot use resource: %s", resource);
22   CeedCallBackend(CeedSetDeterministic(ceed, true));
23 
24   Ceed_Magma *data;
25   CeedCallBackend(CeedCalloc(1, &data));
26   CeedCallBackend(CeedSetData(ceed, data));
27   CeedCallBackend(CeedInit_Magma_common(ceed, resource));
28 
29   // Create reference Ceed that implementation will be dispatched through
30   Ceed ceed_ref;
31 #ifdef CEED_MAGMA_USE_HIP
32   CeedCallBackend(CeedInit("/gpu/hip/magma", &ceed_ref));
33 #else
34   CeedCallBackend(CeedInit("/gpu/cuda/magma", &ceed_ref));
35 #endif
36   CeedCallBackend(CeedSetDelegate(ceed, ceed_ref));
37 
38   CeedCallBackend(CeedSetBackendFunction(ceed, "Ceed", ceed, "Destroy", CeedDestroy_Magma));
39 
40   return CEED_ERROR_SUCCESS;
41 }
42 
43 //------------------------------------------------------------------------------
44 // Backend Register
45 //------------------------------------------------------------------------------
46 CEED_INTERN int CeedRegister_Magma_Det(void) {
47 #ifdef CEED_MAGMA_USE_HIP
48   return CeedRegister("/gpu/hip/magma/det", CeedInit_Magma_Det, 125);
49 #else
50   return CeedRegister("/gpu/cuda/magma/det", CeedInit_Magma_Det, 125);
51 #endif
52 }
53 
54 //------------------------------------------------------------------------------
55