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; 21*bc246734SJeremy L Thompson CeedCallBackend(CeedGetResourceRoot(ceed, resource, ":", &resource_root)); 226574a04fSJeremy L Thompson CeedCheck(!strcmp(resource_root, "/gpu/cuda") || !strcmp(resource_root, "/gpu/cuda/gen"), ceed, CEED_ERROR_BACKEND, 236574a04fSJeremy L Thompson "Cuda backend cannot use resource: %s", resource); 242b730f8bSJeremy L Thompson CeedCallBackend(CeedFree(&resource_root)); 25241a4b83SYohann 266dbfb411Snbeams Ceed_Cuda *data; 272b730f8bSJeremy L Thompson CeedCallBackend(CeedCalloc(1, &data)); 282b730f8bSJeremy L Thompson CeedCallBackend(CeedSetData(ceed, data)); 292b730f8bSJeremy L Thompson CeedCallBackend(CeedCudaInit(ceed, resource)); 30abfaacbbSSander Arens 316dbfb411Snbeams Ceed ceedshared; 322b730f8bSJeremy L Thompson CeedCall(CeedInit("/gpu/cuda/shared", &ceedshared)); 332b730f8bSJeremy L Thompson CeedCallBackend(CeedSetDelegate(ceed, ceedshared)); 346dbfb411Snbeams 35b1d74153SJeremy L Thompson const char fallbackresource[] = "/gpu/cuda/ref"; 362b730f8bSJeremy L Thompson CeedCallBackend(CeedSetOperatorFallbackResource(ceed, fallbackresource)); 37ccaff030SJeremy L Thompson 382b730f8bSJeremy L Thompson CeedCallBackend(CeedSetBackendFunction(ceed, "Ceed", ceed, "QFunctionCreate", CeedQFunctionCreate_Cuda_gen)); 392b730f8bSJeremy L Thompson CeedCallBackend(CeedSetBackendFunction(ceed, "Ceed", ceed, "OperatorCreate", CeedOperatorCreate_Cuda_gen)); 402b730f8bSJeremy L Thompson CeedCallBackend(CeedSetBackendFunction(ceed, "Ceed", ceed, "Destroy", CeedDestroy_Cuda)); 41e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 42241a4b83SYohann } 43241a4b83SYohann 44ab213215SJeremy L Thompson //------------------------------------------------------------------------------ 45ab213215SJeremy L Thompson // Register backend 46ab213215SJeremy L Thompson //------------------------------------------------------------------------------ 472b730f8bSJeremy L Thompson CEED_INTERN int CeedRegister_Cuda_Gen(void) { return CeedRegister("/gpu/cuda/gen", CeedInit_Cuda_gen, 20); } 482a86cc9dSSebastian Grimberg 49ab213215SJeremy L Thompson //------------------------------------------------------------------------------ 50