[Mlir-commits] [mlir] Skip address space checks for memrefs between launchOp and kernel func (PR #102925)

Victor Perez llvmlistbot at llvm.org
Wed Aug 14 03:58:29 PDT 2024


================
@@ -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)
----------------
victor-eds wrote:

I see. In fact, I was thinking on a nonexistent issue. I think we're fine, as, when the kernel is still a `gpu.func`, local memory should be represented as memory attributions in the function, so, instead of:
```
gpu.func @kernel(%slm: memref<f32, #gpu.address_space<workgroup>>, ...)
```
we'll have:
```
gpu.func @kernel(...)
    workgroup(%slm: memref<f32, #gpu.address_space<workgroup>>)
```
And only when converting to LLMV dialect (no signature check anymore), we'll have:
```
llvm.func @kernel(..., %slm: llvm.ptr<3>)
```

TL;DR: We are fine. Thanks!

https://github.com/llvm/llvm-project/pull/102925


More information about the Mlir-commits mailing list