Skip to content

Commit a93ec06

Browse files
committed
[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
1 parent 606245a commit a93ec06

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -919,15 +919,19 @@ def GPU_AllocOp : GPU_Op<"alloc", [
919919
it does not block until the execution has finished on the device). In
920920
that case, it also returns a !gpu.async.token.
921921

922+
If the `host_shared` keyword is present, the memory will be allocated in a
923+
memory accessible both on host and on device.
924+
922925
Example:
923926

924927
```mlir
925-
%memref, %token = gpu.alloc async [%dep] (%width) : memref<64x?xf32, 1>
928+
%memref, %token = gpu.alloc async [%dep] host_shared (%width) : memref<64x?xf32, 1>
926929
```
927930
}];
928931

929932
let arguments = (ins Variadic<GPU_AsyncToken>:$asyncDependencies,
930-
Variadic<Index>:$dynamicSizes, Variadic<Index>:$symbolOperands);
933+
Variadic<Index>:$dynamicSizes, Variadic<Index>:$symbolOperands,
934+
UnitAttr:$hostShared);
931935
let results = (outs Res<AnyMemRef, "", [MemAlloc]>:$memref,
932936
Optional<GPU_AsyncToken>:$asyncToken);
933937

@@ -936,7 +940,7 @@ def GPU_AllocOp : GPU_Op<"alloc", [
936940
}];
937941

938942
let assemblyFormat = [{
939-
custom<AsyncDependencies>(type($asyncToken), $asyncDependencies) ` `
943+
custom<AsyncDependencies>(type($asyncToken), $asyncDependencies) (` ` `host_shared` $hostShared^)? ` `
940944
`(` $dynamicSizes `)` (`` `[` $symbolOperands^ `]`)? attr-dict `:` type($memref)
941945
}];
942946

mlir/lib/Conversion/GPUCommon/GPUToLLVMConversion.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,10 @@ LogicalResult ConvertHostRegisterOpToGpuRuntimeCallPattern::matchAndRewrite(
464464
LogicalResult ConvertAllocOpToGpuRuntimeCallPattern::matchAndRewrite(
465465
gpu::AllocOp allocOp, OpAdaptor adaptor,
466466
ConversionPatternRewriter &rewriter) const {
467+
if (adaptor.getHostShared())
468+
return rewriter.notifyMatchFailure(
469+
allocOp, "host_shared allocation is not supported");
470+
467471
MemRefType memRefType = allocOp.getType();
468472

469473
if (failed(areAllLLVMTypes(allocOp, adaptor.getOperands(), rewriter)) ||

mlir/test/Dialect/GPU/ops.mlir

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,11 @@ module attributes {gpu.container_module} {
209209
// CHECK: gpu.dealloc async [%[[t1]]] %[[m1]] : memref<13xf32, 1>
210210
%t2 = gpu.dealloc async [%t1] %m1 : memref<13xf32, 1>
211211

212+
// CHECK: %[[m2:.*]] = gpu.alloc host_shared () : memref<13xf32, 1>
213+
%m2 = gpu.alloc host_shared () : memref<13xf32, 1>
214+
// CHECK: gpu.dealloc %[[m2]] : memref<13xf32, 1>
215+
gpu.dealloc %m2 : memref<13xf32, 1>
216+
212217
return
213218
}
214219

0 commit comments

Comments
 (0)