Reland of the original patch after updating the Python binding tests, a few CUDA/GPU MLIR tests, and ensuring the assembly format is round-trippable. This patch splits the lowering of vector.print into first converting an n-D print into a loop of scalar prints of the elements, then a second pass that converts those scalar prints into the runtime calls. The former is done in VectorToSCF and the latter in VectorToLLVM. The main reason for this is to allow printing scalable vector types, which are not possible to fully unroll at compile time, though this also avoids fully unrolling very large vectors. To allow VectorToSCF to add the necessary punctuation between vectors and elements, a "punctuation" attribute has been added to vector.print. This abstracts calling the runtime functions such as printNewline(), without leaking the LLVM details into the higher abstraction levels. For example: vector.print punctuation <comma> lowers to llvm.call @printComma() : () -> () The output format and runtime functions remain the same, which avoids the need to alter a large number of tests (aside from the pipelines). Reviewed By: awarzynski, c-rhodes, aartbik Differential Revision: https://reviews.llvm.org/D156519
37 lines
1.7 KiB
MLIR
37 lines
1.7 KiB
MLIR
// RUN: mlir-opt %s -convert-vector-to-scf -convert-scf-to-cf -convert-vector-to-llvm -convert-func-to-llvm -reconcile-unrealized-casts | \
|
|
// RUN: mlir-cpu-runner -e entry -entry-point-result=void \
|
|
// RUN: -shared-libs=%mlir_c_runner_utils | \
|
|
// RUN: FileCheck %s
|
|
|
|
func.func @entry() {
|
|
%f1 = arith.constant 1.0: f32
|
|
%f2 = arith.constant 2.0: f32
|
|
%f3 = arith.constant 3.0: f32
|
|
%f4 = arith.constant 4.0: f32
|
|
%v1 = vector.broadcast %f1 : f32 to vector<4xf32>
|
|
%v2 = vector.broadcast %f2 : f32 to vector<3xf32>
|
|
%v3 = vector.broadcast %f3 : f32 to vector<4x4xf32>
|
|
%v4 = vector.broadcast %f4 : f32 to vector<1xf32>
|
|
|
|
%s1 = vector.insert_strided_slice %v1, %v3 {offsets = [2, 0], strides = [1]} : vector<4xf32> into vector<4x4xf32>
|
|
%s2 = vector.insert_strided_slice %v2, %s1 {offsets = [1, 1], strides = [1]} : vector<3xf32> into vector<4x4xf32>
|
|
%s3 = vector.insert_strided_slice %v2, %s2 {offsets = [0, 0], strides = [1]} : vector<3xf32> into vector<4x4xf32>
|
|
%s4 = vector.insert_strided_slice %v4, %s3 {offsets = [3, 3], strides = [1]} : vector<1xf32> into vector<4x4xf32>
|
|
|
|
vector.print %v3 : vector<4x4xf32>
|
|
vector.print %s1 : vector<4x4xf32>
|
|
vector.print %s2 : vector<4x4xf32>
|
|
vector.print %s3 : vector<4x4xf32>
|
|
vector.print %s4 : vector<4x4xf32>
|
|
//
|
|
// insert strided slice:
|
|
//
|
|
// CHECK: ( ( 3, 3, 3, 3 ), ( 3, 3, 3, 3 ), ( 3, 3, 3, 3 ), ( 3, 3, 3, 3 ) )
|
|
// CHECK: ( ( 3, 3, 3, 3 ), ( 3, 3, 3, 3 ), ( 1, 1, 1, 1 ), ( 3, 3, 3, 3 ) )
|
|
// CHECK: ( ( 3, 3, 3, 3 ), ( 3, 2, 2, 2 ), ( 1, 1, 1, 1 ), ( 3, 3, 3, 3 ) )
|
|
// CHECK: ( ( 2, 2, 2, 3 ), ( 3, 2, 2, 2 ), ( 1, 1, 1, 1 ), ( 3, 3, 3, 3 ) )
|
|
// CHECK: ( ( 2, 2, 2, 3 ), ( 3, 2, 2, 2 ), ( 1, 1, 1, 1 ), ( 3, 3, 3, 4 ) )
|
|
|
|
return
|
|
}
|