xref: /libCEED/rust/libceed-sys/c-src/backends/cuda-shared/ceed-cuda-shared.c (revision 2b730f8b5a9c809740a0b3b302db43a719c636b1)
13d8e8822SJeremy L Thompson // Copyright (c) 2017-2022, Lawrence Livermore National Security, LLC and other CEED contributors.
23d8e8822SJeremy L Thompson // All Rights Reserved. See the top-level LICENSE and NOTICE files for details.
3c532df63SYohann //
43d8e8822SJeremy L Thompson // SPDX-License-Identifier: BSD-2-Clause
5c532df63SYohann //
63d8e8822SJeremy L Thompson // This file is part of CEED:  http://github.com/ceed
7c532df63SYohann 
8c532df63SYohann #include "ceed-cuda-shared.h"
9c532df63SYohann 
10*2b730f8bSJeremy L Thompson #include <ceed/backend.h>
11*2b730f8bSJeremy L Thompson #include <ceed/ceed.h>
12*2b730f8bSJeremy L Thompson #include <string.h>
13*2b730f8bSJeremy L Thompson 
14ab213215SJeremy L Thompson //------------------------------------------------------------------------------
15ab213215SJeremy L Thompson // Backend init
16ab213215SJeremy L Thompson //------------------------------------------------------------------------------
17c532df63SYohann static int CeedInit_Cuda_shared(const char *resource, Ceed ceed) {
18b11824b3SJeremy L Thompson   char *resource_root;
19*2b730f8bSJeremy L Thompson   CeedCallBackend(CeedCudaGetResourceRoot(ceed, resource, &resource_root));
20*2b730f8bSJeremy L Thompson   if (strcmp(resource_root, "/gpu/cuda/shared")) {
2152d8ac88SJeremy L Thompson     // LCOV_EXCL_START
22*2b730f8bSJeremy L Thompson     return CeedError(ceed, CEED_ERROR_BACKEND, "Cuda backend cannot use resource: %s", resource);
2352d8ac88SJeremy L Thompson     // LCOV_EXCL_STOP
24*2b730f8bSJeremy L Thompson   }
25*2b730f8bSJeremy L Thompson   CeedCallBackend(CeedSetDeterministic(ceed, true));
26c532df63SYohann 
276dbfb411Snbeams   Ceed_Cuda *data;
28*2b730f8bSJeremy L Thompson   CeedCallBackend(CeedCalloc(1, &data));
29*2b730f8bSJeremy L Thompson   CeedCallBackend(CeedSetData(ceed, data));
30*2b730f8bSJeremy L Thompson   CeedCallBackend(CeedCudaInit(ceed, resource));
31abfaacbbSSander Arens 
32437930d1SJeremy L Thompson   Ceed ceed_ref;
33*2b730f8bSJeremy L Thompson   CeedCallBackend(CeedInit("/gpu/cuda/ref", &ceed_ref));
34*2b730f8bSJeremy L Thompson   CeedCallBackend(CeedSetDelegate(ceed, ceed_ref));
356dbfb411Snbeams 
36*2b730f8bSJeremy L Thompson   CeedCallBackend(CeedSetBackendFunction(ceed, "Ceed", ceed, "BasisCreateTensorH1", CeedBasisCreateTensorH1_Cuda_shared));
37*2b730f8bSJeremy L Thompson   CeedCallBackend(CeedSetBackendFunction(ceed, "Ceed", ceed, "Destroy", CeedDestroy_Cuda));
38c532df63SYohann   return 0;
39c532df63SYohann }
40c532df63SYohann 
41ab213215SJeremy L Thompson //------------------------------------------------------------------------------
42ab213215SJeremy L Thompson // Register backend
43ab213215SJeremy L Thompson //------------------------------------------------------------------------------
44*2b730f8bSJeremy L Thompson CEED_INTERN int CeedRegister_Cuda_Shared(void) { return CeedRegister("/gpu/cuda/shared", CeedInit_Cuda_shared, 25); }
45ab213215SJeremy L Thompson //------------------------------------------------------------------------------
46