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 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 19*b11824b3SJeremy L Thompson char *resource_root; 20*b11824b3SJeremy L Thompson ierr = CeedCudaGetResourceRoot(ceed, resource, &resource_root); 21*b11824b3SJeremy L Thompson CeedChkBackend(ierr); 22*b11824b3SJeremy L Thompson if (strcmp(resource_root, "/gpu/cuda") 23*b11824b3SJeremy L Thompson && strcmp(resource_root, "/gpu/cuda/gen")) 2452d8ac88SJeremy L Thompson // LCOV_EXCL_START 25e15f9bd0SJeremy L Thompson return CeedError(ceed, CEED_ERROR_BACKEND, 26e15f9bd0SJeremy L Thompson "Cuda backend cannot use resource: %s", resource); 2752d8ac88SJeremy L Thompson // LCOV_EXCL_STOP 28*b11824b3SJeremy L Thompson ierr = CeedFree(&resource_root); CeedChkBackend(ierr); 29241a4b83SYohann 306dbfb411Snbeams Ceed_Cuda *data; 31e15f9bd0SJeremy L Thompson ierr = CeedCalloc(1, &data); CeedChkBackend(ierr); 32e15f9bd0SJeremy L Thompson ierr = CeedSetData(ceed, data); CeedChkBackend(ierr); 33f87d896cSJeremy L Thompson ierr = CeedCudaInit(ceed, resource); CeedChkBackend(ierr); 34abfaacbbSSander Arens 356dbfb411Snbeams Ceed ceedshared; 366dbfb411Snbeams CeedInit("/gpu/cuda/shared", &ceedshared); 376dbfb411Snbeams ierr = CeedSetDelegate(ceed, ceedshared); CeedChkBackend(ierr); 386dbfb411Snbeams 39b1d74153SJeremy L Thompson const char fallbackresource[] = "/gpu/cuda/ref"; 40e15f9bd0SJeremy L Thompson ierr = CeedSetOperatorFallbackResource(ceed, fallbackresource); 41e15f9bd0SJeremy L Thompson CeedChkBackend(ierr); 42ccaff030SJeremy L Thompson 43241a4b83SYohann ierr = CeedSetBackendFunction(ceed, "Ceed", ceed, "QFunctionCreate", 44e15f9bd0SJeremy L Thompson CeedQFunctionCreate_Cuda_gen); CeedChkBackend(ierr); 45241a4b83SYohann ierr = CeedSetBackendFunction(ceed, "Ceed", ceed, "OperatorCreate", 46e15f9bd0SJeremy L Thompson CeedOperatorCreate_Cuda_gen); CeedChkBackend(ierr); 4773b3ccafSJeremy L Thompson ierr = CeedSetBackendFunction(ceed, "Ceed", ceed, "Destroy", 48e15f9bd0SJeremy L Thompson CeedDestroy_Cuda); CeedChkBackend(ierr); 49e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 50241a4b83SYohann } 51241a4b83SYohann 52ab213215SJeremy L Thompson //------------------------------------------------------------------------------ 53ab213215SJeremy L Thompson // Register backend 54ab213215SJeremy L Thompson //------------------------------------------------------------------------------ 551d013790SJed Brown CEED_INTERN int CeedRegister_Cuda_Gen(void) { 561d013790SJed Brown return CeedRegister("/gpu/cuda/gen", CeedInit_Cuda_gen, 20); 57241a4b83SYohann } 58ab213215SJeremy L Thompson //------------------------------------------------------------------------------ 59