Exceptions.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
  2. #pragma once
  3. #include <ATen/miopen/miopen-wrapper.h>
  4. #include <string>
  5. #include <stdexcept>
  6. #include <sstream>
  7. namespace at { namespace native {
  8. class miopen_exception : public std::runtime_error {
  9. public:
  10. miopenStatus_t status;
  11. miopen_exception(miopenStatus_t status, const char* msg)
  12. : std::runtime_error(msg)
  13. , status(status) {}
  14. miopen_exception(miopenStatus_t status, const std::string& msg)
  15. : std::runtime_error(msg)
  16. , status(status) {}
  17. };
  18. inline void MIOPEN_CHECK(miopenStatus_t status)
  19. {
  20. if (status != miopenStatusSuccess) {
  21. if (status == miopenStatusNotImplemented) {
  22. throw miopen_exception(status, std::string(miopenGetErrorString(status)) +
  23. ". This error may appear if you passed in a non-contiguous input.");
  24. }
  25. throw miopen_exception(status, miopenGetErrorString(status));
  26. }
  27. }
  28. inline void HIP_CHECK(hipError_t error)
  29. {
  30. if (error != hipSuccess) {
  31. std::string msg("HIP error: ");
  32. msg += hipGetErrorString(error);
  33. throw std::runtime_error(msg);
  34. }
  35. }
  36. }} // namespace at::native
  37. #else
  38. #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
  39. #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)