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 8ec3da8bcSJed Brown #include <ceed/backend.h> 9*2b730f8bSJeremy L Thompson #include <ceed/ceed.h> 103d576824SJeremy L Thompson #include <cuda_runtime.h> 11241a4b83SYohann #include <stdio.h> 123d576824SJeremy L Thompson #include <string.h> 13*2b730f8bSJeremy L Thompson 14241a4b83SYohann #include "ceed-cuda-gen.h" 15241a4b83SYohann 16ab213215SJeremy L Thompson //------------------------------------------------------------------------------ 17ab213215SJeremy L Thompson // Apply QFunction 18ab213215SJeremy L Thompson //------------------------------------------------------------------------------ 19*2b730f8bSJeremy L Thompson static int CeedQFunctionApply_Cuda_gen(CeedQFunction qf, CeedInt Q, CeedVector *U, CeedVector *V) { 20241a4b83SYohann Ceed ceed; 21*2b730f8bSJeremy L Thompson CeedCallBackend(CeedQFunctionGetCeed(qf, &ceed)); 22*2b730f8bSJeremy L Thompson return CeedError(ceed, CEED_ERROR_BACKEND, "Backend does not implement QFunctionApply"); 23241a4b83SYohann } 24241a4b83SYohann 25ab213215SJeremy L Thompson //------------------------------------------------------------------------------ 26ab213215SJeremy L Thompson // Destroy QFunction 27ab213215SJeremy L Thompson //------------------------------------------------------------------------------ 28241a4b83SYohann static int CeedQFunctionDestroy_Cuda_gen(CeedQFunction qf) { 29241a4b83SYohann CeedQFunction_Cuda_gen *data; 30*2b730f8bSJeremy L Thompson CeedCallBackend(CeedQFunctionGetData(qf, &data)); 31241a4b83SYohann Ceed ceed; 32*2b730f8bSJeremy L Thompson CeedCallBackend(CeedQFunctionGetCeed(qf, &ceed)); 33*2b730f8bSJeremy L Thompson CeedCallCuda(ceed, cudaFree(data->d_c)); 34*2b730f8bSJeremy L Thompson CeedCallBackend(CeedFree(&data->q_function_source)); 35*2b730f8bSJeremy L Thompson CeedCallBackend(CeedFree(&data)); 36e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 37241a4b83SYohann } 38241a4b83SYohann 39ab213215SJeremy L Thompson //------------------------------------------------------------------------------ 40ab213215SJeremy L Thompson // Create QFunction 41ab213215SJeremy L Thompson //------------------------------------------------------------------------------ 42241a4b83SYohann int CeedQFunctionCreate_Cuda_gen(CeedQFunction qf) { 43241a4b83SYohann Ceed ceed; 44241a4b83SYohann CeedQFunctionGetCeed(qf, &ceed); 45241a4b83SYohann CeedQFunction_Cuda_gen *data; 46*2b730f8bSJeremy L Thompson CeedCallBackend(CeedCalloc(1, &data)); 47*2b730f8bSJeremy L Thompson CeedCallBackend(CeedQFunctionSetData(qf, data)); 48241a4b83SYohann 493d3250a0SJeremy L Thompson // Read QFunction source 50*2b730f8bSJeremy L Thompson CeedCallBackend(CeedQFunctionGetKernelName(qf, &data->q_function_name)); 5146dc0734SJeremy L Thompson CeedDebug256(ceed, 2, "----- Loading QFunction User Source -----\n"); 52*2b730f8bSJeremy L Thompson CeedCallBackend(CeedQFunctionLoadSourceToBuffer(qf, &data->q_function_source)); 5346dc0734SJeremy L Thompson CeedDebug256(ceed, 2, "----- Loading QFunction User Source Complete! -----\n"); 54*2b730f8bSJeremy L Thompson if (!data->q_function_source) { 553d3250a0SJeremy L Thompson // LCOV_EXCL_START 56*2b730f8bSJeremy L Thompson return CeedError(ceed, CEED_ERROR_UNSUPPORTED, "/gpu/cuda/gen backend requires QFunction source code file"); 573d3250a0SJeremy L Thompson // LCOV_EXCL_STOP 58*2b730f8bSJeremy L Thompson } 59241a4b83SYohann 60*2b730f8bSJeremy L Thompson CeedCallBackend(CeedSetBackendFunction(ceed, "QFunction", qf, "Apply", CeedQFunctionApply_Cuda_gen)); 61*2b730f8bSJeremy L Thompson CeedCallBackend(CeedSetBackendFunction(ceed, "QFunction", qf, "Destroy", CeedQFunctionDestroy_Cuda_gen)); 62e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 63241a4b83SYohann } 649e201c85SYohann 65ab213215SJeremy L Thompson //------------------------------------------------------------------------------ 66