|
|
|
@ -140,68 +140,72 @@ struct EOFException : public std::exception {
|
|
|
|
|
#define LIKELY(condition) (condition)
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
inline bool is_error(bool stat) { return !stat; }
|
|
|
|
|
|
|
|
|
|
template <typename... Args>
|
|
|
|
|
inline typename std::enable_if<sizeof...(Args) != 0, void>::type throw_on_error(
|
|
|
|
|
bool stat, const Args&... args) {
|
|
|
|
|
if (UNLIKELY(!(stat))) {
|
|
|
|
|
#ifndef REPLACE_ENFORCE_GLOG
|
|
|
|
|
throw std::runtime_error(string::Sprintf(args...));
|
|
|
|
|
throw std::runtime_error(string::Sprintf(args...));
|
|
|
|
|
#else
|
|
|
|
|
LOG(FATAL) << string::Sprintf(args...);
|
|
|
|
|
LOG(FATAL) << string::Sprintf(args...);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#ifdef PADDLE_WITH_CUDA
|
|
|
|
|
|
|
|
|
|
inline bool is_error(cudaError_t e) { return UNLIKELY(e); }
|
|
|
|
|
|
|
|
|
|
template <typename... Args>
|
|
|
|
|
inline typename std::enable_if<sizeof...(Args) != 0, void>::type throw_on_error(
|
|
|
|
|
cudaError_t e, const Args&... args) {
|
|
|
|
|
if (UNLIKELY(e)) {
|
|
|
|
|
#ifndef REPLACE_ENFORCE_GLOG
|
|
|
|
|
throw thrust::system_error(e, thrust::cuda_category(),
|
|
|
|
|
string::Sprintf(args...));
|
|
|
|
|
throw thrust::system_error(e, thrust::cuda_category(),
|
|
|
|
|
string::Sprintf(args...));
|
|
|
|
|
#else
|
|
|
|
|
LOG(FATAL) << string::Sprintf(args...);
|
|
|
|
|
LOG(FATAL) << string::Sprintf(args...);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline bool is_error(curandStatus_t stat) {
|
|
|
|
|
return stat != CURAND_STATUS_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <typename... Args>
|
|
|
|
|
inline typename std::enable_if<sizeof...(Args) != 0, void>::type throw_on_error(
|
|
|
|
|
curandStatus_t stat, const Args&... args) {
|
|
|
|
|
if (stat != CURAND_STATUS_SUCCESS) {
|
|
|
|
|
#ifndef REPLACE_ENFORCE_GLOG
|
|
|
|
|
throw thrust::system_error(cudaErrorLaunchFailure, thrust::cuda_category(),
|
|
|
|
|
string::Sprintf(args...));
|
|
|
|
|
throw thrust::system_error(cudaErrorLaunchFailure, thrust::cuda_category(),
|
|
|
|
|
string::Sprintf(args...));
|
|
|
|
|
#else
|
|
|
|
|
LOG(FATAL) << string::Sprintf(args...);
|
|
|
|
|
LOG(FATAL) << string::Sprintf(args...);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline bool is_error(cudnnStatus_t stat) {
|
|
|
|
|
return stat != CUDNN_STATUS_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <typename... Args>
|
|
|
|
|
inline typename std::enable_if<sizeof...(Args) != 0, void>::type throw_on_error(
|
|
|
|
|
cudnnStatus_t stat, const Args&... args) {
|
|
|
|
|
if (stat == CUDNN_STATUS_SUCCESS) {
|
|
|
|
|
return;
|
|
|
|
|
} else {
|
|
|
|
|
#ifndef REPLACE_ENFORCE_GLOG
|
|
|
|
|
throw std::runtime_error(platform::dynload::cudnnGetErrorString(stat) +
|
|
|
|
|
string::Sprintf(args...));
|
|
|
|
|
throw std::runtime_error(platform::dynload::cudnnGetErrorString(stat) +
|
|
|
|
|
string::Sprintf(args...));
|
|
|
|
|
#else
|
|
|
|
|
LOG(FATAL) << string::Sprintf(args...);
|
|
|
|
|
LOG(FATAL) << string::Sprintf(args...);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline bool is_error(cublasStatus_t stat) {
|
|
|
|
|
return stat != CUBLAS_STATUS_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <typename... Args>
|
|
|
|
|
inline typename std::enable_if<sizeof...(Args) != 0, void>::type throw_on_error(
|
|
|
|
|
cublasStatus_t stat, const Args&... args) {
|
|
|
|
|
std::string err;
|
|
|
|
|
if (stat == CUBLAS_STATUS_SUCCESS) {
|
|
|
|
|
return;
|
|
|
|
|
} else if (stat == CUBLAS_STATUS_NOT_INITIALIZED) {
|
|
|
|
|
if (stat == CUBLAS_STATUS_NOT_INITIALIZED) {
|
|
|
|
|
err = "CUBLAS: not initialized, ";
|
|
|
|
|
} else if (stat == CUBLAS_STATUS_ALLOC_FAILED) {
|
|
|
|
|
err = "CUBLAS: alloc failed, ";
|
|
|
|
@ -254,21 +258,49 @@ inline void throw_on_error(T e) {
|
|
|
|
|
#define PADDLE_THROW(...) \
|
|
|
|
|
throw ::paddle::platform::EnforceNotMet(__FILE__, __LINE__, __VA_ARGS__)
|
|
|
|
|
|
|
|
|
|
#define __PADDLE_THROW_ERROR_I(_, _9, _8, _7, _6, _5, _4, _3, _2, X_, ...) X_;
|
|
|
|
|
|
|
|
|
|
#define __THROW_ON_ERROR_ONE_ARG(COND, ARG) \
|
|
|
|
|
::paddle::platform::throw_on_error(COND, ::paddle::string::Sprintf(ARG));
|
|
|
|
|
|
|
|
|
|
#define __PADDLE_THROW_ON_ERROR(COND, ...) \
|
|
|
|
|
__PADDLE_THROW_ERROR_I( \
|
|
|
|
|
__VA_ARGS__, ::paddle::platform::throw_on_error(COND, __VA_ARGS__), \
|
|
|
|
|
::paddle::platform::throw_on_error(COND, __VA_ARGS__), \
|
|
|
|
|
::paddle::platform::throw_on_error(COND, __VA_ARGS__), \
|
|
|
|
|
::paddle::platform::throw_on_error(COND, __VA_ARGS__), \
|
|
|
|
|
::paddle::platform::throw_on_error(COND, __VA_ARGS__), \
|
|
|
|
|
::paddle::platform::throw_on_error(COND, __VA_ARGS__), \
|
|
|
|
|
::paddle::platform::throw_on_error(COND, __VA_ARGS__), \
|
|
|
|
|
::paddle::platform::throw_on_error(COND, __VA_ARGS__), \
|
|
|
|
|
__THROW_ON_ERROR_ONE_ARG(COND, __VA_ARGS__))
|
|
|
|
|
|
|
|
|
|
#define __PADDLE_UNARY_COMPARE(COND, ...) \
|
|
|
|
|
do { \
|
|
|
|
|
auto __cond = COND; \
|
|
|
|
|
if (UNLIKELY(::paddle::platform::is_error(__cond))) { \
|
|
|
|
|
__PADDLE_THROW_ON_ERROR(__cond, __VA_ARGS__); \
|
|
|
|
|
} \
|
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
|
|
#ifndef REPLACE_ENFORCE_GLOG
|
|
|
|
|
#define PADDLE_ENFORCE(...) \
|
|
|
|
|
#define __PADDLE_ENFORCE_I(COND, ...) \
|
|
|
|
|
do { \
|
|
|
|
|
try { \
|
|
|
|
|
::paddle::platform::throw_on_error(__VA_ARGS__); \
|
|
|
|
|
__PADDLE_UNARY_COMPARE(COND, __VA_ARGS__); \
|
|
|
|
|
} catch (...) { \
|
|
|
|
|
throw ::paddle::platform::EnforceNotMet(std::current_exception(), \
|
|
|
|
|
__FILE__, __LINE__); \
|
|
|
|
|
} \
|
|
|
|
|
} while (false)
|
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
#define PADDLE_ENFORCE(...) ::paddle::platform::throw_on_error(__VA_ARGS__);
|
|
|
|
|
#define __PADDLE_ENFORCE_I(COND, ...) __PADDLE_UNARY_COMPARE(COND, __VA_ARGS__);
|
|
|
|
|
#endif // REPLACE_ENFORCE_GLOG
|
|
|
|
|
|
|
|
|
|
#define __PADDLE_ENFORCE(__args) __PADDLE_ENFORCE_I __args
|
|
|
|
|
#define PADDLE_ENFORCE(...) __PADDLE_ENFORCE((__VA_ARGS__))
|
|
|
|
|
|
|
|
|
|
#define PADDLE_THROW_EOF() \
|
|
|
|
|
do { \
|
|
|
|
|
throw ::paddle::platform::EOFException("There is no next data.", __FILE__, \
|
|
|
|
|