Exceptions.h 1.1 KB

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