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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
|
// RUN: mlir-opt --canonicalize %s | FileCheck %s
shard.grid @grid0(shape = 2x4)
// CHECK-LABEL: func @all_reduce_empty_grid_axes
func.func @all_reduce_empty_grid_axes(
// CHECK-SAME: %[[ARG:.*]]: tensor<4xf32>
%arg0 : tensor<4xf32>) -> tensor<4xf32> {
// CHECK-NOT: shard.all_reduce
%0 = shard.all_reduce %arg0 on @grid0
grid_axes = []
: tensor<4xf32> -> tensor<4xf32>
// CHECK: return %[[ARG]]
return %0 : tensor<4xf32>
}
// CHECK-LABEL: func @all_reduce_empty_grid_axes_different_return_type
func.func @all_reduce_empty_grid_axes_different_return_type(
%arg0 : tensor<4xf32>) -> tensor<4xf64> {
// CHECK: shard.all_reduce
%0 = shard.all_reduce %arg0 on @grid0
// CHECK-NOT: grid_axes
grid_axes = []
: tensor<4xf32> -> tensor<4xf64>
return %0 : tensor<4xf64>
}
// CHECK-LABEL: func @all_reduce_default_reduction
func.func @all_reduce_default_reduction(
%arg0 : tensor<4xf32>) -> tensor<4xf64> {
%0 = shard.all_reduce %arg0 on @grid0
grid_axes = [0]
// CHECK-NOT: reduction
reduction = sum
: tensor<4xf32> -> tensor<4xf64>
return %0 : tensor<4xf64>
}
// CHECK-LABEL: func @all_to_all_empty_grid_axes
func.func @all_to_all_empty_grid_axes(
// CHECK-SAME: %[[ARG:.*]]: tensor<8xf32>
%arg0 : tensor<8xf32>) -> tensor<8xf32> {
// CHECK-NOT: shard.all_to_all
%0 = shard.all_to_all %arg0 on @grid0
grid_axes = []
split_axis = 0
concat_axis = 0
: tensor<8xf32> -> tensor<8xf32>
// CHECK: return %[[ARG]]
return %0 : tensor<8xf32>
}
// CHECK-LABEL: func @all_gather_empty_grid_axes
func.func @all_gather_empty_grid_axes(
// CHECK-SAME: %[[ARG:.*]]: tensor<4xf32>
%arg0 : tensor<4xf32>) -> tensor<4xf32> {
// CHECK-NOT: shard.all_gather
%0 = shard.all_gather %arg0 on @grid0
grid_axes = []
gather_axis = 0
: tensor<4xf32> -> tensor<4xf32>
// CHECK: return %[[ARG]]
return %0 : tensor<4xf32>
}
// CHECK-LABEL: func @all_slice_empty_grid_axes
func.func @all_slice_empty_grid_axes(
// CHECK-SAME: %[[ARG:.*]]: tensor<4xf32>
%arg0 : tensor<4xf32>) -> tensor<4xf32> {
// CHECK-NOT: shard.scatter
%0 = shard.all_slice %arg0 on @grid0
grid_axes = []
slice_axis = 0
: tensor<4xf32> -> tensor<4xf32>
// CHECK: return %[[ARG]]
return %0 : tensor<4xf32>
}
// CHECK-LABEL: func @broadcast_empty_grid_axes
func.func @broadcast_empty_grid_axes(
// CHECK-SAME: %[[ARG:.*]]: tensor<4xf32>
%arg0 : tensor<4xf32>) -> tensor<4xf32> {
// CHECK-NOT: shard.broadcast
%0 = shard.broadcast %arg0 on @grid0
grid_axes = []
root = []
: (tensor<4xf32>) -> tensor<4xf32>
// CHECK: return %[[ARG]]
return %0 : tensor<4xf32>
}
// CHECK-LABEL: func @gather_empty_grid_axes
func.func @gather_empty_grid_axes(
// CHECK-SAME: %[[ARG:.*]]: tensor<4xf32>
%arg0 : tensor<4xf32>) -> tensor<4xf32> {
// CHECK-NOT: shard.gather
%0 = shard.gather %arg0 on @grid0
grid_axes = []
gather_axis = 0
root = []
: (tensor<4xf32>) -> tensor<4xf32>
// CHECK: return %[[ARG]]
return %0 : tensor<4xf32>
}
// CHECK-LABEL: func @receive_empty_grid_axes
func.func @receive_empty_grid_axes(
// CHECK-SAME: %[[ARG:.*]]: tensor<4xf32>
%arg0 : tensor<4xf32>) -> tensor<4xf32> {
// CHECK-NOT: shard.recv
%0 = shard.recv %arg0 on @grid0
grid_axes = []
: (tensor<4xf32>) -> tensor<4xf32>
// CHECK: return %[[ARG]]
return %0 : tensor<4xf32>
}
// CHECK-LABEL: func @reduce_empty_grid_axes
func.func @reduce_empty_grid_axes(
// CHECK-SAME: %[[ARG:.*]]: tensor<4xf32>
%arg0 : tensor<4xf32>) -> tensor<4xf32> {
// CHECK-NOT: shard.reduce
%0 = shard.reduce %arg0 on @grid0
grid_axes = []
root = []
: (tensor<4xf32>) -> tensor<4xf32>
// CHECK: return %[[ARG]]
return %0 : tensor<4xf32>
}
// CHECK-LABEL: func @reduce_scatter_empty_grid_axes
func.func @reduce_scatter_empty_grid_axes(
// CHECK-SAME: %[[ARG:.*]]: tensor<4xf32>
%arg0 : tensor<4xf32>) -> tensor<4xf32> {
// CHECK-NOT: shard.reduce_scatter
%0 = shard.reduce_scatter %arg0 on @grid0
grid_axes = []
scatter_axis = 0
: tensor<4xf32> -> tensor<4xf32>
// CHECK: return %[[ARG]]
return %0 : tensor<4xf32>
}
// CHECK-LABEL: func @reduce_scatter_empty_grid_axes_different_return_type
func.func @reduce_scatter_empty_grid_axes_different_return_type(
%arg0 : tensor<4xf32>) -> tensor<4xf64> {
// CHECK: shard.reduce_scatter
%0 = shard.reduce_scatter %arg0 on @grid0
// CHECK-NOT: grid_axes
grid_axes = []
scatter_axis = 0
: tensor<4xf32> -> tensor<4xf64>
return %0 : tensor<4xf64>
}
// CHECK-LABEL: func @reduce_scatter_default_reduction
func.func @reduce_scatter_default_reduction(
%arg0 : tensor<4xf32>) -> tensor<2xf64> {
%0 = shard.reduce_scatter %arg0 on @grid0
grid_axes = [0]
// CHECK-NOT: reduction
reduction = sum
scatter_axis = 0
: tensor<4xf32> -> tensor<2xf64>
return %0 : tensor<2xf64>
}
// CHECK-LABEL: func @scatter_empty_grid_axes
func.func @scatter_empty_grid_axes(
// CHECK-SAME: %[[ARG:.*]]: tensor<4xf32>
%arg0 : tensor<4xf32>) -> tensor<4xf32> {
// CHECK-NOT: shard.scatter
%0 = shard.scatter %arg0 on @grid0
grid_axes = []
scatter_axis = 0
root = []
: (tensor<4xf32>) -> tensor<4xf32>
// CHECK: return %[[ARG]]
return %0 : tensor<4xf32>
}
// CHECK-LABEL: func @send_empty_grid_axes
func.func @send_empty_grid_axes(
// CHECK-SAME: %[[ARG:.*]]: tensor<4xf32>
%arg0 : tensor<4xf32>) -> tensor<4xf32> {
// CHECK-NOT: shard.send
%0 = shard.send %arg0 on @grid0
grid_axes = []
destination = []
: (tensor<4xf32>) -> tensor<4xf32>
// CHECK: return %[[ARG]]
return %0 : tensor<4xf32>
}
shard.grid @grid4x4(shape = 4x4)
// CHECK-LABEL: func @test_halo_sizes
func.func @test_halo_sizes() -> !shard.sharding {
%c2_i64 = arith.constant 2 : i64
// CHECK shard.sharding @grid4x4 split_axes = [[0], [1]] halo_sizes = [1, 2, 2, 22] : !shard.sharding
%sharding = shard.sharding @grid4x4 split_axes = [[0], [1]] halo_sizes = [1, %c2_i64, %c2_i64, 22] : !shard.sharding
return %sharding : !shard.sharding
}
// CHECK-LABEL: func @test_shard_offs
func.func @test_shard_offs() -> !shard.sharding {
%c2_i64 = arith.constant 2 : i64
// CHECK shard.sharding @grid4x4 split_axes = [[0], [1]] sharded_dims_offsets = [0, 1, 2, 3, 4, 0, 2, 3, 4, 22] : !shard.sharding
%sharding = shard.sharding @grid4x4 split_axes = [[0], [1]] sharded_dims_offsets = [0, 1, %c2_i64, 3, 4, 0, %c2_i64, 3, 4, 22] : !shard.sharding
return %sharding : !shard.sharding
}
// CHECK-LABEL: func @test_duplicate_shardops
func.func @test_duplicate_shardops() -> (tensor<1024x1024xf32>, tensor<1024x1024xf32>) attributes {llvm.emit_c_interface} {
// CHECK-NEXT: [[vcst:%.*]] = arith.constant dense<0.000000e+00> : tensor<1024x1024xf32>
%cst_1 = arith.constant dense<0.000000e+00> : tensor<1024x1024xf32>
// CHECK-NEXT: [[vsharding:%.*]] = shard.sharding @grid4x4 split_axes = {{\[\[}}0, 1]] : !shard.sharding
%sharding_1 = shard.sharding @grid4x4 split_axes = [[0, 1]] : !shard.sharding
%cst_2 = arith.constant dense<0.000000e+00> : tensor<1024x1024xf32>
%sharding_2 = shard.sharding @grid4x4 split_axes = [[0, 1]] : !shard.sharding
%sharded_2 = shard.shard %cst_2 to %sharding_2 : tensor<1024x1024xf32>
%cst_3 = arith.constant dense<0.000000e+00> : tensor<1024x1024xf32>
%sharding_3 = shard.sharding @grid4x4 split_axes = [[0, 1]] : !shard.sharding
%sharded_3 = shard.shard %cst_3 to %sharding_3 : tensor<1024x1024xf32>
// CHECK-NEXT: [[vsharded:%.*]] = shard.shard [[vcst]] to [[vsharding]] : tensor<1024x1024xf32>
%sharded_1 = shard.shard %cst_1 to %sharding_1 : tensor<1024x1024xf32>
// CHECK-NEXT: return [[vsharded]], [[vsharded]] : tensor<1024x1024xf32>, tensor<1024x1024xf32>
return %sharded_1, %sharded_2 : tensor<1024x1024xf32>, tensor<1024x1024xf32>
}
// CHECK-LABEL: func @test_duplicate_shardops_diff
func.func @test_duplicate_shardops_diff() -> (tensor<1024x1024xf32>, tensor<1024x1024xf32>) attributes {llvm.emit_c_interface} {
// CHECK-NEXT: [[vcst:%.*]] = arith.constant dense<0.000000e+00> : tensor<1024x1024xf32>
%cst_1 = arith.constant dense<0.000000e+00> : tensor<1024x1024xf32>
// CHECK-NEXT: [[vsharding:%.*]] = shard.sharding @grid4x4 split_axes = {{\[\[}}0]] : !shard.sharding
%sharding_1 = shard.sharding @grid4x4 split_axes = [[0]] : !shard.sharding
%cst_2 = arith.constant dense<0.000000e+00> : tensor<1024x1024xf32>
// CHECK-NEXT: [[vsharding_0:%.*]] = shard.sharding @grid4x4 split_axes = {{\[\[}}0, 1]] : !shard.sharding
%sharding_2 = shard.sharding @grid4x4 split_axes = [[0, 1]] : !shard.sharding
// CHECK-NEXT: [[vsharded:%.*]] = shard.shard [[vcst]] to [[vsharding_0]] : tensor<1024x1024xf32>
%sharded_2 = shard.shard %cst_2 to %sharding_2 : tensor<1024x1024xf32>
%cst_3 = arith.constant dense<0.000000e+00> : tensor<1024x1024xf32>
%sharding_3 = shard.sharding @grid4x4 split_axes = [[0]] : !shard.sharding
%sharded_3 = shard.shard %cst_3 to %sharding_3 : tensor<1024x1024xf32>
// CHECK-NEXT: [[vsharded_1:%.*]] = shard.shard [[vsharded]] to [[vsharding]] : tensor<1024x1024xf32>
%sharded_1 = shard.shard %cst_1 to %sharding_1 : tensor<1024x1024xf32>
// CHECK-NEXT: return [[vsharded_1]], [[vsharded]] : tensor<1024x1024xf32>, tensor<1024x1024xf32>
return %sharded_1, %sharded_2 : tensor<1024x1024xf32>, tensor<1024x1024xf32>
}
|