rocm_common.h 1.61 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
/*!
 *  Copyright (c) 2017 by Contributors
 * \file rocm_common.h
 * \brief Common utilities for ROCM
 */
#ifndef TVM_RUNTIME_ROCM_ROCM_COMMON_H_
#define TVM_RUNTIME_ROCM_ROCM_COMMON_H_

#include <tvm/runtime/packed_func.h>
#include <hip/hip_runtime_api.h>
11
#include <string>
12 13 14 15 16 17 18
#include "../workspace_pool.h"

namespace tvm {
namespace runtime {

#define ROCM_DRIVER_CALL(x)                                             \
  {                                                                     \
19 20
    hipError_t result = x;                                              \
    if (result != hipSuccess && result != hipErrorDeinitialized) {      \
21
      LOG(FATAL)                                                        \
22
          << "ROCM HIP Error: " #x " failed with error: " << hipGetErrorString(result); \
23 24 25
    }                                                                   \
  }

26 27 28 29
#define ROCM_CALL(func)                                               \
  {                                                                   \
    hipError_t e = (func);                                            \
    CHECK(e == hipSuccess)                                            \
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
        << "ROCM HIP: " << hipGetErrorString(e);                      \
  }

/*! \brief Thread local workspace */
class ROCMThreadEntry {
 public:
  /*! \brief The hip stream */
  hipStream_t stream{nullptr};
  /*! \brief thread local pool*/
  WorkspacePool pool;
  /*! \brief constructor */
  ROCMThreadEntry();
  // get the threadlocal workspace
  static ROCMThreadEntry* ThreadLocal();
};
}  // namespace runtime
}  // namespace tvm
#endif  // TVM_RUNTIME_ROCM_ROCM_COMMON_H_