13d8e8822SJeremy L Thompson // Copyright (c) 2017-2022, Lawrence Livermore National Security, LLC and other CEED contributors. 23d8e8822SJeremy L Thompson // All Rights Reserved. See the top-level LICENSE and NOTICE files for details. 37fcac036SJeremy L Thompson // 43d8e8822SJeremy L Thompson // SPDX-License-Identifier: BSD-2-Clause 57fcac036SJeremy L Thompson // 63d8e8822SJeremy L Thompson // This file is part of CEED: http://github.com/ceed 77fcac036SJeremy L Thompson 87fcac036SJeremy L Thompson #ifndef _ceed_common_hip_h 97fcac036SJeremy L Thompson #define _ceed_common_hip_h 107fcac036SJeremy L Thompson 117fcac036SJeremy L Thompson #include <ceed/ceed.h> 127fcac036SJeremy L Thompson #include <ceed/backend.h> 13*9e201c85SYohann #include <ceed/jit-source/hip/hip-types.h> 147fcac036SJeremy L Thompson #include <hip/hip_runtime.h> 150df8cb37SJeremy L Thompson #if (HIP_VERSION >= 50200000) 160df8cb37SJeremy L Thompson #include <hipblas/hipblas.h> 170df8cb37SJeremy L Thompson #else 187fcac036SJeremy L Thompson #include <hipblas.h> 190df8cb37SJeremy L Thompson #endif 207fcac036SJeremy L Thompson 217fcac036SJeremy L Thompson #define QUOTE(...) #__VA_ARGS__ 227fcac036SJeremy L Thompson 237fcac036SJeremy L Thompson #define CeedChk_Hip(ceed, x) \ 247fcac036SJeremy L Thompson do { \ 257fcac036SJeremy L Thompson hipError_t hip_result = x; \ 267fcac036SJeremy L Thompson if (hip_result != hipSuccess) { \ 277fcac036SJeremy L Thompson const char *msg = hipGetErrorName(hip_result); \ 287fcac036SJeremy L Thompson return CeedError((ceed), CEED_ERROR_BACKEND, msg); \ 297fcac036SJeremy L Thompson } \ 307fcac036SJeremy L Thompson } while (0) 317fcac036SJeremy L Thompson 327fcac036SJeremy L Thompson #define CeedChk_Hipblas(ceed, x) \ 337fcac036SJeremy L Thompson do { \ 347fcac036SJeremy L Thompson hipblasStatus_t hipblas_result = x; \ 357fcac036SJeremy L Thompson if (hipblas_result != HIPBLAS_STATUS_SUCCESS) { \ 367fcac036SJeremy L Thompson const char *msg = hipblasGetErrorName(hipblas_result); \ 377fcac036SJeremy L Thompson return CeedError((ceed), CEED_ERROR_BACKEND, msg); \ 387fcac036SJeremy L Thompson } \ 397fcac036SJeremy L Thompson } while (0) 407fcac036SJeremy L Thompson 417fcac036SJeremy L Thompson #define CASE(name) case name: return #name 427fcac036SJeremy L Thompson // LCOV_EXCL_START 437fcac036SJeremy L Thompson CEED_UNUSED static const char *hipblasGetErrorName(hipblasStatus_t error) { 447fcac036SJeremy L Thompson switch (error) { 457fcac036SJeremy L Thompson CASE(HIPBLAS_STATUS_SUCCESS); 467fcac036SJeremy L Thompson CASE(HIPBLAS_STATUS_NOT_INITIALIZED); 477fcac036SJeremy L Thompson CASE(HIPBLAS_STATUS_ALLOC_FAILED); 487fcac036SJeremy L Thompson CASE(HIPBLAS_STATUS_INVALID_VALUE); 497fcac036SJeremy L Thompson CASE(HIPBLAS_STATUS_ARCH_MISMATCH); 507fcac036SJeremy L Thompson CASE(HIPBLAS_STATUS_MAPPING_ERROR); 517fcac036SJeremy L Thompson CASE(HIPBLAS_STATUS_EXECUTION_FAILED); 527fcac036SJeremy L Thompson CASE(HIPBLAS_STATUS_INTERNAL_ERROR); 537fcac036SJeremy L Thompson default: return "HIPBLAS_STATUS_UNKNOWN_ERROR"; 547fcac036SJeremy L Thompson } 557fcac036SJeremy L Thompson } 567fcac036SJeremy L Thompson // LCOV_EXCL_STOP 577fcac036SJeremy L Thompson 587fcac036SJeremy L Thompson typedef struct { 590d0321e0SJeremy L Thompson int opt_block_size; 600d0321e0SJeremy L Thompson int device_id; 610d0321e0SJeremy L Thompson hipblasHandle_t hipblas_handle; 627fcac036SJeremy L Thompson } Ceed_Hip; 637fcac036SJeremy L Thompson 64b11824b3SJeremy L Thompson CEED_INTERN int CeedHipGetResourceRoot(Ceed ceed, const char *resource, 65b11824b3SJeremy L Thompson char **resource_root); 66b11824b3SJeremy L Thompson 67f87d896cSJeremy L Thompson CEED_INTERN int CeedHipInit(Ceed ceed, const char *resource); 687fcac036SJeremy L Thompson 697fcac036SJeremy L Thompson CEED_INTERN int CeedDestroy_Hip(Ceed ceed); 707fcac036SJeremy L Thompson 717fcac036SJeremy L Thompson #endif // _ceed_hip_common_h 72