xref: /libCEED/rust/libceed-sys/c-src/backends/cuda-shared/ceed-cuda-shared.c (revision ab213215e569729a95fd10d21627f8060eaeb868)
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 
17c532df63SYohann #include <ceed-backend.h>
18c532df63SYohann #include <string.h>
19c532df63SYohann #include <stdarg.h>
20c532df63SYohann #include <nvrtc.h>
21c532df63SYohann #include <cuda.h>
22c532df63SYohann #include <cuda_runtime.h>
23c532df63SYohann #include "ceed-cuda-shared.h"
24c532df63SYohann 
25*ab213215SJeremy L Thompson //------------------------------------------------------------------------------
26*ab213215SJeremy L Thompson // Backend init
27*ab213215SJeremy L Thompson //------------------------------------------------------------------------------
28c532df63SYohann static int CeedInit_Cuda_shared(const char *resource, Ceed ceed) {
29c532df63SYohann   int ierr;
30c532df63SYohann   const int nrc = 9; // number of characters in resource
31c532df63SYohann   if (strncmp(resource, "/gpu/cuda/shared", nrc))
32c532df63SYohann     return CeedError(ceed, 1, "Cuda backend cannot use resource: %s", resource);
33c532df63SYohann 
34c532df63SYohann   Ceed ceedreg;
35c532df63SYohann   CeedInit("/gpu/cuda/reg", &ceedreg);
36a4999eddSjeremylt   ierr = CeedSetDelegate(ceed, ceedreg); CeedChk(ierr);
37c532df63SYohann 
38c532df63SYohann   Ceed_Cuda_shared *data;
39c532df63SYohann   ierr = CeedCalloc(1,&data); CeedChk(ierr);
40c532df63SYohann   ierr = CeedSetData(ceed,(void *)&data); CeedChk(ierr);
41abfaacbbSSander Arens   ierr = CeedCudaInit(ceed, resource, nrc); CeedChk(ierr);
42abfaacbbSSander Arens 
43c532df63SYohann   ierr = CeedSetBackendFunction(ceed, "Ceed", ceed, "BasisCreateTensorH1",
445afe0718Sjeremylt                                 CeedBasisCreateTensorH1_Cuda_shared);
455afe0718Sjeremylt   CeedChk(ierr);
46c532df63SYohann   return 0;
47c532df63SYohann }
48c532df63SYohann 
49*ab213215SJeremy L Thompson //------------------------------------------------------------------------------
50*ab213215SJeremy L Thompson // Register backend
51*ab213215SJeremy L Thompson //------------------------------------------------------------------------------
52c532df63SYohann __attribute__((constructor))
53c532df63SYohann static void Register(void) {
54c532df63SYohann   CeedRegister("/gpu/cuda/shared", CeedInit_Cuda_shared, 40);
55c532df63SYohann }
56*ab213215SJeremy L Thompson //------------------------------------------------------------------------------
57