@@ -1395,40 +1395,40 @@ std::string generate_reduction_code(
1395
1395
// Acquires (possibly creating) the kernel cache directory
1396
1396
std::optional<std::string> get_cache_dir () {
1397
1397
// If the environment variable USE_TORCH_KERNEL_CACHE is set to "0" then no persistent cache is used
1398
- const auto uptkc = c10::utils::get_env (" USE_PYTORCH_KERNEL_CACHE" );
1399
- const bool use_kernel_cache = (uptkc != " 0" );
1398
+ const char * uptkc = std::getenv (" USE_PYTORCH_KERNEL_CACHE" );
1399
+ const bool use_kernel_cache = (uptkc == nullptr ) ? true : std::strcmp (uptkc, " 0" );
1400
1400
1401
1401
if (!use_kernel_cache) {
1402
1402
return {};
1403
1403
}
1404
1404
1405
1405
// Cache path comes from PYTORCH_KERNEL_CACHE_PATH, then TEMP (Windows) or XDG_CACHE_HOME (Linux), then HOME environment variables
1406
1406
std::string cache_dir;
1407
- auto ptkcp = c10::utils::get_env (" PYTORCH_KERNEL_CACHE_PATH" );
1407
+ char * ptkcp = std::getenv (" PYTORCH_KERNEL_CACHE_PATH" );
1408
1408
// Create kernel_cache_dir if needed as we do not want to create the base directory passed by the user
1409
1409
std::string kernels_cache_dir = " " ;
1410
- if (ptkcp. has_value () ) {
1411
- cache_dir = ptkcp. value ( );
1410
+ if (ptkcp != nullptr ) {
1411
+ cache_dir = std::string (ptkcp );
1412
1412
} else {
1413
1413
#ifdef _WIN32
1414
- ptkcp = c10::utils::get_env (" TEMP" );
1414
+ ptkcp = std::getenv (" TEMP" );
1415
1415
#else
1416
1416
// USES XDG_CACHE_HOME if it's set
1417
- ptkcp = c10::utils::get_env (" XDG_CACHE_HOME" );
1417
+ ptkcp = std::getenv (" XDG_CACHE_HOME" );
1418
1418
#endif
1419
- if (ptkcp. has_value () ) {
1419
+ if (ptkcp != nullptr ) {
1420
1420
kernels_cache_dir = " /torch/kernels" ;
1421
- cache_dir = ptkcp. value ( ) + kernels_cache_dir;
1421
+ cache_dir = std::string (ptkcp ) + kernels_cache_dir;
1422
1422
} else {
1423
1423
// Falls back to HOME/.cache
1424
- ptkcp = c10::utils::get_env (" HOME" );
1425
- if (ptkcp. has_value () ) {
1424
+ ptkcp = std::getenv (" HOME" );
1425
+ if (ptkcp == nullptr ) {
1426
1426
TORCH_WARN_ONCE (" No PYTORCH_KERNEL_CACHE_PATH or HOME environment variable set!" ,
1427
1427
" This disables kernel caching." );
1428
1428
return {};
1429
1429
} else {
1430
1430
kernels_cache_dir = " /.cache/torch/kernels" ;
1431
- cache_dir = ptkcp. value ( ) + kernels_cache_dir;
1431
+ cache_dir = std::string (ptkcp ) + kernels_cache_dir;
1432
1432
}
1433
1433
}
1434
1434
}
@@ -1437,7 +1437,7 @@ std::optional<std::string> get_cache_dir() {
1437
1437
const char * p_cache_dir = cache_dir.c_str ();
1438
1438
const bool cache_dir_exists = (access (p_cache_dir, F_OK) == 0 );
1439
1439
if (!cache_dir_exists) {
1440
- std::string s_ptkcp = ptkcp. value ( );
1440
+ std::string s_ptkcp = std::string (ptkcp );
1441
1441
if (!r_mkdir_with_base (s_ptkcp, kernels_cache_dir)) {
1442
1442
TORCH_WARN_ONCE (" Specified kernel cache directory could not be created! This disables kernel caching." ,
1443
1443
" Specified directory is " , cache_dir, " ." ,
0 commit comments