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. 3c532df63SYohann // 4*3d8e8822SJeremy L Thompson // SPDX-License-Identifier: BSD-2-Clause 5c532df63SYohann // 6*3d8e8822SJeremy L Thompson // This file is part of CEED: http://github.com/ceed 7c532df63SYohann 8ec3da8bcSJed Brown #include <ceed/ceed.h> 9ec3da8bcSJed Brown #include <ceed/backend.h> 10c532df63SYohann #include <string.h> 11c532df63SYohann #include "ceed-cuda-shared.h" 12c532df63SYohann 13ab213215SJeremy L Thompson //------------------------------------------------------------------------------ 14ab213215SJeremy L Thompson // Backend init 15ab213215SJeremy L Thompson //------------------------------------------------------------------------------ 16c532df63SYohann static int CeedInit_Cuda_shared(const char *resource, Ceed ceed) { 17c532df63SYohann int ierr; 18f87d896cSJeremy L Thompson 19f87d896cSJeremy L Thompson if (strcmp(resource, "/gpu/cuda/shared")) 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 249525855cSJeremy L Thompson ierr = CeedSetDeterministic(ceed, true); CeedChk(ierr); 25c532df63SYohann 266dbfb411Snbeams Ceed_Cuda *data; 27c532df63SYohann ierr = CeedCalloc(1, &data); CeedChk(ierr); 28777ff853SJeremy L Thompson ierr = CeedSetData(ceed, data); CeedChk(ierr); 29f87d896cSJeremy L Thompson ierr = CeedCudaInit(ceed, resource); CeedChk(ierr); 30abfaacbbSSander Arens 31437930d1SJeremy L Thompson Ceed ceed_ref; 32437930d1SJeremy L Thompson CeedInit("/gpu/cuda/ref", &ceed_ref); 33437930d1SJeremy L Thompson ierr = CeedSetDelegate(ceed, ceed_ref); CeedChk(ierr); 346dbfb411Snbeams 35c532df63SYohann ierr = CeedSetBackendFunction(ceed, "Ceed", ceed, "BasisCreateTensorH1", 365afe0718Sjeremylt CeedBasisCreateTensorH1_Cuda_shared); 37e75c1c2dSJeremy L Thompson CeedChk(ierr); 3873b3ccafSJeremy L Thompson ierr = CeedSetBackendFunction(ceed, "Ceed", ceed, "Destroy", 3973b3ccafSJeremy L Thompson CeedDestroy_Cuda); CeedChk(ierr); 405afe0718Sjeremylt CeedChk(ierr); 41c532df63SYohann return 0; 42c532df63SYohann } 43c532df63SYohann 44ab213215SJeremy L Thompson //------------------------------------------------------------------------------ 45ab213215SJeremy L Thompson // Register backend 46ab213215SJeremy L Thompson //------------------------------------------------------------------------------ 471d013790SJed Brown CEED_INTERN int CeedRegister_Cuda_Shared(void) { 481d013790SJed Brown return CeedRegister("/gpu/cuda/shared", CeedInit_Cuda_shared, 25); 49c532df63SYohann } 50ab213215SJeremy L Thompson //------------------------------------------------------------------------------ 51