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

Commit 1b390a9

Browse files
author
Sven Verdoolaege
committed
Scop: generate context on the fly
Now that the fixed parameter values are stored in the Scop, the context can be generated from these values and the set of all parameter when needed.
1 parent 0eb6dd2 commit 1b390a9

File tree

6 files changed

+25
-33
lines changed

6 files changed

+25
-33
lines changed

tc/core/polyhedral/codegen_llvm.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -324,8 +324,7 @@ llvm::Value* CodeGen_TC::getValue(isl::ast_expr expr) {
324324

325325
class LLVMCodegen {
326326
void collectTensor(const Halide::OutputImageParam& t) {
327-
auto sizes =
328-
getTensorSizesWithoutLeadingDim(t, scop_.globalParameterContext);
327+
auto sizes = getTensorSizesWithoutLeadingDim(t, scop_.context());
329328
if (not sizes.empty()) {
330329
args_.emplace_back(
331330
makePtrToArrayType(halide_cg.llvm_type_of(t.type()), sizes));
@@ -509,7 +508,7 @@ class LLVMCodegen {
509508
CHECK(condLHS);
510509
CHECK_EQ(condLHS.get_id(), iterator);
511510

512-
IslAstExprInterpeter i(scop_.globalParameterContext);
511+
IslAstExprInterpeter i(scop_.context());
513512
auto condRHSVal = i.interpret(cond_expr.get_arg(1));
514513

515514
auto cond = [&]() {

tc/core/polyhedral/cuda/mapped_scop.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -855,7 +855,7 @@ std::unique_ptr<MappedScop> makeSpecializedMappedScop(
855855
// outer schedule dimensions, so the space of a parameter context code is that
856856
// of a zero-dimensional space.
857857
auto root = scop->scheduleRoot();
858-
updateTopLevelContext(root, scop->globalParameterContext.from_params());
858+
updateTopLevelContext(root, scop->context().from_params());
859859

860860
tc::Grid grid = mappedScop.numBlocks;
861861
tc::Block block = mappedScop.numThreads;
@@ -878,7 +878,7 @@ std::unique_ptr<MappedScop> makeSpecializedMappedScop(
878878
} // namespace
879879

880880
// Before generating code, make a copy of the scop and insert
881-
// the globalParameterContext of the original scop as top-level
881+
// the context of the original scop as top-level
882882
// context node in schedule tree.
883883
std::tuple<std::string, tc::Grid, tc::Block> MappedScop::codegen(
884884
const std::string& specializedName) const {

tc/core/polyhedral/cuda/tighten_launch_bounds.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ std::pair<tc::Grid, tc::Block> tightenLaunchBounds(
8484
const tc::Grid& grid,
8585
const tc::Block& block) {
8686
auto root = scop.scheduleRoot();
87-
auto params = scop.globalParameterContext;
87+
auto params = scop.context();
8888

8989
auto max = [root, params](const mapping::MappingId& id) -> size_t {
9090
size_t sizetMax = std::numeric_limits<size_t>::max();

tc/core/polyhedral/memory_promotion.cc

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -421,10 +421,7 @@ isl::set tensorElementsSet(const Scop& scop, isl::id tensorId) {
421421
(isl::aff_set(aff) < (minAff + extentAff));
422422
}
423423

424-
if (scop.globalParameterContext) {
425-
tensorElements =
426-
tensorElements.intersect_params(scop.globalParameterContext);
427-
}
424+
tensorElements = tensorElements.intersect_params(scop.context());
428425
return tensorElements;
429426
}
430427

tc/core/polyhedral/scop.cc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,9 @@ ScopUPtr Scop::makeScop(
4747

4848
halide2isl::SymbolTable sym = halide2isl::makeSymbolTable(components);
4949

50-
auto globalParameterContext = halide2isl::makeParamContext(ctx, sym.params);
51-
isl::space paramSpace = globalParameterContext.get_space();
50+
isl::space paramSpace = halide2isl::makeParamSpace(ctx, sym.params);
5251

5352
ScopUPtr scop(new Scop());
54-
scop->globalParameterContext = globalParameterContext;
5553
scop->halide.params = sym.params;
5654
scop->halide.idx = sym.idxVars;
5755
scop->halide.reductionIdx = sym.reductionVars;

tc/core/polyhedral/scop.h

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ struct Scop {
6464
static std::unique_ptr<Scop> makeScop(const Scop& scop) {
6565
auto res = std::unique_ptr<Scop>(new Scop());
6666
res->parameterValues = scop.parameterValues;
67-
res->globalParameterContext = scop.globalParameterContext;
6867
res->halide = scop.halide;
6968
res->reads = scop.reads;
7069
res->writes = scop.writes;
@@ -79,10 +78,20 @@ struct Scop {
7978
return res;
8079
}
8180

82-
// Intersect globalParameterContext with extraGlobalParameterContext.
83-
inline void intersectContext(isl::set extraGlobalParameterContext) {
84-
auto context = globalParameterContext & extraGlobalParameterContext;
85-
globalParameterContext = context;
81+
// Return a context encapsulating all known information about
82+
// the parameters. In particular, all parameters are known
83+
// to be non-negative and the parameters fixed by fixParameters
84+
// have a known value.
85+
// This context lives in a parameter space.
86+
// The scop is not necessarily specialized to its context.
87+
// Call specializeToContext to perform this specialization.
88+
// The schedule tree of the scop does not necessarily have
89+
// a context node. Call updateTopLevelContext on the schedule tree
90+
// to introduce or refine such a context node.
91+
isl::set context() const {
92+
auto ctx = domain().get_ctx();
93+
auto context = halide2isl::makeParamContext(ctx, halide.params);
94+
return context.intersect(makeContext(parameterValues));
8695
}
8796

8897
// Specialize a Scop by fixing the given parameters to the given sizes.
@@ -108,8 +117,9 @@ struct Scop {
108117
return res;
109118
}
110119

111-
// Specialize the Scop with respect to its globalParameterContext.
120+
// Specialize the Scop with respect to its context.
112121
void specializeToContext() {
122+
auto globalParameterContext = context();
113123
domainRef() = domain().intersect_params(globalParameterContext);
114124
reads = reads.intersect_params(globalParameterContext);
115125
writes = writes.intersect_params(globalParameterContext);
@@ -135,15 +145,14 @@ struct Scop {
135145
}
136146

137147
// Fix the values of the specified parameters in the context
138-
// to the corresponding specified values and keep track of them
148+
// to the corresponding specified values by keeping track of them
139149
// in parameterValues.
140150
template <typename T>
141151
void fixParameters(const std::unordered_map<std::string, T>& sizes) {
142152
CHECK(parameterValues.size() == 0);
143153
for (const auto& kvp : sizes) {
144154
parameterValues.emplace(kvp.first, kvp.second);
145155
}
146-
intersectContext(makeContext(sizes));
147156
}
148157

149158
// Return the list of parameter values in the same
@@ -491,22 +500,11 @@ struct Scop {
491500
// of the ScheduleTree "function".
492501
private:
493502
isl::union_set& domainRef();
503+
494504
public:
495505
const isl::union_set domain() const;
496506
// The parameter values of a specialized Scop.
497507
std::unordered_map<std::string, int> parameterValues;
498-
// A globalParameterContext is kept. This represents (partial)
499-
// parameter specialization coming from the outside.
500-
// This may be further specialized before codegen.
501-
// This globalParameterContext must not give rise to a context node in the
502-
// schedule tree.
503-
// This globalParameterContext is intersected with the domain of the
504-
// ScheduleTree for best possible specialization of polyhedral decisions and
505-
// transformations. By the analogy with generalized functions, the
506-
// globalParameterContext becomes part of the "support" of the ScheduleTree
507-
// "function".
508-
// This globalParameterContext lives in a parameter space.
509-
isl::set globalParameterContext; // TODO: not too happy about this name
510508

511509
isl::union_map reads;
512510
isl::union_map writes;

0 commit comments

Comments
 (0)