xref: /libCEED/rust/libceed-sys/c-src/backends/cuda-gen/ceed-cuda-gen.c (revision 2a86cc9d4dbfce2964c7e8927a1e6db8d19a41fc)
13d8e8822SJeremy L Thompson // Copyright (c) 2017-2022, Lawrence Livermore National Security, LLC and other CEED contributors.
23d8e8822SJeremy L Thompson // All Rights Reserved. See the top-level LICENSE and NOTICE files for details.
3241a4b83SYohann //
43d8e8822SJeremy L Thompson // SPDX-License-Identifier: BSD-2-Clause
5241a4b83SYohann //
63d8e8822SJeremy L Thompson // This file is part of CEED:  http://github.com/ceed
7241a4b83SYohann 
8241a4b83SYohann #include "ceed-cuda-gen.h"
9241a4b83SYohann 
1049aac155SJeremy L Thompson #include <ceed.h>
112b730f8bSJeremy L Thompson #include <ceed/backend.h>
122b730f8bSJeremy L Thompson #include <string.h>
132b730f8bSJeremy L Thompson 
1449aac155SJeremy L Thompson #include "../cuda/ceed-cuda-common.h"
1549aac155SJeremy L Thompson 
16ab213215SJeremy L Thompson //------------------------------------------------------------------------------
17ab213215SJeremy L Thompson // Backend init
18ab213215SJeremy L Thompson //------------------------------------------------------------------------------
19241a4b83SYohann static int CeedInit_Cuda_gen(const char *resource, Ceed ceed) {
20b11824b3SJeremy L Thompson   char *resource_root;
212b730f8bSJeremy L Thompson   CeedCallBackend(CeedCudaGetResourceRoot(ceed, resource, &resource_root));
222b730f8bSJeremy L Thompson   if (strcmp(resource_root, "/gpu/cuda") && strcmp(resource_root, "/gpu/cuda/gen")) {
2352d8ac88SJeremy L Thompson     // LCOV_EXCL_START
242b730f8bSJeremy L Thompson     return CeedError(ceed, CEED_ERROR_BACKEND, "Cuda backend cannot use resource: %s", resource);
2552d8ac88SJeremy L Thompson     // LCOV_EXCL_STOP
262b730f8bSJeremy L Thompson   }
272b730f8bSJeremy L Thompson   CeedCallBackend(CeedFree(&resource_root));
28241a4b83SYohann 
296dbfb411Snbeams   Ceed_Cuda *data;
302b730f8bSJeremy L Thompson   CeedCallBackend(CeedCalloc(1, &data));
312b730f8bSJeremy L Thompson   CeedCallBackend(CeedSetData(ceed, data));
322b730f8bSJeremy L Thompson   CeedCallBackend(CeedCudaInit(ceed, resource));
33abfaacbbSSander Arens 
346dbfb411Snbeams   Ceed ceedshared;
352b730f8bSJeremy L Thompson   CeedCall(CeedInit("/gpu/cuda/shared", &ceedshared));
362b730f8bSJeremy L Thompson   CeedCallBackend(CeedSetDelegate(ceed, ceedshared));
376dbfb411Snbeams 
38b1d74153SJeremy L Thompson   const char fallbackresource[] = "/gpu/cuda/ref";
392b730f8bSJeremy L Thompson   CeedCallBackend(CeedSetOperatorFallbackResource(ceed, fallbackresource));
40ccaff030SJeremy L Thompson 
412b730f8bSJeremy L Thompson   CeedCallBackend(CeedSetBackendFunction(ceed, "Ceed", ceed, "QFunctionCreate", CeedQFunctionCreate_Cuda_gen));
422b730f8bSJeremy L Thompson   CeedCallBackend(CeedSetBackendFunction(ceed, "Ceed", ceed, "OperatorCreate", CeedOperatorCreate_Cuda_gen));
432b730f8bSJeremy L Thompson   CeedCallBackend(CeedSetBackendFunction(ceed, "Ceed", ceed, "Destroy", CeedDestroy_Cuda));
44e15f9bd0SJeremy L Thompson   return CEED_ERROR_SUCCESS;
45241a4b83SYohann }
46241a4b83SYohann 
47ab213215SJeremy L Thompson //------------------------------------------------------------------------------
48ab213215SJeremy L Thompson // Register backend
49ab213215SJeremy L Thompson //------------------------------------------------------------------------------
502b730f8bSJeremy L Thompson CEED_INTERN int CeedRegister_Cuda_Gen(void) { return CeedRegister("/gpu/cuda/gen", CeedInit_Cuda_gen, 20); }
51*2a86cc9dSSebastian Grimberg 
52ab213215SJeremy L Thompson //------------------------------------------------------------------------------
53