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

Commit b29ed63

Browse files
nicolasvasilacheftynse
authored andcommitted
Turn error into an exception
This allows autotuning to proceed without crashing. I did not yet had the chance to capture the problem in a new unit test.
1 parent bc83925 commit b29ed63

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

tc/core/polyhedral/cuda/codegen.cc

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "tc/core/polyhedral/codegen.h"
2727
#include "tc/core/polyhedral/cuda/codegen.h"
2828
#include "tc/core/polyhedral/cuda/mapping_types.h"
29+
#include "tc/core/polyhedral/exceptions.h"
2930
#include "tc/core/polyhedral/memory_promotion.h"
3031
#include "tc/core/polyhedral/schedule_isl_conversion.h"
3132
#include "tc/core/polyhedral/schedule_transforms.h"
@@ -357,7 +358,14 @@ void emitReductionInit(
357358
auto call = provide->values[0].as<Halide::Internal::Call>();
358359
CHECK(call && call->is_intrinsic(tc2halide::kReductionUpdate));
359360
auto assoc = prove_associativity(provide->name, provide->args, call->args);
360-
CHECK(assoc.associative());
361+
if (!assoc.associative()) {
362+
std::stringstream ss;
363+
ss << "Not associative: " << provide->name << ", provide: ";
364+
Halide::Internal::IRPrinter p(ss);
365+
p.print(Halide::Internal::Stmt(provide));
366+
ss << "\nGenerated so far:\n" << context.ss.str();
367+
throw codegen::NotAssociativeError(ss.str());
368+
}
361369
auto statementContext = CodegenStatementContext(context, stmtId);
362370
CHECK_EQ(assoc.pattern.identities.size(), 1u);
363371
detail::emitHalideExpr(assoc.pattern.identities[0], statementContext);

tc/core/polyhedral/exceptions.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,11 @@ struct GroupingError : public std::logic_error {
6464
};
6565
} // namespace promotion
6666

67+
namespace codegen {
68+
69+
struct NotAssociativeError : public std::logic_error {
70+
explicit NotAssociativeError(const std::string& s) : std::logic_error(s) {}
71+
};
72+
} // namespace codegen
6773
} // namespace polyhedral
6874
} // namespace tc

0 commit comments

Comments
 (0)