Skip to content

Commit 228d0b1

Browse files
committed
[mlir] Test vector.to_elements to spirv conversion.
1 parent aa4906a commit 228d0b1

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// RUN: mlir-opt -test-convert-to-spirv="run-signature-conversion=false run-vector-unrolling=true" -split-input-file %s | FileCheck %s
2+
3+
// COM: This file tests the current behaviour of the SignatureConversion
4+
// COM: and the unrolling of vector.to_elements to vectors of valid SPIR-V
5+
// COM: sizes.
6+
7+
// COM: vector's of rank 1 and size 1 will be changed
8+
// COM: to scalars. Since vector.to_elements will also produce
9+
// COM: a scalar, we expect the vector.to_elements to be folded
10+
// COM: away. Please note that even if run-signature-conversion=false
11+
// COM: The pattern FuncOpConversion will still run and change parameters
12+
// COM: which fit this constraint.
13+
14+
// CHECK-LABEL: spirv.func @vec_size_1
15+
// CHECK-SAME: (%[[ARG0:.+]]: f32)
16+
func.func @vec_size_1(%arg0: vector<1xf32>) -> (f32) {
17+
// CHECK-NEXT: spirv.ReturnValue %[[ARG0]] : f32
18+
%0:1 = vector.to_elements %arg0 : vector<1xf32>
19+
return %0#0 : f32
20+
}
21+
22+
// -----
23+
24+
// COM: vector's of rank 2, 3, 4 are allowed by SPIR-V.
25+
// So they remain unchanged. FuncOpConversion will still
26+
// run, but the signature converter will not convert these vectors.
27+
28+
// CHECK-LABEL: spirv.func @vec_size_2
29+
// CHECK-SAME: (%[[ARG0:.+]]: vector<2xf32>)
30+
func.func @vec_size_2(%arg0: vector<2xf32>) -> (f32) {
31+
// COM: A single result type is enforced by the semantics
32+
33+
// CHECK-NEXT: %[[VAL:.+]] = spirv.CompositeExtract %[[ARG0]][0 : i32] : vector<2xf32>
34+
%0:2 = vector.to_elements %arg0 : vector<2xf32>
35+
36+
// CHECK-NEXT: spirv.ReturnValue %[[VAL]]
37+
return %0#0 : f32
38+
}
39+
40+
// -----
41+
42+
// COM: vector of rank 5 is the first one that doesn't fit
43+
// COM: into SPIR-V's vectors.
44+
45+
// COM: run-signature-conversion=false means that
46+
// COM: this vector will not be unrolled.
47+
48+
// CHECK-LABEL: func.func @vec_size_5
49+
// CHECK-SAME: (%[[ARG0:.+]]: vector<5xf32>)
50+
func.func @vec_size_5(%arg0: vector<5xf32>) -> (f32) {
51+
52+
// CHECK-NEXT: %[[VAL:.+]] = vector.extract_strided_slice %[[ARG0]] {offsets = [0], sizes = [1], strides = [1]} : vector<5xf32> to vector<1xf32>
53+
54+
// COM: We have the following comment in VectorConvertToElementOp
55+
// COM:
56+
// COM: // Input vectors of size 1 are converted to scalars by the type converter.
57+
// COM: // We cannot use `spirv::CompositeExtractOp` directly in this case.
58+
// COM: // For a scalar source, the result is just the scalar itself.
59+
// COM:
60+
// COM: Which in this case means an unrealized conversion cast.
61+
62+
// CHECK-NEXT: %[[RETVAL:.+]] = builtin.unrealized_conversion_cast %[[VAL]] : vector<1xf32> to f32
63+
%0:5 = vector.to_elements %arg0 : vector<5xf32>
64+
65+
// CHECK-NEXT: spirv.ReturnValue %[[RETVAL]] : f32
66+
return %0#0 : f32
67+
}

0 commit comments

Comments
 (0)