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

Commit f86ba5b

Browse files
Merge pull request #476 from nicolasvasilache/pr/tuner-break
Improve autotuner UX (both C++ and python land)
2 parents f084cfe + 114212b commit f86ba5b

File tree

5 files changed

+71
-55
lines changed

5 files changed

+71
-55
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_) {

tc/autotuner/parameters.cc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -459,9 +459,11 @@ void CudaDimParameters::setRange(
459459
namespace {
460460
template <typename Params, typename View>
461461
void fromMappingOptions(Params& params, const View& options) {
462-
CHECK_LE(options.size(), params.dims.size());
463-
params.numberDims.selectFromValue(options.size());
464-
for (size_t i = 0; i < options.size(); ++i) {
462+
// It is possible mapping options are higher dimensional than problem sizes
463+
// in which case options could be larger
464+
auto min = std::min(options.size(), params.dims.size());
465+
params.numberDims.selectFromValue(min);
466+
for (size_t i = 0; i < min; ++i) {
465467
params.dims[i].selectFromValue(options[i]);
466468
}
467469
}

tc/core/cpu/cpu_mapping_options.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,12 @@ CpuMappingOptions CpuMappingOptions::makeNaiveMappingOptions() {
7878
return makeUnmappedMappingOptions().tile(32, 32, 32).unroll(1);
7979
}
8080

81+
std::ostream& operator<<(
82+
std::ostream& os,
83+
const CpuMappingOptions& cpuOptions) {
84+
OstreamBoolalphaScope scope(os);
85+
tc::CpuMappingOptionsAsCpp cpp(cpuOptions);
86+
os << cpp;
87+
return os;
88+
}
8189
} // namespace tc

tc/core/cpu/cpu_mapping_options.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,7 @@ class CpuMappingOptions {
7979
public:
8080
MappingOptionsView generic;
8181
};
82+
83+
std::ostream& operator<<(std::ostream& os, const CpuMappingOptions& view);
84+
8285
} // namespace tc

tc/core/cuda/cuda_mapping_options.cc

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -47,35 +47,6 @@ std::string CudaDimView::toCommaSeparatedString() const {
4747
return ss.str();
4848
}
4949

50-
std::ostream& operator<<(std::ostream& os, const CudaDimView& view) {
51-
os << "CudaDim(" << view.toCommaSeparatedString() << ") @" << &view.proto;
52-
return os;
53-
}
54-
55-
std::ostream& operator<<(std::ostream& os, const CudaDim& dim) {
56-
os << dim.view;
57-
return os;
58-
}
59-
60-
std::ostream& operator<<(std::ostream& os, const Grid& dim) {
61-
os << dim.view;
62-
return os;
63-
}
64-
65-
std::ostream& operator<<(std::ostream& os, const Block& dim) {
66-
os << dim.view;
67-
return os;
68-
}
69-
70-
std::ostream& operator<<(
71-
std::ostream& os,
72-
const CudaMappingOptions& cudaOptions) {
73-
OstreamBoolalphaScope scope(os);
74-
tc::CudaMappingOptionsAsCpp cpp(cudaOptions);
75-
os << cpp;
76-
return os;
77-
}
78-
7950
// CudaDimView & CudaDim
8051
//
8152
CudaDim::CudaDim(std::vector<uint64_t> il) : ownedProto_(), view(ownedProto_) {
@@ -400,4 +371,32 @@ CudaMappingOptions CudaMappingOptions::makeGroupConvolutionMappingOptions() {
400371
.unroll(1);
401372
}
402373

374+
std::ostream& operator<<(std::ostream& os, const CudaDimView& view) {
375+
os << "CudaDim(" << view.toCommaSeparatedString() << ") @" << &view.proto;
376+
return os;
377+
}
378+
379+
std::ostream& operator<<(std::ostream& os, const CudaDim& dim) {
380+
os << dim.view;
381+
return os;
382+
}
383+
384+
std::ostream& operator<<(std::ostream& os, const Grid& dim) {
385+
os << dim.view;
386+
return os;
387+
}
388+
389+
std::ostream& operator<<(std::ostream& os, const Block& dim) {
390+
os << dim.view;
391+
return os;
392+
}
393+
394+
std::ostream& operator<<(
395+
std::ostream& os,
396+
const CudaMappingOptions& cudaOptions) {
397+
OstreamBoolalphaScope scope(os);
398+
tc::CudaMappingOptionsAsCpp cpp(cudaOptions);
399+
os << cpp;
400+
return os;
401+
}
403402
} // namespace tc

0 commit comments

Comments
 (0)