1*9ba83ac0SJeremy L Thompson // Copyright (c) 2017-2026, 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; 2146b50f9eSZach Atkins Ceed ceed_shared, ceed_ref; 22ca735530SJeremy L Thompson Ceed_Cuda *data; 23ca735530SJeremy L Thompson 24bc246734SJeremy L Thompson CeedCallBackend(CeedGetResourceRoot(ceed, resource, ":", &resource_root)); 256574a04fSJeremy L Thompson CeedCheck(!strcmp(resource_root, "/gpu/cuda") || !strcmp(resource_root, "/gpu/cuda/gen"), ceed, CEED_ERROR_BACKEND, 266574a04fSJeremy L Thompson "Cuda backend cannot use resource: %s", resource); 272b730f8bSJeremy L Thompson CeedCallBackend(CeedFree(&resource_root)); 28241a4b83SYohann 292b730f8bSJeremy L Thompson CeedCallBackend(CeedCalloc(1, &data)); 302b730f8bSJeremy L Thompson CeedCallBackend(CeedSetData(ceed, data)); 31eb7e6cafSJeremy L Thompson CeedCallBackend(CeedInit_Cuda(ceed, resource)); 32abfaacbbSSander Arens 335a5594ffSJeremy L Thompson CeedCallBackend(CeedInit("/gpu/cuda/shared", &ceed_shared)); 34b2165e7aSSebastian Grimberg CeedCallBackend(CeedSetDelegate(ceed, ceed_shared)); 359bc66399SJeremy L Thompson CeedCallBackend(CeedDestroy(&ceed_shared)); 366dbfb411Snbeams 3746b50f9eSZach Atkins CeedCallBackend(CeedInit("/gpu/cuda/ref", &ceed_ref)); 3846b50f9eSZach Atkins CeedCallBackend(CeedSetOperatorFallbackCeed(ceed, ceed_ref)); 3946b50f9eSZach Atkins CeedCallBackend(CeedDestroy(&ceed_ref)); 40ccaff030SJeremy L Thompson 412b730f8bSJeremy L Thompson CeedCallBackend(CeedSetBackendFunction(ceed, "Ceed", ceed, "QFunctionCreate", CeedQFunctionCreate_Cuda_gen)); 422b730f8bSJeremy L Thompson CeedCallBackend(CeedSetBackendFunction(ceed, "Ceed", ceed, "OperatorCreate", CeedOperatorCreate_Cuda_gen)); 43c99afcd8SJeremy L Thompson CeedCallBackend(CeedSetBackendFunction(ceed, "Ceed", ceed, "CompositeOperatorCreate", CeedOperatorCreate_Cuda_gen)); 448b97b69aSJeremy L Thompson CeedCallBackend(CeedSetBackendFunction(ceed, "Ceed", ceed, "OperatorCreateAtPoints", CeedOperatorCreate_Cuda_gen)); 452b730f8bSJeremy L Thompson CeedCallBackend(CeedSetBackendFunction(ceed, "Ceed", ceed, "Destroy", CeedDestroy_Cuda)); 46e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 47241a4b83SYohann } 48241a4b83SYohann 49ab213215SJeremy L Thompson //------------------------------------------------------------------------------ 50ab213215SJeremy L Thompson // Register backend 51ab213215SJeremy L Thompson //------------------------------------------------------------------------------ 522b730f8bSJeremy L Thompson CEED_INTERN int CeedRegister_Cuda_Gen(void) { return CeedRegister("/gpu/cuda/gen", CeedInit_Cuda_gen, 20); } 532a86cc9dSSebastian Grimberg 54ab213215SJeremy L Thompson //------------------------------------------------------------------------------ 55