Skip to content

Commit

Permalink
Handle combination of atomic() and vectorize() in lowering
Browse files Browse the repository at this point in the history
  • Loading branch information
abadams committed Jun 11, 2020
1 parent 218ee13 commit 4a62886
Show file tree
Hide file tree
Showing 4 changed files with 522 additions and 29 deletions.
2 changes: 1 addition & 1 deletion src/Lower.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ Module lower(const vector<Function> &output_funcs,
<< s << "\n\n";

debug(1) << "Vectorizing...\n";
s = vectorize_loops(s, t);
s = vectorize_loops(s, env, t);
s = simplify(s);
debug(2) << "Lowering after vectorizing:\n"
<< s << "\n\n";
Expand Down
19 changes: 16 additions & 3 deletions src/ScheduleFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,9 +371,22 @@ Stmt build_provide_loop_nest(const map<string, Function> &env,
// Make the (multi-dimensional multi-valued) store node.
Stmt body = Provide::make(func.name(), values, site);
if (def.schedule().atomic()) { // Add atomic node.
// If required, we will allocate a mutex buffer called func.name() + ".mutex"
// The buffer is added in the AddAtomicMutex pass.
body = Atomic::make(func.name(), func.name() + ".mutex", body);
bool any_unordered_parallel = false;
for (auto d : def.schedule().dims()) {
any_unordered_parallel |= is_unordered_parallel(d.for_type);
}
if (any_unordered_parallel) {
// If required, we will allocate a mutex buffer called func.name() + ".mutex"
// The buffer is added in the AddAtomicMutex pass.
body = Atomic::make(func.name(), func.name() + ".mutex", body);
} else {
// No mutex is required if there is no parallelism, and it
// wouldn't work if all parallelism is synchronous
// (e.g. vectorization). Vectorization and the like will
// need to handle atomic nodes specially, by either
// emitting VectorReduce ops or scalarizing.
body = Atomic::make(func.name(), std::string{}, body);
}
}

// Default schedule/values if there is no specialization
Expand Down
Loading

0 comments on commit 4a62886

Please sign in to comment.