@@ -1395,40 +1395,40 @@ std::string generate_reduction_code(
13951395// Acquires (possibly creating) the kernel cache directory
13961396std::optional<std::string> get_cache_dir () {
13971397 // 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" );
14001400
14011401 if (!use_kernel_cache) {
14021402 return {};
14031403 }
14041404
14051405 // Cache path comes from PYTORCH_KERNEL_CACHE_PATH, then TEMP (Windows) or XDG_CACHE_HOME (Linux), then HOME environment variables
14061406 std::string cache_dir;
1407- auto ptkcp = c10::utils::get_env (" PYTORCH_KERNEL_CACHE_PATH" );
1407+ char * ptkcp = std::getenv (" PYTORCH_KERNEL_CACHE_PATH" );
14081408 // Create kernel_cache_dir if needed as we do not want to create the base directory passed by the user
14091409 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 );
14121412 } else {
14131413#ifdef _WIN32
1414- ptkcp = c10::utils::get_env (" TEMP" );
1414+ ptkcp = std::getenv (" TEMP" );
14151415#else
14161416 // USES XDG_CACHE_HOME if it's set
1417- ptkcp = c10::utils::get_env (" XDG_CACHE_HOME" );
1417+ ptkcp = std::getenv (" XDG_CACHE_HOME" );
14181418#endif
1419- if (ptkcp. has_value () ) {
1419+ if (ptkcp != nullptr ) {
14201420 kernels_cache_dir = " /torch/kernels" ;
1421- cache_dir = ptkcp. value ( ) + kernels_cache_dir;
1421+ cache_dir = std::string (ptkcp ) + kernels_cache_dir;
14221422 } else {
14231423 // 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 ) {
14261426 TORCH_WARN_ONCE (" No PYTORCH_KERNEL_CACHE_PATH or HOME environment variable set!" ,
14271427 " This disables kernel caching." );
14281428 return {};
14291429 } else {
14301430 kernels_cache_dir = " /.cache/torch/kernels" ;
1431- cache_dir = ptkcp. value ( ) + kernels_cache_dir;
1431+ cache_dir = std::string (ptkcp ) + kernels_cache_dir;
14321432 }
14331433 }
14341434 }
@@ -1437,7 +1437,7 @@ std::optional<std::string> get_cache_dir() {
14371437 const char * p_cache_dir = cache_dir.c_str ();
14381438 const bool cache_dir_exists = (access (p_cache_dir, F_OK) == 0 );
14391439 if (!cache_dir_exists) {
1440- std::string s_ptkcp = ptkcp. value ( );
1440+ std::string s_ptkcp = std::string (ptkcp );
14411441 if (!r_mkdir_with_base (s_ptkcp, kernels_cache_dir)) {
14421442 TORCH_WARN_ONCE (" Specified kernel cache directory could not be created! This disables kernel caching." ,
14431443 " Specified directory is " , cache_dir, " ." ,
0 commit comments