1 // Copyright (c) 2017-2018, Lawrence Livermore National Security, LLC. 2 // Produced at the Lawrence Livermore National Laboratory. LLNL-CODE-734707. 3 // All Rights reserved. See files LICENSE and NOTICE for details. 4 // 5 // This file is part of CEED, a collection of benchmarks, miniapps, software 6 // libraries and APIs for efficient high-order finite element and spectral 7 // element discretizations for exascale applications. For more information and 8 // source code availability see http://github.com/ceed. 9 // 10 // The CEED research is supported by the Exascale Computing Project 17-SC-20-SC, 11 // a collaborative effort of two U.S. Department of Energy organizations (Office 12 // of Science and the National Nuclear Security Administration) responsible for 13 // the planning and preparation of a capable exascale ecosystem, including 14 // software, applications, hardware, advanced system engineering and early 15 // testbed platforms, in support of the nation's exascale computing imperative. 16 17 #include <ceed/ceed.h> 18 #include <ceed/backend.h> 19 #include <cuda_runtime.h> 20 #include <stdio.h> 21 #include <string.h> 22 #include "ceed-cuda-gen.h" 23 24 //------------------------------------------------------------------------------ 25 // Apply QFunction 26 //------------------------------------------------------------------------------ 27 static int CeedQFunctionApply_Cuda_gen(CeedQFunction qf, CeedInt Q, 28 CeedVector *U, CeedVector *V) { 29 int ierr; 30 Ceed ceed; 31 ierr = CeedQFunctionGetCeed(qf, &ceed); CeedChkBackend(ierr); 32 return CeedError(ceed, CEED_ERROR_BACKEND, 33 "Backend does not implement QFunctionApply"); 34 } 35 36 //------------------------------------------------------------------------------ 37 // Destroy QFunction 38 //------------------------------------------------------------------------------ 39 static int CeedQFunctionDestroy_Cuda_gen(CeedQFunction qf) { 40 int ierr; 41 CeedQFunction_Cuda_gen *data; 42 ierr = CeedQFunctionGetData(qf, &data); CeedChkBackend(ierr); 43 Ceed ceed; 44 ierr = CeedQFunctionGetCeed(qf, &ceed); CeedChkBackend(ierr); 45 ierr = cudaFree(data->d_c); CeedChk_Cu(ceed, ierr); 46 ierr = CeedFree(&data->qFunctionSource); CeedChkBackend(ierr); 47 ierr = CeedFree(&data); CeedChkBackend(ierr); 48 return CEED_ERROR_SUCCESS; 49 } 50 51 //------------------------------------------------------------------------------ 52 // Create QFunction 53 //------------------------------------------------------------------------------ 54 int CeedQFunctionCreate_Cuda_gen(CeedQFunction qf) { 55 int ierr; 56 Ceed ceed; 57 CeedQFunctionGetCeed(qf, &ceed); 58 CeedQFunction_Cuda_gen *data; 59 ierr = CeedCalloc(1, &data); CeedChkBackend(ierr); 60 ierr = CeedQFunctionSetData(qf, data); CeedChkBackend(ierr); 61 62 // Read QFunction source 63 ierr = CeedQFunctionGetKernelName(qf, &data->qFunctionName); 64 CeedChkBackend(ierr); 65 CeedDebug256(ceed, 2, "----- Loading QFunction User Source -----\n"); 66 ierr = CeedQFunctionLoadSourceToBuffer(qf, &data->qFunctionSource); 67 CeedChkBackend(ierr); 68 CeedDebug256(ceed, 2, "----- Loading QFunction User Source Complete! -----\n"); 69 if (!data->qFunctionSource) 70 // LCOV_EXCL_START 71 return CeedError(ceed, CEED_ERROR_UNSUPPORTED, 72 "/gpu/cuda/gen backend requires QFunction source code file"); 73 // LCOV_EXCL_STOP 74 75 ierr = CeedSetBackendFunction(ceed, "QFunction", qf, "Apply", 76 CeedQFunctionApply_Cuda_gen); CeedChkBackend(ierr); 77 ierr = CeedSetBackendFunction(ceed, "QFunction", qf, "Destroy", 78 CeedQFunctionDestroy_Cuda_gen); CeedChkBackend(ierr); 79 return CEED_ERROR_SUCCESS; 80 } 81 //------------------------------------------------------------------------------ 82