Skip to content

Commit 44027f3

Browse files
committed
[mlir][GPU] Prevent adding duplicate async tokens
If, in the GPU async transformation, the operation being given an async dependency already depended on the token in question, we would add duplicate tokens, creating issues in GPU to LLVM lowering. To resolve this issue, add a check to addAsyncDependency() to ensure that duplicate tokens are not present in the token list. (I'm open to a different approach here, this is just what I went with initially) Reviewed By: Mogball Differential Revision: https://reviews.llvm.org/D136105
1 parent 44b7da8 commit 44027f3

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

mlir/include/mlir/Dialect/GPU/IR/GPUBase.td

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,16 @@ def GPU_AsyncOpInterface : OpInterface<"AsyncOpInterface"> {
9696
}],
9797
"OperandRange", "getAsyncDependencies", (ins), [{}], [{
9898
ConcreteOp op = cast<ConcreteOp>(this->getOperation());
99-
return op.asyncDependencies();
99+
return op.getAsyncDependencies();
100100
}]
101101
>,
102102
InterfaceMethod<[{
103-
Adds a new token to the list of async dependencies.
103+
Adds a new token to the list of async dependencies if it is not already there.
104104
}],
105105
"void", "addAsyncDependency", (ins "Value":$token),
106106
[{}], [{
107-
::mlir::gpu::addAsyncDependency(this->getOperation(), token);
107+
if (!::llvm::is_contained(this->getAsyncDependencies(), token))
108+
::mlir::gpu::addAsyncDependency(this->getOperation(), token);
108109
}]
109110
>,
110111
InterfaceMethod<[{

mlir/include/mlir/Dialect/GPU/IR/GPUDialect.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "mlir/Interfaces/InferIntRangeInterface.h"
2626
#include "mlir/Interfaces/InferTypeOpInterface.h"
2727
#include "mlir/Interfaces/SideEffectInterfaces.h"
28+
#include "llvm/ADT/STLExtras.h"
2829

2930
namespace mlir {
3031
namespace gpu {

mlir/test/Dialect/GPU/async-region.mlir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ module attributes {gpu.container_module} {
175175
// CHECK: %[[t0:.*]] = gpu.wait async
176176
// CHECK-NOT: [{{.*}}]
177177
%t0 = gpu.wait async
178-
// CHECK: %[[t1:.*]] = gpu.wait async [%[[t0]], %[[t0]]]
178+
// CHECK: %[[t1:.*]] = gpu.wait async [%[[t0]]]
179179
%t1 = gpu.wait async [%t0]
180180
// CHECK: %[[m:.*]], %[[t2:.*]] = gpu.alloc async [%[[t1]], %[[t0]]] ()
181181
%0 = gpu.alloc [%t0] () : memref<7xf32>

0 commit comments

Comments
 (0)