File tree Expand file tree Collapse file tree 3 files changed +17
-15
lines changed
torch/csrc/distributed/c10d Expand file tree Collapse file tree 3 files changed +17
-15
lines changed Original file line number Diff line number Diff line change 3
3
#include < ATen/Config.h>
4
4
#include < ATen/PTThreadPool.h>
5
5
#include < ATen/Version.h>
6
+ #include < c10/util/env.h>
6
7
7
8
#include < sstream>
8
9
#include < thread>
@@ -23,17 +24,17 @@ namespace at {
23
24
24
25
namespace {
25
26
26
- const char * get_env_var (
27
+ std::string get_env_var (
27
28
const char * var_name, const char * def_value = nullptr ) {
28
- const char * value = std::getenv (var_name);
29
- return value ? value : def_value;
29
+ auto env = c10::utils::get_env (var_name);
30
+ return env. has_value () ? env. value () : def_value;
30
31
}
31
32
32
33
#ifndef C10_MOBILE
33
34
size_t get_env_num_threads (const char * var_name, size_t def_value = 0 ) {
34
35
try {
35
- if (auto * value = std::getenv (var_name)) {
36
- int nthreads = std::stoi (value);
36
+ if (auto value = c10::utils::get_env (var_name)) {
37
+ int nthreads = std::stoi (value. value () );
37
38
TORCH_CHECK (nthreads > 0 );
38
39
return nthreads;
39
40
}
Original file line number Diff line number Diff line change 11
11
#include < c10/cuda/CUDACachingAllocator.h>
12
12
#include < c10/cuda/CUDAFunctions.h>
13
13
#include < c10/macros/Export.h>
14
+ #include < c10/util/env.h>
14
15
#include < c10/util/irange.h>
15
16
16
17
#ifdef USE_ROCM
@@ -180,17 +181,17 @@ uint32_t _getAlignment(uintptr_t address) {
180
181
#endif
181
182
182
183
static size_t _parseChosenWorkspaceSize () {
183
- const char * val = getenv (" CUBLASLT_WORKSPACE_SIZE" );
184
+ auto<
8000
/span> val = c10::utils::get_env (" CUBLASLT_WORKSPACE_SIZE" );
184
185
#ifdef USE_ROCM
185
- if (!val) {
186
+ if (!val. has_value () ) {
186
187
// accept either env var
187
- val = getenv (" HIPBLASLT_WORKSPACE_SIZE" );
188
+ val = c10::utils::get_env (" HIPBLASLT_WORKSPACE_SIZE" );
188
189
}
189
190
#endif
190
191
size_t workspace_size = 1024 ; /* default size in KiB according to #73328 */
191
- if (val) {
192
+ if (val. has_value () ) {
192
193
try {
193
- workspace_size = std::stoi (val);
194
+ workspace_size = std::stoi (val. value () );
194
195
} catch (std::invalid_argument const & e) {
195
196
TORCH_WARN (" invalid CUBLASLT_WORKSPACE_SIZE," ,
196
197
" using default workspace size of " , workspace_size, " KiB." );
Original file line number Diff line number Diff line change 1
1
#ifdef USE_C10D_UCC
2
2
3
3
#include < ATen/cuda/nvrtc_stub/ATenNVRTC.h>
4
+ #include < c10/util/env.h>
4
5
#include < torch/csrc/distributed/c10d/ProcessGroupUCC.hpp>
5
6
#include < torch/csrc/distributed/c10d/UCCTracing.hpp>
6
7
#include < torch/csrc/distributed/c10d/UCCUtils.hpp>
@@ -157,11 +158,10 @@ void read_config() {
157
158
torch_ucc_config.enable_comms_logger = false ;
158
159
159
160
// read all torch_ucc env. variables and update the map
160
- char * env;
161
- for (auto & torch_ucc_env : torch_ucc_envs_map) {
162
- env = std::getenv (torch_ucc_env.first .c_str ());
163
- if (env) {
164
- torch_ucc_envs_map[torch_ucc_env.first ] = std::string (env);
161
+ for (auto & [env_name, value] : torch_ucc_envs_map) {
162
+ auto env = c10::utils::get_env (env_name.c_str ());
163
+ if (env.has_value ()) {
164
+ value = std::move (env.value ());
165
165
}
166
166
}
167
167
You can’t perform that action at this time.
0 commit comments