[TEXPR][PASS] Fix thread all reduce to avoid write after read hazzard (#2937)
authorTianqi Chen <tqchen@users.noreply.github.com>
Mon, 1 Apr 2019 06:04:03 +0000 (23:04 -0700)
committerGitHub <noreply@github.com>
Mon, 1 Apr 2019 06:04:03 +0000 (23:04 -0700)
src/pass/lower_thread_allreduce.cc

index 05f942f..2c1bce8 100644 (file)
@@ -175,6 +175,9 @@ class ThreadAllreduceBuilder final : public IRMutator {
     }
     std::vector<Stmt> seq;
     std::vector<Var> shared_bufs(size);
+    // This sync is necessary because there might be incomplete read of
+    // previous iteration on the same buffer.
+    seq.emplace_back(SyncThread("shared"));
     for (size_t idx = 0; idx < size; ++idx) {
       shared_bufs[idx] = Var("red_buf"+std::to_string(idx), Handle());
       Expr pred = const_true(types[idx].lanes());