1*5aed82e4SJeremy 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. 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; 21ca735530SJeremy L Thompson const char fallback_resource[] = "/gpu/cuda/ref"; 22ca735530SJeremy L Thompson Ceed ceed_shared; 23ca735530SJeremy L Thompson Ceed_Cuda *data; 24ca735530SJeremy L Thompson 25bc246734SJeremy L Thompson CeedCallBackend(CeedGetResourceRoot(ceed, resource, ":", &resource_root)); 266574a04fSJeremy L Thompson CeedCheck(!strcmp(resource_root, "/gpu/cuda") || !strcmp(resource_root, "/gpu/cuda/gen"), ceed, CEED_ERROR_BACKEND, 276574a04fSJeremy L Thompson "Cuda backend cannot use resource: %s", resource); 282b730f8bSJeremy L Thompson CeedCallBackend(CeedFree(&resource_root)); 29241a4b83SYohann 302b730f8bSJeremy L Thompson CeedCallBackend(CeedCalloc(1, &data)); 312b730f8bSJeremy L Thompson CeedCallBackend(CeedSetData(ceed, data)); 32eb7e6cafSJeremy L Thompson CeedCallBackend(CeedInit_Cuda(ceed, resource)); 33abfaacbbSSander Arens 34b2165e7aSSebastian Grimberg CeedCall(CeedInit("/gpu/cuda/shared", &ceed_shared)); 35b2165e7aSSebastian Grimberg CeedCallBackend(CeedSetDelegate(ceed, ceed_shared)); 366dbfb411Snbeams 37ca735530SJeremy L Thompson CeedCallBackend(CeedSetOperatorFallbackResource(ceed, fallback_resource)); 38ccaff030SJeremy L Thompson 392b730f8bSJeremy L Thompson CeedCallBackend(CeedSetBackendFunction(ceed, "Ceed", ceed, "QFunctionCreate", CeedQFunctionCreate_Cuda_gen)); 402b730f8bSJeremy L Thompson CeedCallBackend(CeedSetBackendFunction(ceed, "Ceed", ceed, "OperatorCreate", CeedOperatorCreate_Cuda_gen)); 412b730f8bSJeremy 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 //------------------------------------------------------------------------------ 482b730f8bSJeremy L Thompson CEED_INTERN int CeedRegister_Cuda_Gen(void) { return CeedRegister("/gpu/cuda/gen", CeedInit_Cuda_gen, 20); } 492a86cc9dSSebastian Grimberg 50ab213215SJeremy L Thompson //------------------------------------------------------------------------------ 51