xref: /libCEED/rust/libceed-sys/c-src/backends/cuda-gen/ceed-cuda-gen.c (revision 6dbfb411544a7a6bdd33f391c97c69cd9e1f444a)
1241a4b83SYohann // Copyright (c) 2017-2018, Lawrence Livermore National Security, LLC.
2241a4b83SYohann // Produced at the Lawrence Livermore National Laboratory. LLNL-CODE-734707.
3241a4b83SYohann // All Rights reserved. See files LICENSE and NOTICE for details.
4241a4b83SYohann //
5241a4b83SYohann // This file is part of CEED, a collection of benchmarks, miniapps, software
6241a4b83SYohann // libraries and APIs for efficient high-order finite element and spectral
7241a4b83SYohann // element discretizations for exascale applications. For more information and
8241a4b83SYohann // source code availability see http://github.com/ceed.
9241a4b83SYohann //
10241a4b83SYohann // The CEED research is supported by the Exascale Computing Project 17-SC-20-SC,
11241a4b83SYohann // a collaborative effort of two U.S. Department of Energy organizations (Office
12241a4b83SYohann // of Science and the National Nuclear Security Administration) responsible for
13241a4b83SYohann // the planning and preparation of a capable exascale ecosystem, including
14241a4b83SYohann // software, applications, hardware, advanced system engineering and early
15241a4b83SYohann // testbed platforms, in support of the nation's exascale computing imperative.
16241a4b83SYohann 
17ec3da8bcSJed Brown #include <ceed/ceed.h>
18ec3da8bcSJed Brown #include <ceed/backend.h>
19241a4b83SYohann #include <string.h>
20241a4b83SYohann #include "ceed-cuda-gen.h"
213d576824SJeremy L Thompson #include "../cuda/ceed-cuda.h"
22241a4b83SYohann 
23ab213215SJeremy L Thompson //------------------------------------------------------------------------------
24ab213215SJeremy L Thompson // Backend init
25ab213215SJeremy L Thompson //------------------------------------------------------------------------------
26241a4b83SYohann static int CeedInit_Cuda_gen(const char *resource, Ceed ceed) {
27241a4b83SYohann   int ierr;
28241a4b83SYohann   const int nrc = 9; // number of characters in resource
29241a4b83SYohann   if (strncmp(resource, "/gpu/cuda/gen", nrc))
3052d8ac88SJeremy L Thompson     // LCOV_EXCL_START
31e15f9bd0SJeremy L Thompson     return CeedError(ceed, CEED_ERROR_BACKEND,
32e15f9bd0SJeremy L Thompson                      "Cuda backend cannot use resource: %s", resource);
3352d8ac88SJeremy L Thompson   // LCOV_EXCL_STOP
34241a4b83SYohann 
35*6dbfb411Snbeams   Ceed_Cuda *data;
36e15f9bd0SJeremy L Thompson   ierr = CeedCalloc(1, &data); CeedChkBackend(ierr);
37e15f9bd0SJeremy L Thompson   ierr = CeedSetData(ceed, data); CeedChkBackend(ierr);
38e15f9bd0SJeremy L Thompson   ierr = CeedCudaInit(ceed, resource, nrc); CeedChkBackend(ierr);
39abfaacbbSSander Arens 
40*6dbfb411Snbeams   Ceed ceedshared;
41*6dbfb411Snbeams   CeedInit("/gpu/cuda/shared", &ceedshared);
42*6dbfb411Snbeams   ierr = CeedSetDelegate(ceed, ceedshared); CeedChkBackend(ierr);
43*6dbfb411Snbeams 
44b1d74153SJeremy L Thompson   const char fallbackresource[] = "/gpu/cuda/ref";
45e15f9bd0SJeremy L Thompson   ierr = CeedSetOperatorFallbackResource(ceed, fallbackresource);
46e15f9bd0SJeremy L Thompson   CeedChkBackend(ierr);
47ccaff030SJeremy L Thompson 
48241a4b83SYohann   ierr = CeedSetBackendFunction(ceed, "Ceed", ceed, "QFunctionCreate",
49e15f9bd0SJeremy L Thompson                                 CeedQFunctionCreate_Cuda_gen); CeedChkBackend(ierr);
50241a4b83SYohann   ierr = CeedSetBackendFunction(ceed, "Ceed", ceed, "OperatorCreate",
51e15f9bd0SJeremy L Thompson                                 CeedOperatorCreate_Cuda_gen); CeedChkBackend(ierr);
5273b3ccafSJeremy L Thompson   ierr = CeedSetBackendFunction(ceed, "Ceed", ceed, "Destroy",
53e15f9bd0SJeremy L Thompson                                 CeedDestroy_Cuda); CeedChkBackend(ierr);
54e15f9bd0SJeremy L Thompson   return CEED_ERROR_SUCCESS;
55241a4b83SYohann }
56241a4b83SYohann 
57ab213215SJeremy L Thompson //------------------------------------------------------------------------------
58ab213215SJeremy L Thompson // Register backend
59ab213215SJeremy L Thompson //------------------------------------------------------------------------------
601d013790SJed Brown CEED_INTERN int CeedRegister_Cuda_Gen(void) {
611d013790SJed Brown   return CeedRegister("/gpu/cuda/gen", CeedInit_Cuda_gen, 20);
62241a4b83SYohann }
63ab213215SJeremy L Thompson //------------------------------------------------------------------------------
64