Limit the option value of TORCH_SHOW_DISPATCH_TRACE (#136510)

It`s more convenient for user to enable or disable dispatch trace by
setting TORCH_SHOW_DISPATCH_TRACE to 1 or 0, especially debug in IDE.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/136510
Approved by: https://github.com/shink, https://github.com/ezyang
This commit is contained in:
FFFrog
2024-09-24 12:18:35 +08:00
committed by PyTorch MergeBot
parent 28224329ad
commit 6ecb73bafd

View File

@ -17,8 +17,22 @@ TORCH_SDT_DEFINE_SEMAPHORE(operator_end)
#endif
bool show_dispatch_trace() {
static char const* temp = getenv("TORCH_SHOW_DISPATCH_TRACE");
return temp != nullptr;
static auto envar = std::getenv("TORCH_SHOW_DISPATCH_TRACE");
if (envar) {
if (strcmp(envar, "0") == 0) {
return false;
}
if (strcmp(envar, "1") == 0) {
return true;
}
TORCH_WARN(
"ignoring invalid value for TORCH_SHOW_DISPATCH_TRACE: ",
envar,
" valid values are 0 or 1.");
}
return false;
}
static thread_local int64_t dispatch_trace_nesting_value_;