xref: /libCEED/rust/libceed-sys/c-src/backends/hip/ceed-hip-common.h (revision 7fcac03628df7c326a56de618266f195cb34c506)
1*7fcac036SJeremy L Thompson // Copyright (c) 2017-2018, Lawrence Livermore National Security, LLC.
2*7fcac036SJeremy L Thompson // Produced at the Lawrence Livermore National Laboratory. LLNL-CODE-734707.
3*7fcac036SJeremy L Thompson // All Rights reserved. See files LICENSE and NOTICE for details.
4*7fcac036SJeremy L Thompson //
5*7fcac036SJeremy L Thompson // This file is part of CEED, a collection of benchmarks, miniapps, software
6*7fcac036SJeremy L Thompson // libraries and APIs for efficient high-order finite element and spectral
7*7fcac036SJeremy L Thompson // element discretizations for exascale applications. For more information and
8*7fcac036SJeremy L Thompson // source code availability see http://github.com/ceed.
9*7fcac036SJeremy L Thompson //
10*7fcac036SJeremy L Thompson // The CEED research is supported by the Exascale Computing Project 17-SC-20-SC,
11*7fcac036SJeremy L Thompson // a collaborative effort of two U.S. Department of Energy organizations (Office
12*7fcac036SJeremy L Thompson // of Science and the National Nuclear Security Administration) responsible for
13*7fcac036SJeremy L Thompson // the planning and preparation of a capable exascale ecosystem, including
14*7fcac036SJeremy L Thompson // software, applications, hardware, advanced system engineering and early
15*7fcac036SJeremy L Thompson // testbed platforms, in support of the nation's exascale computing imperative.
16*7fcac036SJeremy L Thompson 
17*7fcac036SJeremy L Thompson #ifndef _ceed_common_hip_h
18*7fcac036SJeremy L Thompson #define _ceed_common_hip_h
19*7fcac036SJeremy L Thompson 
20*7fcac036SJeremy L Thompson #include <ceed/ceed.h>
21*7fcac036SJeremy L Thompson #include <ceed/backend.h>
22*7fcac036SJeremy L Thompson #include <hip/hip_runtime.h>
23*7fcac036SJeremy L Thompson #include <hipblas.h>
24*7fcac036SJeremy L Thompson 
25*7fcac036SJeremy L Thompson #define HIP_MAX_PATH 256
26*7fcac036SJeremy L Thompson 
27*7fcac036SJeremy L Thompson #define QUOTE(...) #__VA_ARGS__
28*7fcac036SJeremy L Thompson 
29*7fcac036SJeremy L Thompson #define CeedChk_Hip(ceed, x) \
30*7fcac036SJeremy L Thompson do { \
31*7fcac036SJeremy L Thompson   hipError_t hip_result = x; \
32*7fcac036SJeremy L Thompson   if (hip_result != hipSuccess) { \
33*7fcac036SJeremy L Thompson     const char *msg = hipGetErrorName(hip_result); \
34*7fcac036SJeremy L Thompson     return CeedError((ceed), CEED_ERROR_BACKEND, msg); \
35*7fcac036SJeremy L Thompson   } \
36*7fcac036SJeremy L Thompson } while (0)
37*7fcac036SJeremy L Thompson 
38*7fcac036SJeremy L Thompson #define CeedChk_Hipblas(ceed, x) \
39*7fcac036SJeremy L Thompson do { \
40*7fcac036SJeremy L Thompson   hipblasStatus_t hipblas_result = x; \
41*7fcac036SJeremy L Thompson   if (hipblas_result != HIPBLAS_STATUS_SUCCESS) { \
42*7fcac036SJeremy L Thompson     const char *msg = hipblasGetErrorName(hipblas_result); \
43*7fcac036SJeremy L Thompson     return CeedError((ceed), CEED_ERROR_BACKEND, msg); \
44*7fcac036SJeremy L Thompson    } \
45*7fcac036SJeremy L Thompson } while (0)
46*7fcac036SJeremy L Thompson 
47*7fcac036SJeremy L Thompson #define CASE(name) case name: return #name
48*7fcac036SJeremy L Thompson // LCOV_EXCL_START
49*7fcac036SJeremy L Thompson CEED_UNUSED static const char *hipblasGetErrorName(hipblasStatus_t error) {
50*7fcac036SJeremy L Thompson   switch (error) {
51*7fcac036SJeremy L Thompson     CASE(HIPBLAS_STATUS_SUCCESS);
52*7fcac036SJeremy L Thompson     CASE(HIPBLAS_STATUS_NOT_INITIALIZED);
53*7fcac036SJeremy L Thompson     CASE(HIPBLAS_STATUS_ALLOC_FAILED);
54*7fcac036SJeremy L Thompson     CASE(HIPBLAS_STATUS_INVALID_VALUE);
55*7fcac036SJeremy L Thompson     CASE(HIPBLAS_STATUS_ARCH_MISMATCH);
56*7fcac036SJeremy L Thompson     CASE(HIPBLAS_STATUS_MAPPING_ERROR);
57*7fcac036SJeremy L Thompson     CASE(HIPBLAS_STATUS_EXECUTION_FAILED);
58*7fcac036SJeremy L Thompson     CASE(HIPBLAS_STATUS_INTERNAL_ERROR);
59*7fcac036SJeremy L Thompson   default: return "HIPBLAS_STATUS_UNKNOWN_ERROR";
60*7fcac036SJeremy L Thompson   }
61*7fcac036SJeremy L Thompson }
62*7fcac036SJeremy L Thompson // LCOV_EXCL_STOP
63*7fcac036SJeremy L Thompson 
64*7fcac036SJeremy L Thompson typedef struct {
65*7fcac036SJeremy L Thompson   int optblocksize;
66*7fcac036SJeremy L Thompson   int deviceId;
67*7fcac036SJeremy L Thompson   hipblasHandle_t hipblasHandle;
68*7fcac036SJeremy L Thompson } Ceed_Hip;
69*7fcac036SJeremy L Thompson 
70*7fcac036SJeremy L Thompson CEED_INTERN int CeedHipInit(Ceed ceed, const char *resource, int nrc);
71*7fcac036SJeremy L Thompson 
72*7fcac036SJeremy L Thompson CEED_INTERN int CeedDestroy_Hip(Ceed ceed);
73*7fcac036SJeremy L Thompson 
74*7fcac036SJeremy L Thompson #endif // _ceed_hip_common_h
75