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 #ifndef _ceed_common_hip_h 18 #define _ceed_common_hip_h 19 20 #include <ceed/ceed.h> 21 #include <ceed/backend.h> 22 #include <hip/hip_runtime.h> 23 #include <hipblas.h> 24 25 #define QUOTE(...) #__VA_ARGS__ 26 27 #define CeedChk_Hip(ceed, x) \ 28 do { \ 29 hipError_t hip_result = x; \ 30 if (hip_result != hipSuccess) { \ 31 const char *msg = hipGetErrorName(hip_result); \ 32 return CeedError((ceed), CEED_ERROR_BACKEND, msg); \ 33 } \ 34 } while (0) 35 36 #define CeedChk_Hipblas(ceed, x) \ 37 do { \ 38 hipblasStatus_t hipblas_result = x; \ 39 if (hipblas_result != HIPBLAS_STATUS_SUCCESS) { \ 40 const char *msg = hipblasGetErrorName(hipblas_result); \ 41 return CeedError((ceed), CEED_ERROR_BACKEND, msg); \ 42 } \ 43 } while (0) 44 45 #define CASE(name) case name: return #name 46 // LCOV_EXCL_START 47 CEED_UNUSED static const char *hipblasGetErrorName(hipblasStatus_t error) { 48 switch (error) { 49 CASE(HIPBLAS_STATUS_SUCCESS); 50 CASE(HIPBLAS_STATUS_NOT_INITIALIZED); 51 CASE(HIPBLAS_STATUS_ALLOC_FAILED); 52 CASE(HIPBLAS_STATUS_INVALID_VALUE); 53 CASE(HIPBLAS_STATUS_ARCH_MISMATCH); 54 CASE(HIPBLAS_STATUS_MAPPING_ERROR); 55 CASE(HIPBLAS_STATUS_EXECUTION_FAILED); 56 CASE(HIPBLAS_STATUS_INTERNAL_ERROR); 57 default: return "HIPBLAS_STATUS_UNKNOWN_ERROR"; 58 } 59 } 60 // LCOV_EXCL_STOP 61 62 typedef struct { 63 int opt_block_size; 64 int device_id; 65 hipblasHandle_t hipblas_handle; 66 } Ceed_Hip; 67 68 CEED_INTERN int CeedHipInit(Ceed ceed, const char *resource); 69 70 CEED_INTERN int CeedDestroy_Hip(Ceed ceed); 71 72 #endif // _ceed_hip_common_h 73