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; 21bc246734SJeremy 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)); 29eb7e6cafSJeremy L Thompson CeedCallBackend(CeedInit_Cuda(ceed, resource)); 30abfaacbbSSander Arens 31*b2165e7aSSebastian Grimberg Ceed ceed_shared; 32*b2165e7aSSebastian Grimberg CeedCall(CeedInit("/gpu/cuda/shared", &ceed_shared)); 33*b2165e7aSSebastian Grimberg CeedCallBackend(CeedSetDelegate(ceed, ceed_shared)); 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)); 41*b2165e7aSSebastian Grimberg 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