xref: /libCEED/rust/libceed-sys/c-src/backends/cuda-shared/ceed-cuda-shared.c (revision e15f9bd09af0280c89b79924fa9af7dd2e3e30be)
1c532df63SYohann // Copyright (c) 2017-2018, Lawrence Livermore National Security, LLC.
2c532df63SYohann // Produced at the Lawrence Livermore National Laboratory. LLNL-CODE-734707.
3c532df63SYohann // All Rights reserved. See files LICENSE and NOTICE for details.
4c532df63SYohann //
5c532df63SYohann // This file is part of CEED, a collection of benchmarks, miniapps, software
6c532df63SYohann // libraries and APIs for efficient high-order finite element and spectral
7c532df63SYohann // element discretizations for exascale applications. For more information and
8c532df63SYohann // source code availability see http://github.com/ceed.
9c532df63SYohann //
10c532df63SYohann // The CEED research is supported by the Exascale Computing Project 17-SC-20-SC,
11c532df63SYohann // a collaborative effort of two U.S. Department of Energy organizations (Office
12c532df63SYohann // of Science and the National Nuclear Security Administration) responsible for
13c532df63SYohann // the planning and preparation of a capable exascale ecosystem, including
14c532df63SYohann // software, applications, hardware, advanced system engineering and early
15c532df63SYohann // testbed platforms, in support of the nation's exascale computing imperative.
16c532df63SYohann 
173d576824SJeremy L Thompson #include <ceed.h>
183d576824SJeremy L Thompson #include <ceed-backend.h>
193d576824SJeremy L Thompson #include <stdbool.h>
20c532df63SYohann #include <string.h>
21c532df63SYohann #include "ceed-cuda-shared.h"
223d576824SJeremy L Thompson #include "../cuda/ceed-cuda.h"
23c532df63SYohann 
24ab213215SJeremy L Thompson //------------------------------------------------------------------------------
25ab213215SJeremy L Thompson // Backend init
26ab213215SJeremy L Thompson //------------------------------------------------------------------------------
27c532df63SYohann static int CeedInit_Cuda_shared(const char *resource, Ceed ceed) {
28c532df63SYohann   int ierr;
29c532df63SYohann   const int nrc = 9; // number of characters in resource
30c532df63SYohann   if (strncmp(resource, "/gpu/cuda/shared", nrc))
3152d8ac88SJeremy L Thompson     // LCOV_EXCL_START
32*e15f9bd0SJeremy L Thompson     return CeedError(ceed, CEED_ERROR_BACKEND,
33*e15f9bd0SJeremy L Thompson                      "Cuda backend cannot use resource: %s", resource);
3452d8ac88SJeremy L Thompson   // LCOV_EXCL_STOP
359525855cSJeremy L Thompson   ierr = CeedSetDeterministic(ceed, true); CeedChk(ierr);
36c532df63SYohann 
37461525f5SNatalie Beams   Ceed ceedref;
38461525f5SNatalie Beams   CeedInit("/gpu/cuda/ref", &ceedref);
39461525f5SNatalie Beams   ierr = CeedSetDelegate(ceed, ceedref); CeedChk(ierr);
40c532df63SYohann 
41c532df63SYohann   Ceed_Cuda_shared *data;
42c532df63SYohann   ierr = CeedCalloc(1, &data); CeedChk(ierr);
43777ff853SJeremy L Thompson   ierr = CeedSetData(ceed, data); CeedChk(ierr);
44abfaacbbSSander Arens   ierr = CeedCudaInit(ceed, resource, nrc); CeedChk(ierr);
45abfaacbbSSander Arens 
46c532df63SYohann   ierr = CeedSetBackendFunction(ceed, "Ceed", ceed, "BasisCreateTensorH1",
475afe0718Sjeremylt                                 CeedBasisCreateTensorH1_Cuda_shared);
48e75c1c2dSJeremy L Thompson   CeedChk(ierr);
4973b3ccafSJeremy L Thompson   ierr = CeedSetBackendFunction(ceed, "Ceed", ceed, "Destroy",
5073b3ccafSJeremy L Thompson                                 CeedDestroy_Cuda); CeedChk(ierr);
515afe0718Sjeremylt   CeedChk(ierr);
52c532df63SYohann   return 0;
53c532df63SYohann }
54c532df63SYohann 
55ab213215SJeremy L Thompson //------------------------------------------------------------------------------
56ab213215SJeremy L Thompson // Register backend
57ab213215SJeremy L Thompson //------------------------------------------------------------------------------
581d013790SJed Brown CEED_INTERN int CeedRegister_Cuda_Shared(void) {
591d013790SJed Brown   return CeedRegister("/gpu/cuda/shared", CeedInit_Cuda_shared, 25);
60c532df63SYohann }
61ab213215SJeremy L Thompson //------------------------------------------------------------------------------
62