xref: /libCEED/rust/libceed-sys/c-src/backends/cuda-gen/ceed-cuda-gen.c (revision 3d8e882215d238700cdceb37404f76ca7fa24eaa)
1*3d8e8822SJeremy L Thompson // Copyright (c) 2017-2022, Lawrence Livermore National Security, LLC and other CEED contributors.
2*3d8e8822SJeremy L Thompson // All Rights Reserved. See the top-level LICENSE and NOTICE files for details.
3241a4b83SYohann //
4*3d8e8822SJeremy L Thompson // SPDX-License-Identifier: BSD-2-Clause
5241a4b83SYohann //
6*3d8e8822SJeremy L Thompson // This file is part of CEED:  http://github.com/ceed
7241a4b83SYohann 
8ec3da8bcSJed Brown #include <ceed/ceed.h>
9ec3da8bcSJed Brown #include <ceed/backend.h>
10241a4b83SYohann #include <string.h>
11241a4b83SYohann #include "ceed-cuda-gen.h"
12241a4b83SYohann 
13ab213215SJeremy L Thompson //------------------------------------------------------------------------------
14ab213215SJeremy L Thompson // Backend init
15ab213215SJeremy L Thompson //------------------------------------------------------------------------------
16241a4b83SYohann static int CeedInit_Cuda_gen(const char *resource, Ceed ceed) {
17241a4b83SYohann   int ierr;
18f87d896cSJeremy L Thompson 
19f87d896cSJeremy L Thompson   if (strcmp(resource, "/gpu/cuda") && strcmp(resource, "/gpu/cuda/gen"))
2052d8ac88SJeremy L Thompson     // LCOV_EXCL_START
21e15f9bd0SJeremy L Thompson     return CeedError(ceed, CEED_ERROR_BACKEND,
22e15f9bd0SJeremy L Thompson                      "Cuda backend cannot use resource: %s", resource);
2352d8ac88SJeremy L Thompson   // LCOV_EXCL_STOP
24241a4b83SYohann 
256dbfb411Snbeams   Ceed_Cuda *data;
26e15f9bd0SJeremy L Thompson   ierr = CeedCalloc(1, &data); CeedChkBackend(ierr);
27e15f9bd0SJeremy L Thompson   ierr = CeedSetData(ceed, data); CeedChkBackend(ierr);
28f87d896cSJeremy L Thompson   ierr = CeedCudaInit(ceed, resource); CeedChkBackend(ierr);
29abfaacbbSSander Arens 
306dbfb411Snbeams   Ceed ceedshared;
316dbfb411Snbeams   CeedInit("/gpu/cuda/shared", &ceedshared);
326dbfb411Snbeams   ierr = CeedSetDelegate(ceed, ceedshared); CeedChkBackend(ierr);
336dbfb411Snbeams 
34b1d74153SJeremy L Thompson   const char fallbackresource[] = "/gpu/cuda/ref";
35e15f9bd0SJeremy L Thompson   ierr = CeedSetOperatorFallbackResource(ceed, fallbackresource);
36e15f9bd0SJeremy L Thompson   CeedChkBackend(ierr);
37ccaff030SJeremy L Thompson 
38241a4b83SYohann   ierr = CeedSetBackendFunction(ceed, "Ceed", ceed, "QFunctionCreate",
39e15f9bd0SJeremy L Thompson                                 CeedQFunctionCreate_Cuda_gen); CeedChkBackend(ierr);
40241a4b83SYohann   ierr = CeedSetBackendFunction(ceed, "Ceed", ceed, "OperatorCreate",
41e15f9bd0SJeremy L Thompson                                 CeedOperatorCreate_Cuda_gen); CeedChkBackend(ierr);
4273b3ccafSJeremy L Thompson   ierr = CeedSetBackendFunction(ceed, "Ceed", ceed, "Destroy",
43e15f9bd0SJeremy L Thompson                                 CeedDestroy_Cuda); CeedChkBackend(ierr);
44e15f9bd0SJeremy L Thompson   return CEED_ERROR_SUCCESS;
45241a4b83SYohann }
46241a4b83SYohann 
47ab213215SJeremy L Thompson //------------------------------------------------------------------------------
48ab213215SJeremy L Thompson // Register backend
49ab213215SJeremy L Thompson //------------------------------------------------------------------------------
501d013790SJed Brown CEED_INTERN int CeedRegister_Cuda_Gen(void) {
511d013790SJed Brown   return CeedRegister("/gpu/cuda/gen", CeedInit_Cuda_gen, 20);
52241a4b83SYohann }
53ab213215SJeremy L Thompson //------------------------------------------------------------------------------
54