[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
This commit is contained in:
Ivan Butygin 2022-09-09 00:04:01 +02:00
parent 606245ad54
commit a93ec06ae6
3 changed files with 16 additions and 3 deletions

View File

@ -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)
}];

View File

@ -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)) ||

View File

@ -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
}