[Mlir-commits] [mlir] [mlir][vector][docs] Document indexed vs. non-indexed arguments (PR #130141)
Andrzej WarzyĆski
llvmlistbot at llvm.org
Fri Mar 7 05:39:36 PST 2025
https://github.com/banach-space updated https://github.com/llvm/llvm-project/pull/130141
>From c572b0ec1e5dbd0d4b77e22ff880ec147286b251 Mon Sep 17 00:00:00 2001
From: Andrzej Warzynski <andrzej.warzynski at arm.com>
Date: Thu, 6 Mar 2025 16:43:32 +0000
Subject: [PATCH] [mlir][vector][docs] Document indexed vs. non-indexed
arguments
Adds a section to the Vector dialect documentation introducing the
distinction between **indexed** and **non-indexed** arguments for
"read"/"write"-like operations.
The goal is to provide guidance on improving terminology consistency
within the Vector dialect and to establish a point of reference for
future discussions.
Credits to Diego Caballero <dieg0ca6aller0 at gmail.com> for proposing this
terminology in on of the PRs.
---
mlir/docs/Dialects/Vector.md | 83 ++++++++++++++++++++++++++++++++++++
1 file changed, 83 insertions(+)
diff --git a/mlir/docs/Dialects/Vector.md b/mlir/docs/Dialects/Vector.md
index ade0068c56fb6..fab75d88cabba 100644
--- a/mlir/docs/Dialects/Vector.md
+++ b/mlir/docs/Dialects/Vector.md
@@ -257,6 +257,89 @@ expressing `vector`s in the IR directly and simple pattern-rewrites.
[EDSC](https://github.com/llvm/llvm-project/blob/main/mlir/docs/EDSC.md)s
provide a simple way of driving such a notional language directly in C++.
+### Taxonomy for "To" and "From" Operands for "Read"/"Write" Ops
+
+Below is a list of vector dialect operations that move values from an abstract
+**source** to an abstract **destination** (i.e., "read"/"write" operations):
+
+* `vector.load`, `vector.store`, `vector.transfer_read`,
+ `vector.transfer_write`, `vector.gather`, `vector.scatter`,
+ `vector.compressstore`, `vector.expandload`, `vector.maskedload`,
+ `vector.maskedstore`, `vector.extract`, `vector.insert`,
+ `vector.scalable_extract`, `vector.scalable_insert`,
+ `vector.extract_strided_slice`, `vector.insert_strided_slice`.
+
+For consistency, let's define:
+- **"Source"** as where values are _read from_.
+- **"Destination"** as where values are _written to_.
+
+#### Current Naming in Vector Dialect
+| **Vector Dialect Op** | **Operand Names** | **Operand Types** | **Result Names** | **Result Types** |
+|--------------------------------|--------------------------|-------------------------------|------------------|----------------------------|
+| `vector.load` | `base` | `memref` | `result` | `vector` |
+| `vector.store` | `valueToStore`, `base` | `vector`, `memref` | - | - |
+| `vector.transfer_read` | `source` | `memref` / `tensor` | `vector` | `vector` |
+| `vector.transfer_write` | `vector`, `source` | `vector`, `memref`/ `tensor` | `result` | `vector` |
+| `vector.gather` | `base` | `memref` | `result` | `vector` |
+| `vector.scatter` | `valueToStore`, `base` | `vector`, `memref` | - | - |
+| `vector.expandload` | `base` | `memref` | `result` | `vector` |
+| `vector.compressstore` | `valueToStore`,`base` | `vector`, `memref` | - | - |
+| `vector.maskedload` | `base` | `memref` | `result` | `vector` |
+| `vector.maskedstore` | `valueToStore`, `base` | `vector`, `memref` | - | - |
+| `vector.extract` | `vector` | `vector` | `result` | `scalar` / `vector` |
+| `vector.insert` | `source`, `dest` | `scalar` / `vector`, `vector` | `result` | `vector` |
+| `vector.scalable_extract` | `source` | `vector` | `res` | `scalar` / `vector` |
+| `vector.scalable_insert` | `source`, `dest` | `scalar` / `vector`, `vector` | `res` | `vector` |
+| `vector.extract_strided_slice` | `vector` | `vector` | (missing name) | `vector` |
+| `vector.insert_strided_slice` | `source`, `dest` | `vector` | `res` | `vector` |
+
+### Observations
+Although each of these operations has a **"source" and/or a "destination"**
+operand, their naming conventions are inconsistent. This makes it difficult to
+extract common patterns and to identify which one refers to which argument.
+Below are some examples using the auto-generated accessesors:
+* `getBase()` for `vector.load` and `vector.store` refers to both "source" (for
+ the former) and "destination" (for the latter).
+* In contrast, `vector.transfer_write` + `vector.transfer_read` use
+ `getSource()`. It's inconsistent with the `vector.load` + `vector.store` pair
+ and it also makes unclear whether the corresponding input represents "source"
+ or "destination".
+* `vector.insert` does define `getSource()` + `getDest()`, so the distinction
+ between "to" and "from" arguments is clear. But it is inconsistent with other
+ Ops. However, its sibling Op, `vector.extract`, only defines `getVector`.
+
+Some names should be **unified**, but that is a separate issue:
+* `getVector` vs `getValueToStore` (`vector.store` and
+ `vector.insert_strided_slice`, respectively).
+
+### Indexed vs. Non-Indexed Taxonomy
+One way to define a **consistent distinction** between "to" and "from"
+arguments is based on whether an operand is **indexed** or **non-indexed**.
+
+For example, consider `vector.transfer_read` and `vector.transfer_write`:
+
+```mlir
+ Indexed Operand
+ |
+vector.transfer_read %A[%expr1, %expr2, %expr3, %expr4]
+ { permutation_map : (d0,d1,d2,d3) -> (d2,0,d0) } :
+ memref<?x?x?x?xf32>, vector<3x4x5xf32>
+ |
+ Non-Indexed Result
+
+ Non-Indexed Operand Indexed Operand
+ \ /
+vector.transfer_write %4, %arg1[%c3, %c3]
+ {permutation_map = (d0, d1)->(d0, d1)}
+ : vector<1x1x4x3xf32>, memref<?x?xvector<4x3xf32>>
+```
+
+Using the "indexed" vs. "non-indexed" classification, we can systematically
+differentiate between "to" and "from" arguments across operations:
+* "to" is always indexed for "write" operations, "from" is non-indexed,
+* "from" is always indexed for "read" oprations, "to" is always non-indexed.
+
+
## Bikeshed Naming Discussion
There are arguments against naming an n-D level of abstraction `vector` because
More information about the Mlir-commits
mailing list