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> 137fcac036SJeremy L Thompson #include <hip/hip_runtime.h> 14*0df8cb37SJeremy L Thompson #if (HIP_VERSION >= 50200000) 15*0df8cb37SJeremy L Thompson #include <hipblas/hipblas.h> 16*0df8cb37SJeremy L Thompson #else 177fcac036SJeremy L Thompson #include <hipblas.h> 18*0df8cb37SJeremy L Thompson #endif 197fcac036SJeremy L Thompson 207fcac036SJeremy L Thompson #define QUOTE(...) #__VA_ARGS__ 217fcac036SJeremy L Thompson 227fcac036SJeremy L Thompson #define CeedChk_Hip(ceed, x) \ 237fcac036SJeremy L Thompson do { \ 247fcac036SJeremy L Thompson hipError_t hip_result = x; \ 257fcac036SJeremy L Thompson if (hip_result != hipSuccess) { \ 267fcac036SJeremy L Thompson const char *msg = hipGetErrorName(hip_result); \ 277fcac036SJeremy L Thompson return CeedError((ceed), CEED_ERROR_BACKEND, msg); \ 287fcac036SJeremy L Thompson } \ 297fcac036SJeremy L Thompson } while (0) 307fcac036SJeremy L Thompson 317fcac036SJeremy L Thompson #define CeedChk_Hipblas(ceed, x) \ 327fcac036SJeremy L Thompson do { \ 337fcac036SJeremy L Thompson hipblasStatus_t hipblas_result = x; \ 347fcac036SJeremy L Thompson if (hipblas_result != HIPBLAS_STATUS_SUCCESS) { \ 357fcac036SJeremy L Thompson const char *msg = hipblasGetErrorName(hipblas_result); \ 367fcac036SJeremy L Thompson return CeedError((ceed), CEED_ERROR_BACKEND, msg); \ 377fcac036SJeremy L Thompson } \ 387fcac036SJeremy L Thompson } while (0) 397fcac036SJeremy L Thompson 407fcac036SJeremy L Thompson #define CASE(name) case name: return #name 417fcac036SJeremy L Thompson // LCOV_EXCL_START 427fcac036SJeremy L Thompson CEED_UNUSED static const char *hipblasGetErrorName(hipblasStatus_t error) { 437fcac036SJeremy L Thompson switch (error) { 447fcac036SJeremy L Thompson CASE(HIPBLAS_STATUS_SUCCESS); 457fcac036SJeremy L Thompson CASE(HIPBLAS_STATUS_NOT_INITIALIZED); 467fcac036SJeremy L Thompson CASE(HIPBLAS_STATUS_ALLOC_FAILED); 477fcac036SJeremy L Thompson CASE(HIPBLAS_STATUS_INVALID_VALUE); 487fcac036SJeremy L Thompson CASE(HIPBLAS_STATUS_ARCH_MISMATCH); 497fcac036SJeremy L Thompson CASE(HIPBLAS_STATUS_MAPPING_ERROR); 507fcac036SJeremy L Thompson CASE(HIPBLAS_STATUS_EXECUTION_FAILED); 517fcac036SJeremy L Thompson CASE(HIPBLAS_STATUS_INTERNAL_ERROR); 527fcac036SJeremy L Thompson default: return "HIPBLAS_STATUS_UNKNOWN_ERROR"; 537fcac036SJeremy L Thompson } 547fcac036SJeremy L Thompson } 557fcac036SJeremy L Thompson // LCOV_EXCL_STOP 567fcac036SJeremy L Thompson 577fcac036SJeremy L Thompson typedef struct { 580d0321e0SJeremy L Thompson int opt_block_size; 590d0321e0SJeremy L Thompson int device_id; 600d0321e0SJeremy L Thompson hipblasHandle_t hipblas_handle; 617fcac036SJeremy L Thompson } Ceed_Hip; 627fcac036SJeremy L Thompson 63b11824b3SJeremy L Thompson CEED_INTERN int CeedHipGetResourceRoot(Ceed ceed, const char *resource, 64b11824b3SJeremy L Thompson char **resource_root); 65b11824b3SJeremy L Thompson 66f87d896cSJeremy L Thompson CEED_INTERN int CeedHipInit(Ceed ceed, const char *resource); 677fcac036SJeremy L Thompson 687fcac036SJeremy L Thompson CEED_INTERN int CeedDestroy_Hip(Ceed ceed); 697fcac036SJeremy L Thompson 707fcac036SJeremy L Thompson #endif // _ceed_hip_common_h 71