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/backend.h> 9 #include <ceed/ceed.h> 10 #include <cuda_runtime.h> 11 #include <stdio.h> 12 #include <string.h> 13 14 #include "ceed-cuda-gen.h" 15 16 //------------------------------------------------------------------------------ 17 // Apply QFunction 18 //------------------------------------------------------------------------------ 19 static int CeedQFunctionApply_Cuda_gen(CeedQFunction qf, CeedInt Q, CeedVector *U, CeedVector *V) { 20 Ceed ceed; 21 CeedCallBackend(CeedQFunctionGetCeed(qf, &ceed)); 22 return CeedError(ceed, CEED_ERROR_BACKEND, "Backend does not implement QFunctionApply"); 23 } 24 25 //------------------------------------------------------------------------------ 26 // Destroy QFunction 27 //------------------------------------------------------------------------------ 28 static int CeedQFunctionDestroy_Cuda_gen(CeedQFunction qf) { 29 CeedQFunction_Cuda_gen *data; 30 CeedCallBackend(CeedQFunctionGetData(qf, &data)); 31 Ceed ceed; 32 CeedCallBackend(CeedQFunctionGetCeed(qf, &ceed)); 33 CeedCallCuda(ceed, cudaFree(data->d_c)); 34 CeedCallBackend(CeedFree(&data->q_function_source)); 35 CeedCallBackend(CeedFree(&data)); 36 return CEED_ERROR_SUCCESS; 37 } 38 39 //------------------------------------------------------------------------------ 40 // Create QFunction 41 //------------------------------------------------------------------------------ 42 int CeedQFunctionCreate_Cuda_gen(CeedQFunction qf) { 43 Ceed ceed; 44 CeedQFunctionGetCeed(qf, &ceed); 45 CeedQFunction_Cuda_gen *data; 46 CeedCallBackend(CeedCalloc(1, &data)); 47 CeedCallBackend(CeedQFunctionSetData(qf, data)); 48 49 // Read QFunction source 50 CeedCallBackend(CeedQFunctionGetKernelName(qf, &data->q_function_name)); 51 CeedDebug256(ceed, 2, "----- Loading QFunction User Source -----\n"); 52 CeedCallBackend(CeedQFunctionLoadSourceToBuffer(qf, &data->q_function_source)); 53 CeedDebug256(ceed, 2, "----- Loading QFunction User Source Complete! -----\n"); 54 if (!data->q_function_source) { 55 // LCOV_EXCL_START 56 return CeedError(ceed, CEED_ERROR_UNSUPPORTED, "/gpu/cuda/gen backend requires QFunction source code file"); 57 // LCOV_EXCL_STOP 58 } 59 60 CeedCallBackend(CeedSetBackendFunction(ceed, "QFunction", qf, "Apply", CeedQFunctionApply_Cuda_gen)); 61 CeedCallBackend(CeedSetBackendFunction(ceed, "QFunction", qf, "Destroy", CeedQFunctionDestroy_Cuda_gen)); 62 return CEED_ERROR_SUCCESS; 63 } 64 65 //------------------------------------------------------------------------------ 66