xref: /libCEED/backends/magma/ceed-magma-det.c (revision 07d5b98a8feba68a643190b8ea9bcdac5c3e6570)
1 // Copyright (c) 2017-2024, 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   Ceed        ceed_ref;
20   Ceed_Magma *data;
21   const int   nrc = 18;  // number of characters in resource
22 
23   CeedCheck(!strncmp(resource, "/gpu/cuda/magma/det", nrc) || !strncmp(resource, "/gpu/hip/magma/det", nrc), ceed, CEED_ERROR_BACKEND,
24             "Magma backend cannot use resource: %s", resource);
25   CeedCallBackend(CeedSetDeterministic(ceed, true));
26 
27   CeedCallBackend(CeedCalloc(1, &data));
28   CeedCallBackend(CeedSetData(ceed, data));
29   CeedCallBackend(CeedInit_Magma_common(ceed, resource));
30 
31   // Create reference Ceed that implementation will be dispatched through
32 #ifdef CEED_MAGMA_USE_HIP
33   CeedCallBackend(CeedInit("/gpu/hip/magma", &ceed_ref));
34 #else
35   CeedCallBackend(CeedInit("/gpu/cuda/magma", &ceed_ref));
36 #endif
37   CeedCallBackend(CeedSetDelegate(ceed, ceed_ref));
38 
39   CeedCallBackend(CeedSetBackendFunction(ceed, "Ceed", ceed, "Destroy", CeedDestroy_Magma));
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