[Mlir-commits] [mlir] [mlir][linalg] added some conditions for values being undefined in the documentation for `linalg.generic` (PR #96251)

Jacob Yu llvmlistbot at llvm.org
Thu Jun 20 16:43:34 PDT 2024


https://github.com/pingshiyu created https://github.com/llvm/llvm-project/pull/96251

I've been quite confused by the "gotchas" in `linalg.generic` a couple of weeks back, running into undefined/unspecified behaviours a couple of times, case and point:
https://github.com/llvm/llvm-project/issues/94179
https://github.com/llvm/llvm-project/issues/94180

and I was helped by @ftynse to understand these issues. I thought it would be a good idea to document, in the specification, when the behaviours might be unexpected since they can be unintuitive. 

This is not specifying what "should" happen, but just specifying when things are undefined, reflective of the behaviour implemented within existing passes that I ran into. 

I'm not sure if these situations mentioned should be as strong as full undefined behaviour, versus just local "undefined values". 
This PR treats them as "undefined values" for now, but would be good to discuss them!

>From 1e3973bc43ab6492c1d7b2fbfa5ef88a042fd913 Mon Sep 17 00:00:00 2001
From: pingshiyu <pingshiyu at gmail.com>
Date: Fri, 21 Jun 2024 00:37:14 +0100
Subject: [PATCH] added some mentions of UBs in the documentation

---
 mlir/include/mlir/Dialect/Linalg/IR/LinalgStructuredOps.td | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/mlir/include/mlir/Dialect/Linalg/IR/LinalgStructuredOps.td b/mlir/include/mlir/Dialect/Linalg/IR/LinalgStructuredOps.td
index 5ee363ed32572..6fbb50dbf94ef 100644
--- a/mlir/include/mlir/Dialect/Linalg/IR/LinalgStructuredOps.td
+++ b/mlir/include/mlir/Dialect/Linalg/IR/LinalgStructuredOps.td
@@ -82,6 +82,11 @@ def GenericOp : LinalgStructuredBase_Op<"generic", [
         types:
           parallel, reduction, window
 
+    Any values within the output operands that are not unindexed by the 
+    `indexing_maps` are undefined.
+    Any dimensions associated with a `reduction` `iterator_types` must not 
+    be used for indexing output operands, otherwise the results are undefined.
+
     Example:
     Defining a #matmul_trait attribute in MLIR can be done as follows:
       ```mlir



More information about the Mlir-commits mailing list