xref: /libCEED/rust/libceed-sys/c-src/backends/cuda-shared/ceed-cuda-shared.c (revision 9ff05d55386b4e6413be60b7231511258906fd9f)
15aed82e4SJeremy L Thompson // Copyright (c) 2017-2024, 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.
3c532df63SYohann //
43d8e8822SJeremy L Thompson // SPDX-License-Identifier: BSD-2-Clause
5c532df63SYohann //
63d8e8822SJeremy L Thompson // This file is part of CEED:  http://github.com/ceed
7c532df63SYohann 
8c532df63SYohann #include "ceed-cuda-shared.h"
9c532df63SYohann 
1049aac155SJeremy L Thompson #include <ceed.h>
112b730f8bSJeremy L Thompson #include <ceed/backend.h>
1249aac155SJeremy L Thompson #include <stdbool.h>
132b730f8bSJeremy L Thompson #include <string.h>
142b730f8bSJeremy L Thompson 
1549aac155SJeremy L Thompson #include "../cuda/ceed-cuda-common.h"
1649aac155SJeremy L Thompson 
17ab213215SJeremy L Thompson //------------------------------------------------------------------------------
18ab213215SJeremy L Thompson // Backend init
19ab213215SJeremy L Thompson //------------------------------------------------------------------------------
20c532df63SYohann static int CeedInit_Cuda_shared(const char *resource, Ceed ceed) {
21ca735530SJeremy L Thompson   Ceed       ceed_ref;
22ca735530SJeremy L Thompson   Ceed_Cuda *data;
23b11824b3SJeremy L Thompson   char      *resource_root;
24ca735530SJeremy L Thompson 
25bc246734SJeremy L Thompson   CeedCallBackend(CeedGetResourceRoot(ceed, resource, ":", &resource_root));
266574a04fSJeremy L Thompson   CeedCheck(!strcmp(resource_root, "/gpu/cuda/shared"), ceed, CEED_ERROR_BACKEND, "Cuda backend cannot use resource: %s", resource);
27bf84744cSJeremy L Thompson   CeedCallBackend(CeedFree(&resource_root));
282b730f8bSJeremy L Thompson   CeedCallBackend(CeedSetDeterministic(ceed, true));
29c532df63SYohann 
302b730f8bSJeremy L Thompson   CeedCallBackend(CeedCalloc(1, &data));
312b730f8bSJeremy L Thompson   CeedCallBackend(CeedSetData(ceed, data));
32eb7e6cafSJeremy L Thompson   CeedCallBackend(CeedInit_Cuda(ceed, resource));
33abfaacbbSSander Arens 
342b730f8bSJeremy L Thompson   CeedCallBackend(CeedInit("/gpu/cuda/ref", &ceed_ref));
352b730f8bSJeremy L Thompson   CeedCallBackend(CeedSetDelegate(ceed, ceed_ref));
369bc66399SJeremy L Thompson   CeedCallBackend(CeedDestroy(&ceed_ref));
376dbfb411Snbeams 
382b730f8bSJeremy L Thompson   CeedCallBackend(CeedSetBackendFunction(ceed, "Ceed", ceed, "BasisCreateTensorH1", CeedBasisCreateTensorH1_Cuda_shared));
39*9ff05d55SJeremy L Thompson   CeedCallBackend(CeedSetBackendFunction(ceed, "Ceed", ceed, "BasisCreateH1", CeedBasisCreateH1_Cuda_shared));
402b730f8bSJeremy L Thompson   CeedCallBackend(CeedSetBackendFunction(ceed, "Ceed", ceed, "Destroy", CeedDestroy_Cuda));
41b2165e7aSSebastian Grimberg   return CEED_ERROR_SUCCESS;
42c532df63SYohann }
43c532df63SYohann 
44ab213215SJeremy L Thompson //------------------------------------------------------------------------------
45ab213215SJeremy L Thompson // Register backend
46ab213215SJeremy L Thompson //------------------------------------------------------------------------------
472b730f8bSJeremy L Thompson CEED_INTERN int CeedRegister_Cuda_Shared(void) { return CeedRegister("/gpu/cuda/shared", CeedInit_Cuda_shared, 25); }
482a86cc9dSSebastian Grimberg 
49ab213215SJeremy L Thompson //------------------------------------------------------------------------------
50