xref: /libCEED/rust/libceed-sys/c-src/backends/magma/ceed-magma-det.c (revision d4cc18453651bd0f94c1a2e078b2646a92dafdcc)
1 // Copyright (c) 2017-2026, 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 //------------------------------------------------------------------------------
CeedInit_Magma_Det(const char * resource,Ceed ceed)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   CeedCallBackend(CeedDestroy(&ceed_ref));
39 
40   CeedCallBackend(CeedSetBackendFunction(ceed, "Ceed", ceed, "Destroy", CeedDestroy_Magma));
41   return CEED_ERROR_SUCCESS;
42 }
43 
44 //------------------------------------------------------------------------------
45 // Backend Register
46 //------------------------------------------------------------------------------
CeedRegister_Magma_Det(void)47 CEED_INTERN int CeedRegister_Magma_Det(void) {
48 #ifdef CEED_MAGMA_USE_HIP
49   return CeedRegister("/gpu/hip/magma/det", CeedInit_Magma_Det, 125);
50 #else
51   return CeedRegister("/gpu/cuda/magma/det", CeedInit_Magma_Det, 125);
52 #endif
53 }
54 
55 //------------------------------------------------------------------------------
56