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

Victor Perez llvmlistbot at llvm.org
Tue Aug 13 02:01:04 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:

According to the OpenCL spec  https://registry.khronos.org/OpenCL/specs/3.0-unified/html/OpenCL_API.html#setting-kernel-arguments:

```OpenCL
// Provided by CL_VERSION_1_0
cl_int clSetKernelArg(
    cl_kernel kernel,
    cl_uint arg_index,
    size_t arg_size,
    const void* arg_value);
```

> arg_size specifies the size of the argument value. If the argument is a memory object, the arg_size value must be equal to sizeof(cl_mem). *For arguments declared with the local qualifier, the size specified will be the size in bytes of the buffer that must be allocated for the local argument.* If the argument is of type sampler_t, the arg_size value must be equal to sizeof(cl_sampler). If the argument is of type queue_t, the arg_size value must be equal to sizeof(cl_command_queue). For all other arguments, the size will be the size of argument type.


Also, in the OpenCL-SPIR-V client specification https://registry.khronos.org/OpenCL/specs/3.0-unified/html/OpenCL_Env.html#_kernel_arguments:

> For OpTypePointer parameters, supported Storage Classes are:
> - CrossWorkgroup
> - Workgroup
> - UniformConstant


I would also allow SLM pointer arguments here, as that's how, e.g., SYCL is doing it AFAIL


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


More information about the Mlir-commits mailing list