Files
pytorch/torch/csrc/assertions.h
peterjc123 63af898d46 Fix extension test on Windows (#5548)
* Change cpp_extensions.py to make it work on Windows

* Fix linting

* Show python paths

* Debug

* Debug 1

* set PYTHONPATH

* Add ATen into library

* expose essential libs and functions, and copy _C.lib

* Specify dir in header

* Update check_abi for MSVC

* Activate cl environment to compile cpp extensions

* change version string

* Redirect stderr to stdout

* Add monkey patch for windows

* Remove unnecessary self

* Fix various issues

* Append necessary flags

* add /MD flag to cuda

* Install ninja

* Use THP_API instead of THP_CLASS

* Beautify the paths

* Revert "Use THP_API instead of THP_CLASS"

This reverts commit dd7e74c44db48e4c5f85bb8e3c698ff9de71ba2d.

* Use THP_API instead of THP_CLASS(new)
2018-04-02 13:53:25 -04:00

53 lines
1.5 KiB
C++

#pragma once
#include <exception>
#include <string>
#include "THP_export.h"
namespace torch {
struct assert_error final : public std::exception {
const std::string msg;
explicit assert_error(const std::string& msg) : msg(msg) {}
virtual const char* what() const noexcept { return msg.c_str(); }
};
[[noreturn]]
THP_CLASS void barf(const char *fmt, ...);
} // namespace torch
#if defined(__GNUC__) || defined(__ICL) || defined(__clang__)
#define TORCH_EXPECT(x, y) (__builtin_expect((x), (y)))
#else
#define TORCH_EXPECT(x, y) (x)
#endif
#define TORCH_ASSERT(cond) \
if (TORCH_EXPECT(!(cond), 0)) { \
::torch::barf("%s:%u: %s: Assertion `%s` failed.", __FILE__, __LINE__, __func__, #cond); \
}
// The trailing ' ' argument is a hack to deal with the extra comma when ... is empty.
// Another way to solve this is ##__VA_ARGS__ in _TORCH_ASSERTM, but this is a non-portable
// extension we shouldn't use.
#define TORCH_ASSERTM(...) _TORCH_ASSERTM(__VA_ARGS__, " ")
// Note: msg must be a string literal
#define _TORCH_ASSERTM(cond, msg, ...) \
if (TORCH_EXPECT(!(cond), 0)) { \
::torch::barf("%s:%u: %s: Assertion `%s` failed: " msg, __FILE__, __LINE__, __func__, #cond, __VA_ARGS__); \
}
#define TORCH_EXPECTM(...) _TORCH_EXPECTM(__VA_ARGS__, " ")
// Note: msg must be a string literal
#define _TORCH_EXPECTM(cond, msg, ...) \
if (TORCH_EXPECT(!(cond), 0)) { \
::torch::barf("%s:%u: %s: " msg, __FILE__, __LINE__, __func__, __VA_ARGS__); \
}
#define JIT_ASSERT TORCH_ASSERT
#define JIT_ASSERTM TORCH_ASSERTM
#define JIT_EXPECTM TORCH_EXPECTM