Create a vector from elements


I am trying to create a vector from elements in MLIR, but I cannot find a way to do it in a consise way, here is a small example:

%c0 = arith.constant 0 : index
%c1 = arith.constant 11 : index
%c2 = arith.constant 12 : index
%c3 = arith.constant 13 : index
%c4 = arith.constant 14 : index
%c5 = arith.constant 15 : index
%c6 = arith.constant 16 : index
%c7 = arith.constant 17 : index
%c8 = arith.constant 18 : index

%from_elements = tensor.from_elements %c8, %c7, %c6,
                                      %c5, %c4, %c3,
                                      %c2, %c1, %c0
            : tensor<9xindex>

%transfer = vector.transfer_read %from_elements[%c0],
                                 %c0 {in_bounds = [true]}
        : tensor<9xindex>, vector<9xindex>

Do we have something to do this for vectors without using tensor.from_elements like this:

%transfer = vector.transfer_read %c8, %c7, %c6,
                                 %c5, %c4, %c3,
                                 %c2, %c1, %c0
        : tensor<9xindex>, vector<9xindex>

I think right now this would have to be a series of vector.insertions. If you only need it for constants, you can also create a vector constant from a dense element attribute.

In the SPIR-V dialect we have spirv.CompositeConstruct that seems like what you described: SPIR-V Dialect - MLIR

1 Like