1313#include < ATen/cuda/tunable/Tunable.h>
1414#include < c10/util/Exception.h>
1515#include < c10/util/StringUtil.h>
16- #include < c10/util/env.h>
1716#include < torch/version.h>
1817
1918#ifndef _WIN32
@@ -434,8 +433,8 @@ void TuningContext::EnableTunableOp(bool value) {
434433}
435434
436435bool TuningContext::IsTunableOpEnabled () const {
437- static const auto env = c10::utils::get_env (" PYTORCH_TUNABLEOP_ENABLED" );
438- if (env == " 1" ) {
436+ static const char * env = std::getenv (" PYTORCH_TUNABLEOP_ENABLED" );
437+ if (env != nullptr && strcmp (env, " 1" ) == 0 ) {
439438 return true ;
440439 }
441440 return enable_;
@@ -461,25 +460,25 @@ void TuningContext::EnableRecordUntuned(bool value) {
461460}
462461
463462bool TuningContext::IsTuningEnabled () const {
464- static const auto env = c10::utils::get_env (" PYTORCH_TUNABLEOP_TUNING" );
465- if (env == " 0" ) {
463+ static const char * env = std::getenv (" PYTORCH_TUNABLEOP_TUNING" );
464+ if (env != nullptr && strcmp (env, " 0" ) == 0 ) {
466465 return false ;
467466 }
468467 return tuning_enable_;
469468}
470469
471470bool TuningContext::IsRecordUntunedEnabled () const {
472- static const auto env = c10::utils::get_env (" PYTORCH_TUNABLEOP_RECORD_UNTUNED" );
473- if (env == " 1" ) {
471+ static const char * env = std::getenv (" PYTORCH_TUNABLEOP_RECORD_UNTUNED" );
472+ if (env != nullptr && strcmp (env, " 1" ) == 0 ) {
474473 return true ;
475474 }
476475 return record_untuned_enable_;
477476}
478477
479478std::ofstream& TuningContext::GetUntunedFile (){
480479 if (!untuned_file_.is_open ()) {
481- const auto env = c10::utils::get_env (" PYTORCH_TUNABLEOP_UNTUNED_FILENAME" );
482- std::string filename = (! env. has_value ()) ? " tunableop_untuned.csv" : env. value () ;
480+ const char * env = std::getenv (" PYTORCH_TUNABLEOP_UNTUNED_FILENAME" );
481+ std::string filename = (env == nullptr ) ? " tunableop_untuned.csv" : env;
483482
484483 std::string device = c10::str (int (c10::cuda::current_device ()));
485484 std::size_t found = filename.rfind (' .' );
@@ -516,9 +515,9 @@ void TuningContext::SetMaxTuningDurationMs(int max_duration_ms) {
516515}
517516
518517int TuningContext::GetMaxTuningDurationMs () const {
519- static const auto env = c10::utils::get_env (" PYTORCH_TUNABLEOP_MAX_TUNING_DURATION_MS" );
520- if (env. has_value () ) {
521- int val = stoi (env. value () );
518+ static const char * env = std::getenv (" PYTORCH_TUNABLEOP_MAX_TUNING_DURATION_MS" );
519+ if (env != nullptr ) {
520+ int val = atoi (env);
522521 return val < 0 ? 0 : val;
523522 }
524523 return max_tuning_duration_ms_;
@@ -529,9 +528,9 @@ void TuningContext::SetMaxTuningIterations(int max_iter) {
529528}
530529
531530int TuningContext::GetMaxTuningIterations () const {
532- static const auto env = c10::utils::get_env (" PYTORCH_TUNABLEOP_MAX_TUNING_ITERATIONS" );
533- if (env. has_value () ) {
534- int val = stoi (env. value () );
531+ static const char * env = std::getenv (" PYTORCH_TUNABLEOP_MAX_TUNING_ITERATIONS" );
532+ if (env != nullptr ) {
533+ int val = atoi (env);
535534 return val < 0 ? 0 : val;
536535 }
537536 return max_tuning_iterations_;
@@ -542,9 +541,9 @@ void TuningContext::SetMaxWarmupDurationMs(int max_duration_ms) {
542541}
543542
544543int TuningContext::GetMaxWarmupDurationMs () const {
545- static const auto env = c10::utils::get_env (" PYTORCH_TUNABLEOP_MAX_WARMUP_DURATION_MS" );
546- if (env. has_value () ) {
547- int val = stoi (env. value () );
544+ static const char * env = std::getenv (" PYTORCH_TUNABLEOP_MAX_WARMUP_DURATION_MS" );
545+ if (env != nullptr ) {
546+ int val = atoi (env);
548547 return val < 0 ? 0 : val;
549548 }
550549 return max_warmup_duration_ms_;
@@ -555,9 +554,9 @@ void TuningContext::SetMaxWarmupIterations(int max_iter) {
555554}
556555
557556int TuningContext::GetMaxWarmupIterations () const {
558- static const auto env = c10::utils::get_env (" PYTORCH_TUNABLEOP_MAX_WARMUP_ITERATIONS" );
559- if (env. has_value () ) {
560- int val = stoi (env. value () );
557+ static const char * env = std::getenv (" PYTORCH_TUNABLEOP_MAX_WARMUP_ITERATIONS" );
558+ if (env != nullptr ) {
559+ int val = atoi (env);
561560 return val < 0 ? 0 : val;
562561 }
563562 return max_warmup_iterations_;
@@ -568,8 +567,8 @@ void TuningContext::EnableICacheFlush(bool value) {
568567}
569568
570569bool TuningContext::IsICacheFlushEnabled () const {
571- static const auto env = c10::utils::get_env (" PYTORCH_TUNABLEOP_ICACHE_FLUSH_ENABLED" );
572- if (env == " 0" ) {
570+ static const char * env = std::getenv (" PYTORCH_TUNABLEOP_ICACHE_FLUSH_ENABLED" );
571+ if (env != nullptr && strcmp (env, " 0" ) == 0 ) {
573572 return false ;
574573 }
575574 return icache_flush_;
@@ -580,10 +579,10 @@ void TuningContext::SetRotatingBufferSize(int size) {
580579}
581580
582581int TuningContext::GetRotatingBufferSize () const {
583- static const auto env = c10::utils::get_env (" PYTORCH_TUNABLEOP_ROTATING_BUFFER_SIZE" );
584- if (env. has_value () ) {
582+ static const char * env = std::getenv (" PYTORCH_TUNABLEOP_ROTATING_BUFFER_SIZE" );
583+ if (env != nullptr ) {
585584 constexpr int MB = 1024 * 1024 ;
586- int val = stoi (env. value () );
585+ int val = atoi (env);
587586 return val < 0 ? 0 : val * MB; // env var is specified as MB, returned as bytes
588587 }
589588 else {
@@ -603,8 +602,8 @@ TuningResultsManager& TuningContext::GetTuningResultsManager() {
603602 manager_initialized_ = true ;
604603 if (GetFilename ().empty ()) {
605604 // if SetFilename() was not already called, call it now with the default or env var
606- const auto env = c10::utils::get_env (" PYTORCH_TUNABLEOP_FILENAME" );
607- std::string filename = (! env. has_value ()) ? " tunableop_results.csv" : env. value () ;
605+ const char * env = std::getenv (" PYTORCH_TUNABLEOP_FILENAME" );
606+ std::string filename = (env == nullptr ) ? " tunableop_results.csv" : env;
608607 SetFilename (filename, true );
609608 }
610609 auto filename = GetFilename ();
0 commit comments