LLVM Discussion Forums

N-D vector transfer_read/write

Hi,

trying to use the vector.transfer_read/write operations. I got them working for 1D (there are tests for that in MLIR) but not 2D (no tests for 2d). Can you tell me if I am missing something?

working 1D

// mlir-opt  -convert-vector-to-scf  -convert-vector-to-llvm -convert-scf-to-std -convert-std-to-llvm
func @simple1Dvec(%A: memref<16xf32>, %B: memref<16xf32>) {
  %c0 = constant 0: index
  %fm0 = constant 0.0 : f32
  %va = vector.transfer_read %A[%c0], %fm0 {permutation_map=affine_map<(d0) -> (d0)>} : memref<16xf32>, vector<16xf32>
  %vb = std.addf %va, %va: vector<16xf32>
  vector.transfer_write %vb, %B[%c0] {permutation_map=affine_map<(d0) -> (d0)>} : vector<16xf32>, memref<16xf32>
  return
}

whereas the 2D version results in errors (tried a few command variations)

// ~/Onnxcode/llvm-project/build/bin/mlir-opt mat.mlir --convert-vector-to-scf  -convert-vector-to-llvm -convert-scf-to-std -convert-std-to-llvm

func @test2dvect(%A: memref<4x4xf32>, %B: memref<4x4xf32>) {
  %c0 = constant 0: index
  %fm0 = constant 0.0 : f32
  %va = vector.transfer_read %A[%c0, %c0], %fm0 {permutation_map=affine_map<(d0, d1) -> (d0, d1)>} : memref<4x4xf32>, vector<4x4xf32>
  %vb = std.addf %va, %va: vector<4x4xf32>
  vector.transfer_write %vb, %B[%c0, %c0] {permutation_map=affine_map<(d0, d1) -> (d0, d1)>} : vector<4x4xf32>, memref<4x4xf32>
  return
}

@aartbik, @AlexEichenberger thanks for raising, this is actually supported but the n-D -> 1-D lowering uses affine atm and so requires -lower-affine.

mlir-opt --convert-vector-to-scf -lower-affine --convert-scf-to-std --convert-vector-to-llvm /tmp/aaa.mlir

should work.

works like a charm, thanks.

Wait until you hit new corner cases :wink: @aartbik fixed a bunch in LLVM to get this running reliably.

Side note, if you plan on using these, there is still quite some work needed on canonicalizations and masks for the cases that don’t divide statically.

Trying a few 2D examples, have some that works, some that do not. Happy to add the working examples in the integration tests.

What is the best forum to report examples that fails? Here or somewhere else? Thanks for the guidance.

Vector dialect under
https://bugs.llvm.org/enter_bug.cgi?product=MLIR&Bugzilla_restrictlogin=on&GoAheadAndLogIn=Log%20in

seems like the best place.

And, perhaps needless to say, but please CC Nicolas and myself on the bug so we don’t miss it!