From 2380a08ca40ef15d8e3406d9bcc53a799f283758 Mon Sep 17 00:00:00 2001 From: Max191 <44243577+Max191@users.noreply.github.com> Date: Fri, 19 Jul 2024 11:00:32 -0700 Subject: [PATCH] [Codegen] Do not consider parallel regions in bufferization analysis (#17757) When there is a buffer used inside of an `scf.forall` op that is defined outside of the `scf.forall`, bufferization will unconditionally bufferize out of place by default in order to avoid race conditions. However, handling parallel accesses to a buffer should generally be the responsibility of the source program, and if there is a race condition, then it should be handled outside of bufferization. This PR disables the parallel region check in IREE to simplify the bufferization analysis and enable more buffer reuse. It is possible that this PR could cause race conditions if data races are not handled properly, and we are relying too much on bufferization to be conservative. Turning this option off could be a good early step in diagnosing data races on GPU. --------- Signed-off-by: Max Dawkins --- .../Codegen/Common/IREEComprehensiveBufferizePass.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/compiler/src/iree/compiler/Codegen/Common/IREEComprehensiveBufferizePass.cpp b/compiler/src/iree/compiler/Codegen/Common/IREEComprehensiveBufferizePass.cpp index 97a28212ccbb..9b46b845e935 100644 --- a/compiler/src/iree/compiler/Codegen/Common/IREEComprehensiveBufferizePass.cpp +++ b/compiler/src/iree/compiler/Codegen/Common/IREEComprehensiveBufferizePass.cpp @@ -206,6 +206,11 @@ void IREEComprehensiveBufferizePass::runOnOperation() { options.printConflicts = printConflicts; options.allocationFn = allocationFn; options.memCpyFn = memCpyFn; + // Turning off checkParallelRegions assumes that we are not relying too much + // on bufferization being conservative. If we are, then this could cause race + // conditions. Turning this option off could be a good step in diagnosing + // data races on GPU. + options.checkParallelRegions = false; if (failed(runIREEOneShotBufferize(funcOp, options))) { return signalPassFailure();