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

Commit 4b252e5

Browse files
author
Sven Verdoolaege
committed
emitCudaKernel: avoid relying on isl set variable names in domain of schedule
In particular, call Scop::makeIslAffFromStmtExpr, which takes care of the mapping between set dimensions and their names, instead of assuming that the variable names of the domain of the schedule were preserved through the entire AST generation process. This only handles half of the reliance on the preservation of isl set variable names in the scheduler. The other half will be handled by the next commit.
1 parent 956495e commit 4b252e5

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

include/tc/core/polyhedral/cuda/codegen.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <string>
2020
#include <unordered_map>
2121

22+
#include "tc/core/halide2isl.h"
2223
#include "tc/core/polyhedral/cuda/mapped_scop.h"
2324
#include "tc/core/polyhedral/scop.h"
2425
#include "tc/external/isl.h"
@@ -103,6 +104,16 @@ struct CodegenStatementContext : CodegenContext {
103104
}
104105
return result;
105106
}
107+
// Make an affine function from a Halide Expr that is defined
108+
// over the instance set of the statement corresponding to
109+
// the AST node of this CodegenStatementContext. Return a
110+
// null isl::aff if the expression is not affine. Fail if any
111+
// of the variables does not correspond to a parameter or
112+
// an instance identifier of the statement.
113+
isl::aff makeIslAffFromExpr(const Halide::Expr& e) const {
114+
auto space = iteratorMap().get_space().params();
115+
return scop().makeIslAffFromStmtExpr(statementId(), space, e);
116+
}
106117

107118
isl::id astNodeId;
108119
};

src/core/polyhedral/cuda/codegen.cc

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#include <utility>
2222

2323
#include "tc/core/flags.h"
24-
#include "tc/core/halide2isl.h"
2524
#include "tc/core/islpp_wrap.h"
2625
#include "tc/core/libraries.h"
2726
#include "tc/core/polyhedral/codegen.h"
@@ -458,11 +457,10 @@ namespace detail {
458457
isl::pw_aff makeAffFromMappedExpr(
459458
const Halide::Expr& expr,
460459
const CodegenStatementContext& context) {
461-
auto space = context.iteratorMap().get_space().range();
462460
// We only expect this to be called on encountering a free
463461
// variable. Compound expressions should be emitted as Halide.
464462
CHECK(expr.as<Halide::Internal::Variable>());
465-
auto aff = halide2isl::makeIslAffFromExpr(space, expr);
463+
auto aff = context.makeIslAffFromExpr(expr);
466464
auto pwaff = isl::pw_aff(aff).pullback(context.iteratorMap());
467465
return pwaff;
468466
}
@@ -492,8 +490,7 @@ isl::multi_aff makeMultiAffAccess(
492490

493491
auto ma = isl::multi_aff::zero(space);
494492
for (size_t i = 0; i < subscripts.size(); ++i) {
495-
ma = ma.set_aff(
496-
i, halide2isl::makeIslAffFromExpr(domainSpace, subscripts[i]));
493+
ma = ma.set_aff(i, context.makeIslAffFromExpr(subscripts[i]));
497494
}
498495
return ma;
499496
}

0 commit comments

Comments
 (0)