xref: /libCEED/rust/libceed-sys/c-src/backends/cuda-shared/ceed-cuda-shared.c (revision f87d896ccdb3ae7eb58212d71cf20ac055d48f9d)
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 
17ec3da8bcSJed Brown #include <ceed/ceed.h>
18ec3da8bcSJed Brown #include <ceed/backend.h>
19c532df63SYohann #include <string.h>
20c532df63SYohann #include "ceed-cuda-shared.h"
21c532df63SYohann 
22ab213215SJeremy L Thompson //------------------------------------------------------------------------------
23ab213215SJeremy L Thompson // Backend init
24ab213215SJeremy L Thompson //------------------------------------------------------------------------------
25c532df63SYohann static int CeedInit_Cuda_shared(const char *resource, Ceed ceed) {
26c532df63SYohann   int ierr;
27*f87d896cSJeremy L Thompson 
28*f87d896cSJeremy L Thompson   if (strcmp(resource, "/gpu/cuda/shared"))
2952d8ac88SJeremy L Thompson     // LCOV_EXCL_START
30e15f9bd0SJeremy L Thompson     return CeedError(ceed, CEED_ERROR_BACKEND,
31e15f9bd0SJeremy L Thompson                      "Cuda backend cannot use resource: %s", resource);
3252d8ac88SJeremy L Thompson   // LCOV_EXCL_STOP
339525855cSJeremy L Thompson   ierr = CeedSetDeterministic(ceed, true); CeedChk(ierr);
34c532df63SYohann 
356dbfb411Snbeams   Ceed_Cuda *data;
36c532df63SYohann   ierr = CeedCalloc(1, &data); CeedChk(ierr);
37777ff853SJeremy L Thompson   ierr = CeedSetData(ceed, data); CeedChk(ierr);
38*f87d896cSJeremy L Thompson   ierr = CeedCudaInit(ceed, resource); CeedChk(ierr);
39abfaacbbSSander Arens 
406dbfb411Snbeams   Ceed ceedref;
416dbfb411Snbeams   CeedInit("/gpu/cuda/ref", &ceedref);
426dbfb411Snbeams   ierr = CeedSetDelegate(ceed, ceedref); CeedChk(ierr);
436dbfb411Snbeams 
44c532df63SYohann   ierr = CeedSetBackendFunction(ceed, "Ceed", ceed, "BasisCreateTensorH1",
455afe0718Sjeremylt                                 CeedBasisCreateTensorH1_Cuda_shared);
46e75c1c2dSJeremy L Thompson   CeedChk(ierr);
4773b3ccafSJeremy L Thompson   ierr = CeedSetBackendFunction(ceed, "Ceed", ceed, "Destroy",
4873b3ccafSJeremy L Thompson                                 CeedDestroy_Cuda); CeedChk(ierr);
495afe0718Sjeremylt   CeedChk(ierr);
50c532df63SYohann   return 0;
51c532df63SYohann }
52c532df63SYohann 
53ab213215SJeremy L Thompson //------------------------------------------------------------------------------
54ab213215SJeremy L Thompson // Register backend
55ab213215SJeremy L Thompson //------------------------------------------------------------------------------
561d013790SJed Brown CEED_INTERN int CeedRegister_Cuda_Shared(void) {
571d013790SJed Brown   return CeedRegister("/gpu/cuda/shared", CeedInit_Cuda_shared, 25);
58c532df63SYohann }
59ab213215SJeremy L Thompson //------------------------------------------------------------------------------
60