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 <hip/hip_runtime.h> 20 #include <stdio.h> 21 #include <string.h> 22 #include "ceed-hip-gen.h" 23 #include "../hip/ceed-hip.h" 24 25 //------------------------------------------------------------------------------ 26 // Apply QFunction 27 //------------------------------------------------------------------------------ 28 static int CeedQFunctionApply_Hip_gen(CeedQFunction qf, CeedInt Q, 29 CeedVector *U, CeedVector *V) { 30 int ierr; 31 Ceed ceed; 32 ierr = CeedQFunctionGetCeed(qf, &ceed); CeedChkBackend(ierr); 33 return CeedError(ceed, CEED_ERROR_BACKEND, 34 "Backend does not implement QFunctionApply"); 35 } 36 37 //------------------------------------------------------------------------------ 38 // Destroy QFunction 39 //------------------------------------------------------------------------------ 40 static int CeedQFunctionDestroy_Hip_gen(CeedQFunction qf) { 41 int ierr; 42 CeedQFunction_Hip_gen *data; 43 ierr = CeedQFunctionGetData(qf, &data); CeedChkBackend(ierr); 44 Ceed ceed; 45 ierr = CeedQFunctionGetCeed(qf, &ceed); CeedChkBackend(ierr); 46 ierr = hipFree(data->d_c); CeedChk_Hip(ceed, ierr); 47 ierr = CeedFree(&data->qFunctionSource); CeedChkBackend(ierr); 48 ierr = CeedFree(&data); CeedChkBackend(ierr); 49 return CEED_ERROR_SUCCESS; 50 } 51 52 //------------------------------------------------------------------------------ 53 // Create QFunction 54 //------------------------------------------------------------------------------ 55 int CeedQFunctionCreate_Hip_gen(CeedQFunction qf) { 56 int ierr; 57 Ceed ceed; 58 CeedQFunctionGetCeed(qf, &ceed); 59 CeedQFunction_Hip_gen *data; 60 ierr = CeedCalloc(1, &data); CeedChkBackend(ierr); 61 ierr = CeedQFunctionSetData(qf, data); CeedChkBackend(ierr); 62 63 // Read QFunction source 64 ierr = CeedQFunctionGetKernelName(qf, &data->qFunctionName); 65 CeedChkBackend(ierr); 66 ierr = CeedQFunctionLoadSourceToBuffer(qf, &data->qFunctionSource); 67 CeedChkBackend(ierr); 68 if (!data->qFunctionSource) 69 // LCOV_EXCL_START 70 return CeedError(ceed, CEED_ERROR_UNSUPPORTED, 71 "/gpu/hip/gen backend requires QFunction source code file"); 72 // LCOV_EXCL_STOP 73 74 ierr = CeedSetBackendFunction(ceed, "QFunction", qf, "Apply", 75 CeedQFunctionApply_Hip_gen); CeedChkBackend(ierr); 76 ierr = CeedSetBackendFunction(ceed, "QFunction", qf, "Destroy", 77 CeedQFunctionDestroy_Hip_gen); CeedChkBackend(ierr); 78 return CEED_ERROR_SUCCESS; 79 } 80 //------------------------------------------------------------------------------ 81