17fcac036SJeremy L Thompson // Copyright (c) 2017-2018, Lawrence Livermore National Security, LLC. 27fcac036SJeremy L Thompson // Produced at the Lawrence Livermore National Laboratory. LLNL-CODE-734707. 37fcac036SJeremy L Thompson // All Rights reserved. See files LICENSE and NOTICE for details. 47fcac036SJeremy L Thompson // 57fcac036SJeremy L Thompson // This file is part of CEED, a collection of benchmarks, miniapps, software 67fcac036SJeremy L Thompson // libraries and APIs for efficient high-order finite element and spectral 77fcac036SJeremy L Thompson // element discretizations for exascale applications. For more information and 87fcac036SJeremy L Thompson // source code availability see http://github.com/ceed. 97fcac036SJeremy L Thompson // 107fcac036SJeremy L Thompson // The CEED research is supported by the Exascale Computing Project 17-SC-20-SC, 117fcac036SJeremy L Thompson // a collaborative effort of two U.S. Department of Energy organizations (Office 127fcac036SJeremy L Thompson // of Science and the National Nuclear Security Administration) responsible for 137fcac036SJeremy L Thompson // the planning and preparation of a capable exascale ecosystem, including 147fcac036SJeremy L Thompson // software, applications, hardware, advanced system engineering and early 157fcac036SJeremy L Thompson // testbed platforms, in support of the nation's exascale computing imperative. 167fcac036SJeremy L Thompson 177fcac036SJeremy L Thompson #ifndef _ceed_common_hip_h 187fcac036SJeremy L Thompson #define _ceed_common_hip_h 197fcac036SJeremy L Thompson 207fcac036SJeremy L Thompson #include <ceed/ceed.h> 217fcac036SJeremy L Thompson #include <ceed/backend.h> 227fcac036SJeremy L Thompson #include <hip/hip_runtime.h> 237fcac036SJeremy L Thompson #include <hipblas.h> 247fcac036SJeremy L Thompson 257fcac036SJeremy L Thompson #define QUOTE(...) #__VA_ARGS__ 267fcac036SJeremy L Thompson 277fcac036SJeremy L Thompson #define CeedChk_Hip(ceed, x) \ 287fcac036SJeremy L Thompson do { \ 297fcac036SJeremy L Thompson hipError_t hip_result = x; \ 307fcac036SJeremy L Thompson if (hip_result != hipSuccess) { \ 317fcac036SJeremy L Thompson const char *msg = hipGetErrorName(hip_result); \ 327fcac036SJeremy L Thompson return CeedError((ceed), CEED_ERROR_BACKEND, msg); \ 337fcac036SJeremy L Thompson } \ 347fcac036SJeremy L Thompson } while (0) 357fcac036SJeremy L Thompson 367fcac036SJeremy L Thompson #define CeedChk_Hipblas(ceed, x) \ 377fcac036SJeremy L Thompson do { \ 387fcac036SJeremy L Thompson hipblasStatus_t hipblas_result = x; \ 397fcac036SJeremy L Thompson if (hipblas_result != HIPBLAS_STATUS_SUCCESS) { \ 407fcac036SJeremy L Thompson const char *msg = hipblasGetErrorName(hipblas_result); \ 417fcac036SJeremy L Thompson return CeedError((ceed), CEED_ERROR_BACKEND, msg); \ 427fcac036SJeremy L Thompson } \ 437fcac036SJeremy L Thompson } while (0) 447fcac036SJeremy L Thompson 457fcac036SJeremy L Thompson #define CASE(name) case name: return #name 467fcac036SJeremy L Thompson // LCOV_EXCL_START 477fcac036SJeremy L Thompson CEED_UNUSED static const char *hipblasGetErrorName(hipblasStatus_t error) { 487fcac036SJeremy L Thompson switch (error) { 497fcac036SJeremy L Thompson CASE(HIPBLAS_STATUS_SUCCESS); 507fcac036SJeremy L Thompson CASE(HIPBLAS_STATUS_NOT_INITIALIZED); 517fcac036SJeremy L Thompson CASE(HIPBLAS_STATUS_ALLOC_FAILED); 527fcac036SJeremy L Thompson CASE(HIPBLAS_STATUS_INVALID_VALUE); 537fcac036SJeremy L Thompson CASE(HIPBLAS_STATUS_ARCH_MISMATCH); 547fcac036SJeremy L Thompson CASE(HIPBLAS_STATUS_MAPPING_ERROR); 557fcac036SJeremy L Thompson CASE(HIPBLAS_STATUS_EXECUTION_FAILED); 567fcac036SJeremy L Thompson CASE(HIPBLAS_STATUS_INTERNAL_ERROR); 577fcac036SJeremy L Thompson default: return "HIPBLAS_STATUS_UNKNOWN_ERROR"; 587fcac036SJeremy L Thompson } 597fcac036SJeremy L Thompson } 607fcac036SJeremy L Thompson // LCOV_EXCL_STOP 617fcac036SJeremy L Thompson 627fcac036SJeremy L Thompson typedef struct { 637fcac036SJeremy L Thompson int optblocksize; 647fcac036SJeremy L Thompson int deviceId; 657fcac036SJeremy L Thompson hipblasHandle_t hipblasHandle; 667fcac036SJeremy L Thompson } Ceed_Hip; 677fcac036SJeremy L Thompson 68*f87d896cSJeremy L Thompson CEED_INTERN int CeedHipInit(Ceed ceed, const char *resource); 697fcac036SJeremy L Thompson 707fcac036SJeremy L Thompson CEED_INTERN int CeedDestroy_Hip(Ceed ceed); 717fcac036SJeremy L Thompson 727fcac036SJeremy L Thompson #endif // _ceed_hip_common_h 73