[Mlir-commits] [mlir] a93ec06 - [mlir][gpu] Introduce `host_shared` flag to `gpu.alloc`
Ivan Butygin
llvmlistbot at llvm.org
Wed Oct 5 13:03:46 PDT 2022
Author: Ivan Butygin
Date: 2022-10-05T22:01:30+02:00
New Revision: a93ec06ae6277480b3f3d7521f867a7099e68fc1
URL: https://github.com/llvm/llvm-project/commit/a93ec06ae6277480b3f3d7521f867a7099e68fc1
DIFF: https://github.com/llvm/llvm-project/commit/a93ec06ae6277480b3f3d7521f867a7099e68fc1.diff
LOG: [mlir][gpu] Introduce `host_shared` flag to `gpu.alloc`
Motivation: we have lowering pipeline based on upstream gpu and spirv dialects and and we are using host shared gpu memory to transfer data between host and device.
Add `host_shared` flag to `gpu.alloc` to distinguish between shared and device-only gpu memory allocations.
Differential Revision: https://reviews.llvm.org/D133533
Added:
Modified:
mlir/include/mlir/Dialect/GPU/IR/GPUOps.td
mlir/lib/Conversion/GPUCommon/GPUToLLVMConversion.cpp
mlir/test/Dialect/GPU/ops.mlir
Removed:
################################################################################
diff --git a/mlir/include/mlir/Dialect/GPU/IR/GPUOps.td b/mlir/include/mlir/Dialect/GPU/IR/GPUOps.td
index 43d4c7ef9efa..f3d10464cbc4 100644
--- a/mlir/include/mlir/Dialect/GPU/IR/GPUOps.td
+++ b/mlir/include/mlir/Dialect/GPU/IR/GPUOps.td
@@ -919,15 +919,19 @@ def GPU_AllocOp : GPU_Op<"alloc", [
it does not block until the execution has finished on the device). In
that case, it also returns a !gpu.async.token.
+ If the `host_shared` keyword is present, the memory will be allocated in a
+ memory accessible both on host and on device.
+
Example:
```mlir
- %memref, %token = gpu.alloc async [%dep] (%width) : memref<64x?xf32, 1>
+ %memref, %token = gpu.alloc async [%dep] host_shared (%width) : memref<64x?xf32, 1>
```
}];
let arguments = (ins Variadic<GPU_AsyncToken>:$asyncDependencies,
- Variadic<Index>:$dynamicSizes, Variadic<Index>:$symbolOperands);
+ Variadic<Index>:$dynamicSizes, Variadic<Index>:$symbolOperands,
+ UnitAttr:$hostShared);
let results = (outs Res<AnyMemRef, "", [MemAlloc]>:$memref,
Optional<GPU_AsyncToken>:$asyncToken);
@@ -936,7 +940,7 @@ def GPU_AllocOp : GPU_Op<"alloc", [
}];
let assemblyFormat = [{
- custom<AsyncDependencies>(type($asyncToken), $asyncDependencies) ` `
+ custom<AsyncDependencies>(type($asyncToken), $asyncDependencies) (` ` `host_shared` $hostShared^)? ` `
`(` $dynamicSizes `)` (`` `[` $symbolOperands^ `]`)? attr-dict `:` type($memref)
}];
diff --git a/mlir/lib/Conversion/GPUCommon/GPUToLLVMConversion.cpp b/mlir/lib/Conversion/GPUCommon/GPUToLLVMConversion.cpp
index 3fde6abe294f..a529c529d354 100644
--- a/mlir/lib/Conversion/GPUCommon/GPUToLLVMConversion.cpp
+++ b/mlir/lib/Conversion/GPUCommon/GPUToLLVMConversion.cpp
@@ -464,6 +464,10 @@ LogicalResult ConvertHostRegisterOpToGpuRuntimeCallPattern::matchAndRewrite(
LogicalResult ConvertAllocOpToGpuRuntimeCallPattern::matchAndRewrite(
gpu::AllocOp allocOp, OpAdaptor adaptor,
ConversionPatternRewriter &rewriter) const {
+ if (adaptor.getHostShared())
+ return rewriter.notifyMatchFailure(
+ allocOp, "host_shared allocation is not supported");
+
MemRefType memRefType = allocOp.getType();
if (failed(areAllLLVMTypes(allocOp, adaptor.getOperands(), rewriter)) ||
diff --git a/mlir/test/Dialect/GPU/ops.mlir b/mlir/test/Dialect/GPU/ops.mlir
index 0ffaf2210fc5..52320744d078 100644
--- a/mlir/test/Dialect/GPU/ops.mlir
+++ b/mlir/test/Dialect/GPU/ops.mlir
@@ -209,6 +209,11 @@ module attributes {gpu.container_module} {
// CHECK: gpu.dealloc async [%[[t1]]] %[[m1]] : memref<13xf32, 1>
%t2 = gpu.dealloc async [%t1] %m1 : memref<13xf32, 1>
+ // CHECK: %[[m2:.*]] = gpu.alloc host_shared () : memref<13xf32, 1>
+ %m2 = gpu.alloc host_shared () : memref<13xf32, 1>
+ // CHECK: gpu.dealloc %[[m2]] : memref<13xf32, 1>
+ gpu.dealloc %m2 : memref<13xf32, 1>
+
return
}
More information about the Mlir-commits
mailing list