Skip to content

[mlir][gpu] Skip address space checks for memrefs between launchFuncOp and kernel func #102925

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion mlir/lib/Dialect/GPU/IR/GPUDialect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -401,8 +401,29 @@ LogicalResult GPUDialect::verifyOperationAttribute(Operation *op,
<< expectedNumArguments;

auto functionType = kernelGPUFunction.getFunctionType();
auto typesMatch = [&](Type launchOpArgType, Type gpuFuncArgType) {
auto launchOpMemref = dyn_cast<MemRefType>(launchOpArgType);
auto kernelMemref = dyn_cast<MemRefType>(gpuFuncArgType);
// Allow address space incompatibility for OpenCL kernels: `gpu.launch`'s
// argument memref without address space attribute will match a kernel
// function's memref argument with address space `Global`.
if (launchOpMemref && kernelMemref) {
auto launchAS = llvm::dyn_cast_or_null<gpu::AddressSpaceAttr>(
launchOpMemref.getMemorySpace());
auto kernelAS = llvm::dyn_cast_or_null<gpu::AddressSpaceAttr>(
kernelMemref.getMemorySpace());
if (!launchAS && kernelAS &&
kernelAS.getValue() == gpu::AddressSpace::Global)
return launchOpMemref.getShape() == kernelMemref.getShape() &&
launchOpMemref.getLayout() == kernelMemref.getLayout() &&
launchOpMemref.getElementType() ==
kernelMemref.getElementType();
}
return launchOpArgType == gpuFuncArgType;
};
for (unsigned i = 0; i < expectedNumArguments; ++i) {
if (launchOp.getKernelOperand(i).getType() != functionType.getInput(i)) {
if (!typesMatch(launchOp.getKernelOperand(i).getType(),
functionType.getInput(i))) {
return launchOp.emitOpError("type of function argument ")
<< i << " does not match";
}
Expand Down
14 changes: 14 additions & 0 deletions mlir/test/Dialect/GPU/ops.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -441,3 +441,17 @@ gpu.module @module_with_two_target [#nvvm.target, #rocdl.target<chip = "gfx90a">

gpu.module @module_with_offload_handler <#gpu.select_object<0>> [#nvvm.target] {
}

// Check kernel memref args are valid even if the address space differs
module attributes {gpu.container_module} {
func.func @foo(%mem : memref<5xf32>) {
%c0 = arith.constant 0 : i32
gpu.launch_func @gpu_kernels::@kernel blocks in (%c0, %c0, %c0) threads in (%c0, %c0, %c0) : i32 args(%mem : memref<5xf32>)
return
}
gpu.module @gpu_kernels {
gpu.func @kernel(%arg0 : memref<5xf32, #gpu.address_space<global>>) kernel {
gpu.return
}
}
}
Loading