Skip to content

Commit a8683f3

Browse files
committed
[mlir][spirv] Add integration test for vector.deinterleave
1 parent 1ebda11 commit a8683f3

File tree

1 file changed

+81
-0
lines changed

1 file changed

+81
-0
lines changed
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
// RUN: mlir-vulkan-runner %s \
2+
// RUN: --shared-libs=%vulkan-runtime-wrappers,%mlir_runner_utils \
3+
// RUN: --entry-point-result=void | FileCheck %s
4+
5+
// CHECK: [0, 2]
6+
// CHECK: [1, 3]
7+
module attributes {
8+
gpu.container_module,
9+
spirv.target_env = #spirv.target_env<
10+
#spirv.vce<v1.0, [Shader], [SPV_KHR_storage_buffer_storage_class]>, #spirv.resource_limits<>>
11+
} {
12+
gpu.module @kernels {
13+
gpu.func @kernel_vector_deinterleave(%arg0 : memref<4xi32>, %arg1 : memref<2xi32>, %arg2 : memref<2xi32>)
14+
kernel attributes { spirv.entry_point_abi = #spirv.entry_point_abi<workgroup_size = [1, 1, 1]>} {
15+
%idx0 = arith.constant 0 : index
16+
%idx1 = arith.constant 1 : index
17+
%idx2 = arith.constant 2 : index
18+
%idx3 = arith.constant 3 : index
19+
%idx4 = arith.constant 4 : index
20+
21+
%src = arith.constant dense<[0, 0, 0, 0]> : vector<4xi32>
22+
23+
%val0 = memref.load %arg0[%idx0] : memref<4xi32>
24+
%val1 = memref.load %arg0[%idx1] : memref<4xi32>
25+
%val2 = memref.load %arg0[%idx2] : memref<4xi32>
26+
%val3 = memref.load %arg0[%idx3] : memref<4xi32>
27+
28+
%src0 = vector.insert %val0, %src[%idx0] : i32 into vector<4xi32>
29+
%src1 = vector.insert %val1, %src0[%idx1] : i32 into vector<4xi32>
30+
%src2 = vector.insert %val2, %src1[%idx2] : i32 into vector<4xi32>
31+
%src3 = vector.insert %val3, %src2[%idx3] : i32 into vector<4xi32>
32+
33+
%res0, %res1 = vector.deinterleave %src3 : vector<4xi32> -> vector<2xi32>
34+
35+
%res0_0 = vector.extract %res0[%idx0] : i32 from vector<2xi32>
36+
%res0_1 = vector.extract %res0[%idx1] : i32 from vector<2xi32>
37+
%res1_0 = vector.extract %res1[%idx0] : i32 from vector<2xi32>
38+
%res1_1 = vector.extract %res1[%idx1] : i32 from vector<2xi32>
39+
40+
memref.store %res0_0, %arg1[%idx0]: memref<2xi32>
41+
memref.store %res0_1, %arg1[%idx1]: memref<2xi32>
42+
memref.store %res1_0, %arg2[%idx0]: memref<2xi32>
43+
memref.store %res1_1, %arg2[%idx1]: memref<2xi32>
44+
45+
gpu.return
46+
}
47+
}
48+
49+
func.func @main() {
50+
// Allocate 3 buffers.
51+
%buf0 = memref.alloc() : memref<4xi32>
52+
%buf1 = memref.alloc() : memref<2xi32>
53+
%buf2 = memref.alloc() : memref<2xi32>
54+
55+
%idx0 = arith.constant 0 : index
56+
%idx1 = arith.constant 1 : index
57+
%idx4 = arith.constant 4 : index
58+
59+
// Initialize input buffer.
60+
%buf0_vals = arith.constant dense<[0, 1, 2, 3]> : vector<4xi32>
61+
vector.store %buf0_vals, %buf0[%idx0] : memref<4xi32>, vector<4xi32>
62+
63+
// Initialize output buffers.
64+
%value0 = arith.constant 0 : i32
65+
%buf3 = memref.cast %buf1 : memref<2xi32> to memref<?xi32>
66+
%buf4 = memref.cast %buf2 : memref<2xi32> to memref<?xi32>
67+
call @fillResource1DInt(%buf3, %value0) : (memref<?xi32>, i32) -> ()
68+
call @fillResource1DInt(%buf4, %value0) : (memref<?xi32>, i32) -> ()
69+
70+
gpu.launch_func @kernels::@kernel_vector_deinterleave
71+
blocks in (%idx4, %idx1, %idx1) threads in (%idx1, %idx1, %idx1)
72+
args(%buf0 : memref<4xi32>, %buf1 : memref<2xi32>, %buf2 : memref<2xi32>)
73+
%buf5 = memref.cast %buf3 : memref<?xi32> to memref<*xi32>
74+
%buf6 = memref.cast %buf4 : memref<?xi32> to memref<*xi32>
75+
call @printMemrefI32(%buf5) : (memref<*xi32>) -> ()
76+
call @printMemrefI32(%buf6) : (memref<*xi32>) -> ()
77+
return
78+
}
79+
func.func private @fillResource1DInt(%0 : memref<?xi32>, %1 : i32)
80+
func.func private @printMemrefI32(%ptr : memref<*xi32>)
81+
}

0 commit comments

Comments
 (0)