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 849aac155SJeremy L Thompson #include <ceed.h> 9ec3da8bcSJed Brown #include <ceed/backend.h> 103d576824SJeremy L Thompson #include <cuda_runtime.h> 112b730f8bSJeremy L Thompson 1249aac155SJeremy L Thompson #include "../cuda/ceed-cuda-common.h" 13241a4b83SYohann #include "ceed-cuda-gen.h" 14241a4b83SYohann 15ab213215SJeremy L Thompson //------------------------------------------------------------------------------ 16ab213215SJeremy L Thompson // Apply QFunction 17ab213215SJeremy L Thompson //------------------------------------------------------------------------------ 182b730f8bSJeremy L Thompson static int CeedQFunctionApply_Cuda_gen(CeedQFunction qf, CeedInt Q, CeedVector *U, CeedVector *V) { 19*6e536b99SJeremy L Thompson return CeedError(CeedQFunctionReturnCeed(qf), CEED_ERROR_BACKEND, "Backend does not implement QFunctionApply"); 20241a4b83SYohann } 21241a4b83SYohann 22ab213215SJeremy L Thompson //------------------------------------------------------------------------------ 23ab213215SJeremy L Thompson // Destroy QFunction 24ab213215SJeremy L Thompson //------------------------------------------------------------------------------ 25241a4b83SYohann static int CeedQFunctionDestroy_Cuda_gen(CeedQFunction qf) { 26ca735530SJeremy L Thompson CeedQFunction_Cuda_gen *data; 27ca735530SJeremy L Thompson 28ca735530SJeremy L Thompson CeedCallBackend(CeedQFunctionGetData(qf, &data)); 29*6e536b99SJeremy L Thompson CeedCallCuda(CeedQFunctionReturnCeed(qf), cudaFree(data->d_c)); 3009095acaSJeremy L Thompson CeedCallBackend(CeedFree(&data->qfunction_source)); 312b730f8bSJeremy L Thompson CeedCallBackend(CeedFree(&data)); 32e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 33241a4b83SYohann } 34241a4b83SYohann 35ab213215SJeremy L Thompson //------------------------------------------------------------------------------ 36ab213215SJeremy L Thompson // Create QFunction 37ab213215SJeremy L Thompson //------------------------------------------------------------------------------ 38241a4b83SYohann int CeedQFunctionCreate_Cuda_gen(CeedQFunction qf) { 39241a4b83SYohann Ceed ceed; 40241a4b83SYohann CeedQFunction_Cuda_gen *data; 41ca735530SJeremy L Thompson 42ca735530SJeremy L Thompson CeedQFunctionGetCeed(qf, &ceed); 432b730f8bSJeremy L Thompson CeedCallBackend(CeedCalloc(1, &data)); 442b730f8bSJeremy L Thompson CeedCallBackend(CeedQFunctionSetData(qf, data)); 45241a4b83SYohann 463d3250a0SJeremy L Thompson // Read QFunction source 4709095acaSJeremy L Thompson CeedCallBackend(CeedQFunctionGetKernelName(qf, &data->qfunction_name)); 4823d4529eSJeremy L Thompson CeedDebug256(ceed, CEED_DEBUG_COLOR_SUCCESS, "----- Loading QFunction User Source -----\n"); 4909095acaSJeremy L Thompson CeedCallBackend(CeedQFunctionLoadSourceToBuffer(qf, &data->qfunction_source)); 5023d4529eSJeremy L Thompson CeedDebug256(ceed, CEED_DEBUG_COLOR_SUCCESS, "----- Loading QFunction User Source Complete! -----\n"); 5109095acaSJeremy L Thompson CeedCheck(data->qfunction_source, ceed, CEED_ERROR_UNSUPPORTED, "/gpu/cuda/gen backend requires QFunction source code file"); 52241a4b83SYohann 532b730f8bSJeremy L Thompson CeedCallBackend(CeedSetBackendFunction(ceed, "QFunction", qf, "Apply", CeedQFunctionApply_Cuda_gen)); 542b730f8bSJeremy L Thompson CeedCallBackend(CeedSetBackendFunction(ceed, "QFunction", qf, "Destroy", CeedQFunctionDestroy_Cuda_gen)); 55e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 56241a4b83SYohann } 579e201c85SYohann 58ab213215SJeremy L Thompson //------------------------------------------------------------------------------ 59