1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
|
// RUN: mlir-opt %s -convert-vector-to-scf -convert-scf-to-cf -convert-vector-to-llvm -finalize-memref-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 @transfer_write16_inbounds_1d(%A : memref<?xf32>, %base: index) {
%f = arith.constant 16.0 : f32
%v = vector.splat %f : vector<16xf32>
vector.transfer_write %v, %A[%base]
{permutation_map = affine_map<(d0) -> (d0)>, in_bounds = [true]}
: vector<16xf32>, memref<?xf32>
return
}
func.func @transfer_write13_1d(%A : memref<?xf32>, %base: index) {
%f = arith.constant 13.0 : f32
%v = vector.splat %f : vector<13xf32>
vector.transfer_write %v, %A[%base]
{permutation_map = affine_map<(d0) -> (d0)>}
: vector<13xf32>, memref<?xf32>
return
}
func.func @transfer_write17_1d(%A : memref<?xf32>, %base: index) {
%f = arith.constant 17.0 : f32
%v = vector.splat %f : vector<17xf32>
vector.transfer_write %v, %A[%base]
{permutation_map = affine_map<(d0) -> (d0)>}
: vector<17xf32>, memref<?xf32>
return
}
func.func @transfer_read_1d(%A : memref<?xf32>) -> vector<32xf32> {
%z = arith.constant 0: index
%f = arith.constant 0.0: f32
%r = vector.transfer_read %A[%z], %f
{permutation_map = affine_map<(d0) -> (d0)>}
: memref<?xf32>, vector<32xf32>
return %r : vector<32xf32>
}
func.func @transfer_write_inbounds_3d(%A : memref<4x4x4xf32>) {
%c0 = arith.constant 0: index
%f = arith.constant 0.0 : f32
%v0 = vector.splat %f : vector<2x3x4xf32>
%f1 = arith.constant 1.0 : f32
%f2 = arith.constant 2.0 : f32
%f3 = arith.constant 3.0 : f32
%f4 = arith.constant 4.0 : f32
%f5 = arith.constant 5.0 : f32
%f6 = arith.constant 6.0 : f32
%f7 = arith.constant 7.0 : f32
%f8 = arith.constant 8.0 : f32
%v1 = vector.insert %f1, %v0[0, 0, 0] : f32 into vector<2x3x4xf32>
%v2 = vector.insert %f2, %v1[0, 0, 3] : f32 into vector<2x3x4xf32>
%v3 = vector.insert %f3, %v2[0, 2, 0] : f32 into vector<2x3x4xf32>
%v4 = vector.insert %f4, %v3[0, 2, 3] : f32 into vector<2x3x4xf32>
%v5 = vector.insert %f5, %v4[1, 0, 0] : f32 into vector<2x3x4xf32>
%v6 = vector.insert %f6, %v5[1, 0, 3] : f32 into vector<2x3x4xf32>
%v7 = vector.insert %f7, %v6[1, 2, 0] : f32 into vector<2x3x4xf32>
%v8 = vector.insert %f8, %v7[1, 2, 3] : f32 into vector<2x3x4xf32>
vector.transfer_write %v8, %A[%c0, %c0, %c0]
{permutation_map = affine_map<(d0, d1, d2) -> (d2, d0, d1)>,
in_bounds = [true, true, true]}
: vector<2x3x4xf32>, memref<4x4x4xf32>
return
}
func.func @entry() {
%c0 = arith.constant 0: index
%c1 = arith.constant 1: index
%c32 = arith.constant 32: index
%A = memref.alloc(%c32) {alignment=64} : memref<?xf32>
scf.for %i = %c0 to %c32 step %c1 {
%f = arith.constant 0.0: f32
memref.store %f, %A[%i] : memref<?xf32>
}
// On input, memory contains all zeros.
%0 = call @transfer_read_1d(%A) : (memref<?xf32>) -> (vector<32xf32>)
vector.print %0 : vector<32xf32>
// Overwrite with 16 values of 16 at base 3.
// Statically guaranteed to be in-bounds. Exercises proper alignment.
%c3 = arith.constant 3: index
call @transfer_write16_inbounds_1d(%A, %c3) : (memref<?xf32>, index) -> ()
%1 = call @transfer_read_1d(%A) : (memref<?xf32>) -> (vector<32xf32>)
vector.print %1 : vector<32xf32>
// Overwrite with 13 values of 13 at base 3.
call @transfer_write13_1d(%A, %c3) : (memref<?xf32>, index) -> ()
%2 = call @transfer_read_1d(%A) : (memref<?xf32>) -> (vector<32xf32>)
vector.print %2 : vector<32xf32>
// Overwrite with 17 values of 17 at base 7.
%c7 = arith.constant 7: index
call @transfer_write17_1d(%A, %c3) : (memref<?xf32>, index) -> ()
%3 = call @transfer_read_1d(%A) : (memref<?xf32>) -> (vector<32xf32>)
vector.print %3 : vector<32xf32>
// Overwrite with 13 values of 13 at base 8.
%c8 = arith.constant 8: index
call @transfer_write13_1d(%A, %c8) : (memref<?xf32>, index) -> ()
%4 = call @transfer_read_1d(%A) : (memref<?xf32>) -> (vector<32xf32>)
vector.print %4 : vector<32xf32>
// Overwrite with 17 values of 17 at base 14.
%c14 = arith.constant 14: index
call @transfer_write17_1d(%A, %c14) : (memref<?xf32>, index) -> ()
%5 = call @transfer_read_1d(%A) : (memref<?xf32>) -> (vector<32xf32>)
vector.print %5 : vector<32xf32>
// Overwrite with 13 values of 13 at base 19.
%c19 = arith.constant 19: index
call @transfer_write13_1d(%A, %c19) : (memref<?xf32>, index) -> ()
%6 = call @transfer_read_1d(%A) : (memref<?xf32>) -> (vector<32xf32>)
vector.print %6 : vector<32xf32>
memref.dealloc %A : memref<?xf32>
// 3D case
%c4 = arith.constant 4: index
%A1 = memref.alloc() {alignment=64} : memref<4x4x4xf32>
scf.for %i = %c0 to %c4 step %c1 {
scf.for %j = %c0 to %c4 step %c1 {
scf.for %k = %c0 to %c4 step %c1 {
%f = arith.constant 0.0: f32
memref.store %f, %A1[%i, %j, %k] : memref<4x4x4xf32>
}
}
}
call @transfer_write_inbounds_3d(%A1) : (memref<4x4x4xf32>) -> ()
%f = arith.constant 0.0: f32
%r = vector.transfer_read %A1[%c0, %c0, %c0], %f
: memref<4x4x4xf32>, vector<4x4x4xf32>
vector.print %r : vector<4x4x4xf32>
memref.dealloc %A1 : memref<4x4x4xf32>
return
}
// CHECK: ( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 )
// CHECK: ( 0, 0, 0, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 )
// CHECK: ( 0, 0, 0, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 16, 16, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 )
// CHECK: ( 0, 0, 0, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 )
// CHECK: ( 0, 0, 0, 17, 17, 17, 17, 17, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 )
// CHECK: ( 0, 0, 0, 17, 17, 17, 17, 17, 13, 13, 13, 13, 13, 13, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 0 )
// CHECK: ( 0, 0, 0, 17, 17, 17, 17, 17, 13, 13, 13, 13, 13, 13, 17, 17, 17, 17, 17, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13 )
// 3D case.
// CHECK: ( ( ( 1, 5, 0, 0 ), ( 0, 0, 0, 0 ), ( 0, 0, 0, 0 ), ( 2, 6, 0, 0 ) ), ( ( 0, 0, 0, 0 ), ( 0, 0, 0, 0 ), ( 0, 0, 0, 0 ), ( 0, 0, 0, 0 ) ),
// CHECK-SAME: ( ( 3, 7, 0, 0 ), ( 0, 0, 0, 0 ), ( 0, 0, 0, 0 ), ( 4, 8, 0, 0 ) ), ( ( 0, 0, 0, 0 ), ( 0, 0, 0, 0 ), ( 0, 0, 0, 0 ), ( 0, 0, 0, 0 ) ) )
|