xref: /libCEED/rust/libceed-sys/c-src/backends/cuda-shared/ceed-cuda-shared.c (revision b11824b355ec5db8d1d0662d2c2bd260606aac4b)
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 
8ec3da8bcSJed Brown #include <ceed/ceed.h>
9ec3da8bcSJed Brown #include <ceed/backend.h>
10c532df63SYohann #include <string.h>
11c532df63SYohann #include "ceed-cuda-shared.h"
12c532df63SYohann 
13ab213215SJeremy L Thompson //------------------------------------------------------------------------------
14ab213215SJeremy L Thompson // Backend init
15ab213215SJeremy L Thompson //------------------------------------------------------------------------------
16c532df63SYohann static int CeedInit_Cuda_shared(const char *resource, Ceed ceed) {
17c532df63SYohann   int ierr;
18f87d896cSJeremy L Thompson 
19*b11824b3SJeremy L Thompson   char *resource_root;
20*b11824b3SJeremy L Thompson   ierr = CeedCudaGetResourceRoot(ceed, resource, &resource_root);
21*b11824b3SJeremy L Thompson   CeedChkBackend(ierr);
22*b11824b3SJeremy L Thompson   if (strcmp(resource_root, "/gpu/cuda/shared"))
2352d8ac88SJeremy L Thompson     // LCOV_EXCL_START
24e15f9bd0SJeremy L Thompson     return CeedError(ceed, CEED_ERROR_BACKEND,
25e15f9bd0SJeremy L Thompson                      "Cuda backend cannot use resource: %s", resource);
2652d8ac88SJeremy L Thompson   // LCOV_EXCL_STOP
27*b11824b3SJeremy L Thompson   ierr = CeedSetDeterministic(ceed, true); CeedChkBackend(ierr);
28c532df63SYohann 
296dbfb411Snbeams   Ceed_Cuda *data;
30*b11824b3SJeremy L Thompson   ierr = CeedCalloc(1, &data); CeedChkBackend(ierr);
31*b11824b3SJeremy L Thompson   ierr = CeedSetData(ceed, data); CeedChkBackend(ierr);
32*b11824b3SJeremy L Thompson   ierr = CeedCudaInit(ceed, resource); CeedChkBackend(ierr);
33abfaacbbSSander Arens 
34437930d1SJeremy L Thompson   Ceed ceed_ref;
35437930d1SJeremy L Thompson   CeedInit("/gpu/cuda/ref", &ceed_ref);
36*b11824b3SJeremy L Thompson   ierr = CeedSetDelegate(ceed, ceed_ref); CeedChkBackend(ierr);
376dbfb411Snbeams 
38c532df63SYohann   ierr = CeedSetBackendFunction(ceed, "Ceed", ceed, "BasisCreateTensorH1",
395afe0718Sjeremylt                                 CeedBasisCreateTensorH1_Cuda_shared);
40*b11824b3SJeremy L Thompson   CeedChkBackend(ierr);
4173b3ccafSJeremy L Thompson   ierr = CeedSetBackendFunction(ceed, "Ceed", ceed, "Destroy",
42*b11824b3SJeremy L Thompson                                 CeedDestroy_Cuda); CeedChkBackend(ierr);
43*b11824b3SJeremy L Thompson   CeedChkBackend(ierr);
44c532df63SYohann   return 0;
45c532df63SYohann }
46c532df63SYohann 
47ab213215SJeremy L Thompson //------------------------------------------------------------------------------
48ab213215SJeremy L Thompson // Register backend
49ab213215SJeremy L Thompson //------------------------------------------------------------------------------
501d013790SJed Brown CEED_INTERN int CeedRegister_Cuda_Shared(void) {
511d013790SJed Brown   return CeedRegister("/gpu/cuda/shared", CeedInit_Cuda_shared, 25);
52c532df63SYohann }
53ab213215SJeremy L Thompson //------------------------------------------------------------------------------
54