[Mlir-commits] [mlir] [mlir] Add DenseUI32ArrayAttr (PR #68230)

Maya Amrami llvmlistbot at llvm.org
Tue Oct 10 03:08:28 PDT 2023


amrami wrote:

@joker-eph - I have a op with permutation attribute. Since this is a permutation of the tensor dims, I know that values are >= 0.
So I find it more accurate to declare the attribute as DenseUI32ArrayAttr.

I looked now at the existing code, and saw that linalg TransposeOp uses `DenseI64ArrayAttr:$permutation`.
Then the verifier validates that no negative numbers are there:

```
LogicalResult TransposeOp::verify() {
  ArrayRef<int64_t> permutationRef = getPermutation();

  if (!isPermutationVector(permutationRef))
    return emitOpError("permutation is not valid");
...
```

Where
```
bool mlir::isPermutationVector(ArrayRef<int64_t> interchange) {
  assert(llvm::all_of(interchange, [](int64_t s) { return s >= 0; }) &&
         "permutation must be non-negative");
  llvm::SmallDenseSet<int64_t, 4> seenVals;
  for (auto val : interchange) {
    if (seenVals.count(val))
      return false;
    seenVals.insert(val);
  }
  return seenVals.size() == interchange.size();
}
```

I believe the permutation could be `DenseUI64ArrayAttr` (which can be added too)


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


More information about the Mlir-commits mailing list