1 // Copyright (c) 2017-2022, Lawrence Livermore National Security, LLC and other CEED contributors. 2 // All Rights Reserved. See the top-level LICENSE and NOTICE files for details. 3 // 4 // SPDX-License-Identifier: BSD-2-Clause 5 // 6 // This file is part of CEED: http://github.com/ceed 7 8 #include <ceed.h> 9 #include <ceed/backend.h> 10 #include <cuda_runtime.h> 11 12 #include "../cuda/ceed-cuda-common.h" 13 #include "ceed-cuda-gen.h" 14 15 //------------------------------------------------------------------------------ 16 // Apply QFunction 17 //------------------------------------------------------------------------------ 18 static int CeedQFunctionApply_Cuda_gen(CeedQFunction qf, CeedInt Q, CeedVector *U, CeedVector *V) { 19 Ceed ceed; 20 CeedCallBackend(CeedQFunctionGetCeed(qf, &ceed)); 21 return CeedError(ceed, CEED_ERROR_BACKEND, "Backend does not implement QFunctionApply"); 22 } 23 24 //------------------------------------------------------------------------------ 25 // Destroy QFunction 26 //------------------------------------------------------------------------------ 27 static int CeedQFunctionDestroy_Cuda_gen(CeedQFunction qf) { 28 CeedQFunction_Cuda_gen *data; 29 CeedCallBackend(CeedQFunctionGetData(qf, &data)); 30 Ceed ceed; 31 CeedCallBackend(CeedQFunctionGetCeed(qf, &ceed)); 32 CeedCallCuda(ceed, cudaFree(data->d_c)); 33 CeedCallBackend(CeedFree(&data->q_function_source)); 34 CeedCallBackend(CeedFree(&data)); 35 return CEED_ERROR_SUCCESS; 36 } 37 38 //------------------------------------------------------------------------------ 39 // Create QFunction 40 //------------------------------------------------------------------------------ 41 int CeedQFunctionCreate_Cuda_gen(CeedQFunction qf) { 42 Ceed ceed; 43 CeedQFunctionGetCeed(qf, &ceed); 44 CeedQFunction_Cuda_gen *data; 45 CeedCallBackend(CeedCalloc(1, &data)); 46 CeedCallBackend(CeedQFunctionSetData(qf, data)); 47 48 // Read QFunction source 49 CeedCallBackend(CeedQFunctionGetKernelName(qf, &data->q_function_name)); 50 CeedDebug256(ceed, 2, "----- Loading QFunction User Source -----\n"); 51 CeedCallBackend(CeedQFunctionLoadSourceToBuffer(qf, &data->q_function_source)); 52 CeedDebug256(ceed, 2, "----- Loading QFunction User Source Complete! -----\n"); 53 if (!data->q_function_source) { 54 // LCOV_EXCL_START 55 return CeedError(ceed, CEED_ERROR_UNSUPPORTED, "/gpu/cuda/gen backend requires QFunction source code file"); 56 // LCOV_EXCL_STOP 57 } 58 59 CeedCallBackend(CeedSetBackendFunction(ceed, "QFunction", qf, "Apply", CeedQFunctionApply_Cuda_gen)); 60 CeedCallBackend(CeedSetBackendFunction(ceed, "QFunction", qf, "Destroy", CeedQFunctionDestroy_Cuda_gen)); 61 return CEED_ERROR_SUCCESS; 62 } 63 64 //------------------------------------------------------------------------------ 65