-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add replace enforce with glog switch for debug #11244
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -113,7 +113,11 @@ 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...)); | ||
#else | ||
LOG(FATAL) << string::Sprintf(args...); | ||
#endif | ||
} | ||
} | ||
|
||
|
@@ -123,17 +127,25 @@ 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...)); | ||
#else | ||
LOG(FATAL) << string::Sprintf(args...); | ||
#endif | ||
} | ||
} | ||
|
||
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...)); | ||
#else | ||
LOG(FATAL) << string::Sprintf(args...); | ||
#endif | ||
} | ||
} | ||
|
||
|
@@ -143,8 +155,12 @@ inline typename std::enable_if<sizeof...(Args) != 0, void>::type throw_on_error( | |
if (stat == CUDNN_STATUS_SUCCESS) { | ||
return; | ||
} else { | ||
#ifndef REPLACE_ENFORCE_GLOG | ||
throw std::runtime_error(platform::dynload::cudnnGetErrorString(stat) + | ||
string::Sprintf(args...)); | ||
#else | ||
LOG(FATAL) << string::Sprintf(args...); | ||
#endif | ||
} | ||
} | ||
|
||
|
@@ -173,7 +189,11 @@ inline typename std::enable_if<sizeof...(Args) != 0, void>::type throw_on_error( | |
} else if (stat == CUBLAS_STATUS_LICENSE_ERROR) { | ||
err = "CUBLAS: license error, "; | ||
} | ||
#ifndef REPLACE_ENFORCE_GLOG | ||
throw std::runtime_error(err + string::Sprintf(args...)); | ||
#else | ||
LOG(FATAL) << err << string::Sprintf(args...); | ||
#endif | ||
} | ||
|
||
#ifndef __APPLE__ | ||
|
@@ -183,8 +203,13 @@ inline typename std::enable_if<sizeof...(Args) != 0, void>::type throw_on_error( | |
if (stat == ncclSuccess) { | ||
return; | ||
} else { | ||
#ifndef REPLACE_ENFORCE_GLOG | ||
throw std::runtime_error(platform::dynload::ncclGetErrorString(stat) + | ||
string::Sprintf(args...)); | ||
#else | ||
LOG(FATAL) << platform::dynload::ncclGetErrorString(stat) | ||
<< string::Sprintf(args...); | ||
#endif | ||
} | ||
} | ||
#endif // __APPLE__ | ||
|
@@ -203,6 +228,7 @@ inline void throw_on_error(T e) { | |
__FILE__, __LINE__); \ | ||
} while (false) | ||
|
||
#ifndef REPLACE_ENFORCE_GLOG | ||
#define PADDLE_ENFORCE(...) \ | ||
do { \ | ||
try { \ | ||
|
@@ -212,6 +238,9 @@ inline void throw_on_error(T e) { | |
__FILE__, __LINE__); \ | ||
} \ | ||
} while (false) | ||
#else | ||
#define PADDLE_ENFORCE(...) ::paddle::platform::throw_on_error(__VA_ARGS__); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这个地方为何去掉了try, catch部分? |
||
#endif | ||
|
||
/* | ||
* Some enforce helpers here, usage: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -84,7 +84,7 @@ void Fprintf(std::ostream& out, const char* fmt, const Args&... args) { | |
} | ||
|
||
template <typename... Args> | ||
std::string Sprintf(const char* fmt, const Args&... args) { | ||
std::string Sprintf(const char* fmt = "", const Args&... args) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 默认参数一般是最后一个吧? |
||
std::ostringstream oss; | ||
Fprintf(oss, fmt, args...); | ||
return oss.str(); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
put into configure.cmake?