[mlir][GPU] treat the absence of workgroup attributes correctly
authorAlex Zinenko <zinenko@google.com>
Thu, 29 Sep 2022 09:50:24 +0000 (09:50 +0000)
committerAlex Zinenko <zinenko@google.com>
Thu, 29 Sep 2022 12:36:10 +0000 (12:36 +0000)
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

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

index c781606..673be1b 100644 (file)
@@ -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
index f882a8e..0ffaf22 100644 (file)
@@ -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"} : () -> ()
+}