Skip to content
This repository was archived by the owner on Apr 28, 2023. It is now read-only.

Commit 6d2f56b

Browse files
nicolasvasilacheftynse
authored andcommitted
Cleanup SIGINT handling to terminate tuning
At the moment, sending a SIGINT (Ctrl + C) is utterly useless: 1. it can take a long time to finish a tuning iteration 2. SIGINT results in 2 successive thread join calls which always crash the program This PR fixes these broken behaviors by shortcircuiting those compilations and evaluations that have not yet started at the time SIGINT was sent. We still need to flush the pipe so when multiple threads are compiling, we need to wait for the last one to finish. Tested and works from both python and C++
1 parent a9057d9 commit 6d2f56b

File tree

1 file changed

+27
-23
lines changed

1 file changed

+27
-23
lines changed

tc/autotuner/autotuner-inl.h

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -89,24 +89,28 @@ void TuningHarness<Backend>::doCompile(SearchStrategy& searchStrategy) {
8989
}
9090
std::unique_ptr<typename Backend::ExecutorType> pExecutor(nullptr);
9191
auto pConf = searchStrategy.population.at(current).get();
92-
auto options = makeOptions<Backend>(baseMapping_, *pConf);
93-
try {
94-
if (FLAGS_debug_tuner) {
95-
std::stringstream ssInfo;
96-
typename Backend::MappingOptionsCppPrinter infoPrinter(ssInfo);
97-
infoPrinter << options;
98-
LOG(INFO) << "[COMPILE] Start compilation @:" << current;
99-
LOG_LINE_BY_LINE(INFO, ssInfo);
92+
if (not stopRequested_) {
93+
auto options = makeOptions<Backend>(baseMapping_, *pConf);
94+
try {
95+
if (FLAGS_debug_tuner) {
96+
std::stringstream ssInfo;
97+
typename Backend::MappingOptionsCppPrinter infoPrinter(ssInfo);
98+
infoPrinter << options;
99+
LOG(INFO) << "[COMPILE] Start compilation @:" << current;
100+
LOG_LINE_BY_LINE(INFO, ssInfo);
101+
}
102+
pExecutor =
103+
tc::compile<Backend>(tcTree_, inputs_.begin()->second, options);
104+
LOG_IF(INFO, FLAGS_debug_tuner) << "[COMPILE] Done compilation";
105+
} catch (const std::exception& e) {
106+
LOG(WARNING) << "[TUNER][COMPILE] failed compilation: " << e.what();
107+
std::stringstream ssWarning;
108+
typename Backend::MappingOptionsCppPrinter warningPrinter(ssWarning);
109+
warningPrinter << options;
110+
LOG_LINE_BY_LINE(WARNING, ssWarning);
111+
pConf->invalid = true;
100112
}
101-
pExecutor =
102-
tc::compile<Backend>(tcTree_, inputs_.begin()->second, options);
103-
LOG_IF(INFO, FLAGS_debug_tuner) << "[COMPILE] Done compilation";
104-
} catch (const std::exception& e) {
105-
LOG(WARNING) << "[TUNER][COMPILE] failed compilation: " << e.what();
106-
std::stringstream ssWarning;
107-
typename Backend::MappingOptionsCppPrinter warningPrinter(ssWarning);
108-
warningPrinter << options;
109-
LOG_LINE_BY_LINE(WARNING, ssWarning);
113+
} else {
110114
pConf->invalid = true;
111115
}
112116

@@ -158,6 +162,11 @@ void TuningHarness<Backend>::doEvaluate(
158162
continue;
159163
}
160164

165+
if (stopRequested_) {
166+
pConf->invalid = true;
167+
continue;
168+
}
169+
161170
auto options = makeOptions<Backend>(baseMapping_, *pConf);
162171
if (FLAGS_debug_tuner) {
163172
// Always log option to INFO so we can correlate to timing offline
@@ -497,8 +506,7 @@ Autotuner<Backend, SearchStrategy>::tune(
497506
} catch (const std::exception& e) {
498507
std::cerr << "Exception during autotuning: " << e.what()
499508
<< "\n dumping cache to "
500-
<< tc::makeOptionsFilename(cacheFileName) << "/"
501-
<< Backend::makeDeviceFilename(cacheFileName) << std::endl;
509+
<< tc::makeOptionsFilename(cacheFileName) << std::endl;
502510
storeTopKInCache<Backend>(optionsCache_, cacheFileName);
503511
tuningHarnessThreadEx = std::current_exception();
504512
}
@@ -507,11 +515,7 @@ Autotuner<Backend, SearchStrategy>::tune(
507515
while (not tuningHarnessFinished) {
508516
std::this_thread::sleep_for(std::chrono::milliseconds(100));
509517
if (sigint_) {
510-
std::cerr
511-
<< "Autotuning will stop after the current iteration has finished."
512-
<< std::endl;
513518
tuningHarness.stopAfterCurrentIteration();
514-
tuningHarnessThread.join();
515519
storeTopKInCache<Backend>(optionsCache_, cacheFileName);
516520
}
517521
if (sigterm_) {

0 commit comments

Comments
 (0)