Skip to content

Commit 5cfe565

Browse files
committed
make target check more robust
1 parent 18134d6 commit 5cfe565

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

src/meta_schedule/schedule_rule/multi_level_tiling.cc

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,18 @@ void MultiLevelTilingNode::InitializeWithTuneContext(const TuneContext& context)
8787
TVM_PY_LOG(INFO, context->logger) << "'thread_warp_size' is not defined in the target";
8888
}
8989
}
90-
Optional<String> arch_attr = context->target.value()->GetAttr<String>("arch");
91-
if (arch_attr.defined()) {
92-
String arch = arch_attr.value();
93-
// format: sm_xx
94-
// @see src/target/tag.cc
95-
if (arch.size() == 5 && (strncmp(arch.c_str(), "sm_", 3) == 0)) {
96-
// only sm_80 or higher supports async memcopy
97-
if (arch.at(3) >= '8') {
98-
this->stages.insert(this->stages.end(), {4, 5});
90+
if (Optional<String> opt_sm = context->target.value()->GetAttr<String>("arch")) {
91+
std::string sm = opt_sm.value();
92+
if (support::StartsWith(sm, "sm_")) {
93+
sm = sm.substr(3);
94+
try {
95+
// only sm_80 or higher supports async memcopy
96+
if (std::stoi(sm) >= 80) {
97+
this->stages.insert(this->stages.end(), {4, 5});
98+
}
99+
} catch (const std::invalid_argument& e) {
100+
LOG(WARNING) << "ValueError: Unable to parse `target.arch`: " << sm
101+
<< ". Details: " << e.what();
99102
}
100103
}
101104
}

0 commit comments

Comments
 (0)