[Mlir-commits] [mlir] 8a8bacb - [mlir][GPU] treat the absence of workgroup attributes correctly

Alex Zinenko llvmlistbot at llvm.org
Thu Sep 29 05:36:19 PDT 2022


Author: Alex Zinenko
Date: 2022-09-29T12:36:10Z
New Revision: 8a8bacb973837147f97b939d1373cd02057424fc

URL: https://github.com/llvm/llvm-project/commit/8a8bacb973837147f97b939d1373cd02057424fc
DIFF: https://github.com/llvm/llvm-project/commit/8a8bacb973837147f97b939d1373cd02057424fc.diff

LOG: [mlir][GPU] treat the absence of workgroup attributes correctly

The helper function in GPUFuncOp incorrectly assumed the workgroup
attribution attribute is always present. Instead, treat its absence as
if its value was zero, i.e., no workgroup attributions are specified.

Closes #58045.

Reviewed By: nicolasvasilache

Differential Revision: https://reviews.llvm.org/D134865

Added: 
    

Modified: 
    mlir/include/mlir/Dialect/GPU/IR/GPUOps.td
    mlir/test/Dialect/GPU/ops.mlir

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/Dialect/GPU/IR/GPUOps.td b/mlir/include/mlir/Dialect/GPU/IR/GPUOps.td
index c7816063bf870..673be1bb41804 100644
--- a/mlir/include/mlir/Dialect/GPU/IR/GPUOps.td
+++ b/mlir/include/mlir/Dialect/GPU/IR/GPUOps.td
@@ -263,8 +263,9 @@ def GPU_GPUFuncOp : GPU_Op<"func", [
 
     /// Returns the number of buffers located in the workgroup memory.
     unsigned getNumWorkgroupAttributions() {
-      return (*this)->getAttrOfType<IntegerAttr>(
-          getNumWorkgroupAttributionsAttrName()).getInt();
+      auto attr = (*this)->getAttrOfType<IntegerAttr>(
+          getNumWorkgroupAttributionsAttrName());
+      return attr ? attr.getInt() : 0;
     }
 
     /// Returns a list of block arguments that correspond to buffers located in

diff  --git a/mlir/test/Dialect/GPU/ops.mlir b/mlir/test/Dialect/GPU/ops.mlir
index f882a8e5d630a..0ffaf2210fc5e 100644
--- a/mlir/test/Dialect/GPU/ops.mlir
+++ b/mlir/test/Dialect/GPU/ops.mlir
@@ -284,3 +284,10 @@ module attributes {gpu.container_module} {
     return
   }
 }
+
+// Just check that this doesn't crash.
+gpu.module @module {
+  "gpu.func"() ({
+    gpu.return
+  }) {function_type = () -> (), sym_name = "func"} : () -> ()
+}


        


More information about the Mlir-commits mailing list