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> 147fcac036SJeremy L Thompson #include <hipblas.h> 157fcac036SJeremy L Thompson 167fcac036SJeremy L Thompson #define QUOTE(...) #__VA_ARGS__ 177fcac036SJeremy L Thompson 187fcac036SJeremy L Thompson #define CeedChk_Hip(ceed, x) \ 197fcac036SJeremy L Thompson do { \ 207fcac036SJeremy L Thompson hipError_t hip_result = x; \ 217fcac036SJeremy L Thompson if (hip_result != hipSuccess) { \ 227fcac036SJeremy L Thompson const char *msg = hipGetErrorName(hip_result); \ 237fcac036SJeremy L Thompson return CeedError((ceed), CEED_ERROR_BACKEND, msg); \ 247fcac036SJeremy L Thompson } \ 257fcac036SJeremy L Thompson } while (0) 267fcac036SJeremy L Thompson 277fcac036SJeremy L Thompson #define CeedChk_Hipblas(ceed, x) \ 287fcac036SJeremy L Thompson do { \ 297fcac036SJeremy L Thompson hipblasStatus_t hipblas_result = x; \ 307fcac036SJeremy L Thompson if (hipblas_result != HIPBLAS_STATUS_SUCCESS) { \ 317fcac036SJeremy L Thompson const char *msg = hipblasGetErrorName(hipblas_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 CASE(name) case name: return #name 377fcac036SJeremy L Thompson // LCOV_EXCL_START 387fcac036SJeremy L Thompson CEED_UNUSED static const char *hipblasGetErrorName(hipblasStatus_t error) { 397fcac036SJeremy L Thompson switch (error) { 407fcac036SJeremy L Thompson CASE(HIPBLAS_STATUS_SUCCESS); 417fcac036SJeremy L Thompson CASE(HIPBLAS_STATUS_NOT_INITIALIZED); 427fcac036SJeremy L Thompson CASE(HIPBLAS_STATUS_ALLOC_FAILED); 437fcac036SJeremy L Thompson CASE(HIPBLAS_STATUS_INVALID_VALUE); 447fcac036SJeremy L Thompson CASE(HIPBLAS_STATUS_ARCH_MISMATCH); 457fcac036SJeremy L Thompson CASE(HIPBLAS_STATUS_MAPPING_ERROR); 467fcac036SJeremy L Thompson CASE(HIPBLAS_STATUS_EXECUTION_FAILED); 477fcac036SJeremy L Thompson CASE(HIPBLAS_STATUS_INTERNAL_ERROR); 487fcac036SJeremy L Thompson default: return "HIPBLAS_STATUS_UNKNOWN_ERROR"; 497fcac036SJeremy L Thompson } 507fcac036SJeremy L Thompson } 517fcac036SJeremy L Thompson // LCOV_EXCL_STOP 527fcac036SJeremy L Thompson 537fcac036SJeremy L Thompson typedef struct { 540d0321e0SJeremy L Thompson int opt_block_size; 550d0321e0SJeremy L Thompson int device_id; 560d0321e0SJeremy L Thompson hipblasHandle_t hipblas_handle; 577fcac036SJeremy L Thompson } Ceed_Hip; 587fcac036SJeremy L Thompson 59*b11824b3SJeremy L Thompson CEED_INTERN int CeedHipGetResourceRoot(Ceed ceed, const char *resource, 60*b11824b3SJeremy L Thompson char **resource_root); 61*b11824b3SJeremy L Thompson 62f87d896cSJeremy L Thompson CEED_INTERN int CeedHipInit(Ceed ceed, const char *resource); 637fcac036SJeremy L Thompson 647fcac036SJeremy L Thompson CEED_INTERN int CeedDestroy_Hip(Ceed ceed); 657fcac036SJeremy L Thompson 667fcac036SJeremy L Thompson #endif // _ceed_hip_common_h 67