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 10*2b730f8bSJeremy L Thompson #include <ceed/backend.h> 11*2b730f8bSJeremy L Thompson #include <ceed/ceed.h> 12*2b730f8bSJeremy L Thompson #include <string.h> 13*2b730f8bSJeremy L Thompson 14ab213215SJeremy L Thompson //------------------------------------------------------------------------------ 15ab213215SJeremy L Thompson // Backend init 16ab213215SJeremy L Thompson //------------------------------------------------------------------------------ 17241a4b83SYohann static int CeedInit_Cuda_gen(const char *resource, Ceed ceed) { 18b11824b3SJeremy L Thompson char *resource_root; 19*2b730f8bSJeremy L Thompson CeedCallBackend(CeedCudaGetResourceRoot(ceed, resource, &resource_root)); 20*2b730f8bSJeremy L Thompson if (strcmp(resource_root, "/gpu/cuda") && strcmp(resource_root, "/gpu/cuda/gen")) { 2152d8ac88SJeremy L Thompson // LCOV_EXCL_START 22*2b730f8bSJeremy L Thompson return CeedError(ceed, CEED_ERROR_BACKEND, "Cuda backend cannot use resource: %s", resource); 2352d8ac88SJeremy L Thompson // LCOV_EXCL_STOP 24*2b730f8bSJeremy L Thompson } 25*2b730f8bSJeremy L Thompson CeedCallBackend(CeedFree(&resource_root)); 26241a4b83SYohann 276dbfb411Snbeams Ceed_Cuda *data; 28*2b730f8bSJeremy L Thompson CeedCallBackend(CeedCalloc(1, &data)); 29*2b730f8bSJeremy L Thompson CeedCallBackend(CeedSetData(ceed, data)); 30*2b730f8bSJeremy L Thompson CeedCallBackend(CeedCudaInit(ceed, resource)); 31abfaacbbSSander Arens 326dbfb411Snbeams Ceed ceedshared; 33*2b730f8bSJeremy L Thompson CeedCall(CeedInit("/gpu/cuda/shared", &ceedshared)); 34*2b730f8bSJeremy L Thompson CeedCallBackend(CeedSetDelegate(ceed, ceedshared)); 356dbfb411Snbeams 36b1d74153SJeremy L Thompson const char fallbackresource[] = "/gpu/cuda/ref"; 37*2b730f8bSJeremy L Thompson CeedCallBackend(CeedSetOperatorFallbackResource(ceed, fallbackresource)); 38ccaff030SJeremy L Thompson 39*2b730f8bSJeremy L Thompson CeedCallBackend(CeedSetBackendFunction(ceed, "Ceed", ceed, "QFunctionCreate", CeedQFunctionCreate_Cuda_gen)); 40*2b730f8bSJeremy L Thompson CeedCallBackend(CeedSetBackendFunction(ceed, "Ceed", ceed, "OperatorCreate", CeedOperatorCreate_Cuda_gen)); 41*2b730f8bSJeremy L Thompson CeedCallBackend(CeedSetBackendFunction(ceed, "Ceed", ceed, "Destroy", CeedDestroy_Cuda)); 42e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 43241a4b83SYohann } 44241a4b83SYohann 45ab213215SJeremy L Thompson //------------------------------------------------------------------------------ 46ab213215SJeremy L Thompson // Register backend 47ab213215SJeremy L Thompson //------------------------------------------------------------------------------ 48*2b730f8bSJeremy L Thompson CEED_INTERN int CeedRegister_Cuda_Gen(void) { return CeedRegister("/gpu/cuda/gen", CeedInit_Cuda_gen, 20); } 49ab213215SJeremy L Thompson //------------------------------------------------------------------------------ 50