Repository: pytorch
Issue: Unify `std::getenv` usages
Labels: triaged,better-engineering

We have a bunch of environment variable-grabbing logic across the codebase that operates in slightly different ways (some check for presence, others for `== "1"`). We should move this all to a single `bool c10::utils::check_env(char* name)` API so these can all be handled the exact same way.

`grep 'std::getenv' -r *`

<details>

```
aten/src/ATen/core/type.cpp:  static const char* c_verbosity = std::getenv("PYTORCH_JIT_TYPE_VERBOSITY");
aten/src/ATen/native/DispatchStub.cpp:  auto envar = std::getenv("ATEN_CPU_CAPABILITY");
aten/src/ATen/ParallelCommon.cpp:  const char* value = std::getenv(var_name);
aten/src/ATen/ParallelCommon.cpp:    if (auto* value = std::getenv(var_name)) {
aten/src/ATen/Context.cpp:    char* workspace_config = std::getenv(cublas_config_var_name);
build/include/c10d/Utils.hpp:  char* stringValue = std::getenv(envVarName);
test/cpp/jit/torch_python_test.cpp:      (std::getenv("SANDCASTLE")) ||
test/cpp/jit/torch_python_test.cpp:      (std::getenv("TW_JOB_USER") &&
test/cpp/jit/torch_python_test.cpp:       std::string(std::getenv("TW_JOB_USER")) == "sandcastle"));
test/cpp/jit/test_lite_interpreter.cpp:  auto s = std::getenv("PYTORCH_TEST_WITH_TSAN");
third_party/fbgemm/src/Utils.cc:  const char* env = std::getenv(isa_env);
third_party/fbgemm/src/Utils.cc:  const char* env = std::getenv(isa_env);
third_party/fbgemm/src/spmmUtils.cc:  const char* include_roberta = std::getenv("INCLUDE_ROBERTA");
third_party/fbgemm/src/spmmUtils.cc:  const char* include_lstm = std::getenv("INCLUDE_LSTM");                                                                                                                                        
third_party/fbgemm/src/spmmUtils.cc:  const char* include_rnnt = std::getenv("INCLUDE_RNNT");
third_party/ideep/include/ideep/lru_cache.hpp:    } (std::getenv("LRU_CACHE_CAPACITY"));
third_party/tbb/src/test/harness.h:        return std::getenv(envname);
third_party/tensorpipe/tensorpipe/common/defs.h:  char* levelStr = std::getenv("TP_VERBOSE_LOGGING");
third_party/tensorpipe/tensorpipe/test/channel/cuda_helpers.h:  char* shouldSkip = std::getenv("TP_SKIP_CHECK_OPEN_CUDA_CTXS");
torch/csrc/distributed/rpc/tensorpipe_agent.cpp:    char* ifnameEnv = std::getenv(kSocketIfnameEnvVar.c_str());
torch/csrc/jit/codegen/cuda/executor.cpp:  const char* debug_env = std::getenv("PYTORCH_CUDA_FUSER_DEBUG");
torch/csrc/jit/codegen/cuda/executor.cpp:  const char* debug_env = std::getenv("PYTORCH_CUDA_FUSER_DEBUG");                                                                                                                          
torch/csrc/jit/codegen/cuda/executor.cpp:  const char* dump_kir_env = std::getenv("PYTORCH_CUDA_FUSER_DUMP_KIR");
torch/csrc/jit/codegen/cuda/executor.cpp:  const char* dump_kir_env = std::getenv("PYTORCH_CUDA_FUSER_DUMP_KIR");
torch/csrc/jit/passes/tensorexpr_fuser.cpp:  static const char* enable_c_str = std::getenv("PYTORCH_TENSOREXPR");
torch/csrc/jit/passes/tensorexpr_fuser.cpp:    const char* option = std::getenv("PYTORCH_TENSOREXPR_DONT_FUSE");
torch/csrc/jit/runtime/graph_executor.cpp:      std::getenv("TORCH_JIT_DISABLE_NEW_EXECUTOR");
torch/csrc/jit/tensorexpr/kernel.cpp:  static const char* enable_c_str = std::getenv("PYTORCH_TENSOREXPR_FALLBACK");
torch/csrc/jit/tensorexpr/kernel.cpp:  static const char* enable_c_str = std::getenv("PYTORCH_TENSOREXPR_FALLBACK");
torch/csrc/jit/tensorexpr/kernel.cpp:      std::getenv("PYTORCH_TENSOREXPR_DONT_USE_LLVM");
torch/csrc/jit/jit_log.cpp:  static const char* c_log_level = std::getenv("PYTORCH_JIT_LOG_LEVEL");
torch/csrc/jit/jit_opt_limit.cpp:  static const char* opt_limit = std::getenv("PYTORCH_JIT_OPT_LIMIT");
torch/csrc/utils/crash_handler.cpp:  char* value = std::getenv(name);
torch/csrc/Exceptions.cpp:  auto envar = std::getenv("TORCH_SHOW_CPP_STACKTRACES");
torch/lib/c10d/test/TestUtils.hpp:  auto s = std::getenv("PYTORCH_TEST_WITH_TSAN");
torch/lib/c10d/test/ProcessGroupNCCLTest.cpp:    auto sizeEnv = std::getenv("WORLD_SIZE");
torch/lib/c10d/test/ProcessGroupNCCLTest.cpp:    auto rankEnv = std::getenv("RANK");
torch/lib/c10d/test/ProcessGroupMPITest.cpp:  if (!std::getenv("OMPI_COMM_WORLD_SIZE")) {
torch/lib/c10d/Utils.cpp:    char* stringValue = std::getenv(env_var_name);
torch/lib/c10d/Utils.hpp:  char* stringValue = std::getenv(envVarName);
torch/lib/c10d/ProcessGroupNCCL.cpp:  const char * ncclDebugLevel = std::getenv("NCCL_DEBUG");
torch/include/c10d/Utils.hpp:  char* stringValue = std::getenv(envVarName);
```

</details>