Skip to content

Commit b44ebdc

Browse files
author
Krzysztof Parzyszek
committed
Format updated files
1 parent 9472d8b commit b44ebdc

File tree

12 files changed

+61
-168
lines changed

12 files changed

+61
-168
lines changed

python/tvm/topi/arm_cpu/conv2d.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,7 @@
3333
schedule_conv2d_spatial_pack_nchw,
3434
schedule_conv2d_spatial_pack_nhwc,
3535
)
36-
from .mprofile.dsp.conv2d import (
37-
conv2d_nhwc_dsp_compute,
38-
conv2d_nhwc_dsp_schedule,
39-
)
36+
from .mprofile.dsp.conv2d import conv2d_nhwc_dsp_compute, conv2d_nhwc_dsp_schedule
4037

4138

4239
@autotvm.register_topi_compute("conv2d_nchw_spatial_pack.arm_cpu")
@@ -267,13 +264,7 @@ def _schedule_winograd(cfg, s, output, last):
267264
if isinstance(U.op, tvm.te.ComputeOp):
268265
kernel, G = U.op.input_tensors
269266
s[G].compute_inline()
270-
(
271-
eps,
272-
nu,
273-
k,
274-
c,
275-
kk,
276-
) = s[U].op.axis
267+
(eps, nu, k, c, kk) = s[U].op.axis
277268
if autotvm.GLOBAL_SCOPE.in_tuning:
278269
# kernel transformation will be pre-computed during compilation, so we skip
279270
# this part to make tuning records correct

python/tvm/topi/arm_cpu/conv2d_alter_op.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,7 @@ def _alter_conv2d_layout(attrs, inputs, tinfos, out_type):
152152
)
153153
dispatch_ctx.update(target, new_workload, cfg)
154154
return relay.nn.conv2d(
155-
inputs[0],
156-
relay.Constant(tvm.nd.array(reshaped_new_kernel)),
157-
**new_attrs,
155+
inputs[0], relay.Constant(tvm.nd.array(reshaped_new_kernel)), **new_attrs
158156
)
159157

160158
# Only microTVM does layout alteration for NHWC layout with real data types

python/tvm/topi/cuda/dense.py

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,7 @@
2929

3030

3131
def _matmul_cublas_common(
32-
cfg,
33-
tensor_a,
34-
tensor_b,
35-
bias=None,
36-
out_dtype=None,
37-
transpose_a=False,
38-
transpose_b=False,
32+
cfg, tensor_a, tensor_b, bias=None, out_dtype=None, transpose_a=False, transpose_b=False
3933
):
4034
assert len(tensor_a.shape) == 2 and len(tensor_b.shape) == 2, "only support 2-dim matmul"
4135
if bias is not None:
@@ -58,13 +52,7 @@ def _matmul_cublas_common(
5852

5953
@autotvm.register_topi_compute("matmul_cublas.cuda")
6054
def matmul_cublas(
61-
cfg,
62-
tensor_a,
63-
tensor_b,
64-
bias=None,
65-
out_dtype=None,
66-
transpose_a=False,
67-
transpose_b=False,
55+
cfg, tensor_a, tensor_b, bias=None, out_dtype=None, transpose_a=False, transpose_b=False
6856
):
6957
"""Matmul operator on CUDA with CUBLAS"""
7058
return _matmul_cublas_common(cfg, tensor_a, tensor_b, bias, out_dtype, transpose_a, transpose_b)

python/tvm/topi/cuda/sparse.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,10 @@ def gen_ir(data, w_data, w_indices, w_indptr, out):
159159
bs_m = bs_n
160160
mb = m // bs_m
161161
mi = warp_size
162-
assert (
163-
mb >= mi
164-
), f"Number of block rows in dense matrix must be larger than warp size: {warp_size} vs {mb}."
162+
assert mb >= mi, (
163+
f"Number of block rows in dense matrix must be larger than warp size: "
164+
f"{warp_size} vs {mb}."
165+
)
165166
mo = ceil_div(mb, mi)
166167
ni = 1 # TODO(tkonolige): how do I compute the number of warps per block?
167168
no = ceil_div(nb, ni)

python/tvm/topi/generic/conv2d.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,12 @@ def fallback_schedule_cpu_common_int8(cfg, wkl, int32_lanes, num_int8_elements):
4545
dilated_kernel_w = (wkl.kernel_w - 1) * wkl.dilation_w + 1
4646
out_width = (wkl.width + pl + pr - dilated_kernel_w) // WSTR + 1
4747

48-
assert wkl.out_filter % int32_lanes == 0, f"wkl.out_filter={wkl.out_filter}, int32_lanes={int32_lanes}"
49-
assert wkl.in_filter % num_int8_elements == 0, f"wkl.in_filter={wkl.in_filter}, num_int8_elements={num_int8_elements}"
48+
assert (
49+
wkl.out_filter % int32_lanes == 0
50+
), f"wkl.out_filter={wkl.out_filter}, int32_lanes={int32_lanes}"
51+
assert (
52+
wkl.in_filter % num_int8_elements == 0
53+
), f"wkl.in_filter={wkl.in_filter}, num_int8_elements={num_int8_elements}"
5054

5155
oc_bn = int32_lanes if int32_lanes >= num_int8_elements else num_int8_elements
5256
ic_bn = 1
@@ -87,8 +91,12 @@ def fallback_schedule_cpu_1x1_int8(cfg, wkl, int32_lanes, num_int8_elements):
8791
out_height = (wkl.height + pt + pb - wkl.kernel_h) // HSTR + 1
8892
out_width = (wkl.width + pl + pr - wkl.kernel_w) // WSTR + 1
8993

90-
assert wkl.out_filter % int32_lanes == 0, f"wkl.out_filter={wkl.out_filter}, int32_lanes={int32_lanes}"
91-
assert wkl.in_filter % num_int8_elements == 0, f"wkl.in_filter={wkl.in_filter}, num_int8_elements={num_int8_elements}"
94+
assert (
95+
wkl.out_filter % int32_lanes == 0
96+
), f"wkl.out_filter={wkl.out_filter}, int32_lanes={int32_lanes}"
97+
assert (
98+
wkl.in_filter % num_int8_elements == 0
99+
), f"wkl.in_filter={wkl.in_filter}, num_int8_elements={num_int8_elements}"
92100

93101
oc_bn = int32_lanes if int32_lanes >= num_int8_elements else num_int8_elements
94102
ic_bn = 1

python/tvm/topi/image/resize.py

Lines changed: 4 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -314,14 +314,7 @@ def _cast_output(value, data_dtype="float32", out_dtype=None):
314314
if boxes is not None:
315315
# TODO(mbrookhart): Find an example of this
316316
raise NotImplementedError("resize1d with image boxes not yet implemented")
317-
in_x = get_inx(
318-
x,
319-
image_width,
320-
target_width,
321-
coordinate_transformation_mode,
322-
roi[0],
323-
roi[1],
324-
)
317+
in_x = get_inx(x, image_width, target_width, coordinate_transformation_mode, roi[0], roi[1])
325318

326319
if method == "nearest_neighbor":
327320
if rounding_method == "":
@@ -332,35 +325,15 @@ def _cast_output(value, data_dtype="float32", out_dtype=None):
332325

333326
closest_x_index = get_closest_index(in_x, rounding_method, boxes)
334327

335-
value = get_1d_pixel(
336-
data,
337-
layout,
338-
image_width,
339-
box_idx,
340-
c,
341-
closest_x_index,
342-
cc,
343-
inum,
344-
ic,
345-
)
328+
value = get_1d_pixel(data, layout, image_width, box_idx, c, closest_x_index, cc, inum, ic)
346329
elif method == "linear":
347330
x_int = te.floor(in_x).astype("int32")
348331

349332
x_lerp = in_x - x_int
350333

351334
p = [0 for i in range(2)]
352335
for i in range(2):
353-
p[i] = get_1d_pixel(
354-
data,
355-
layout,
356-
image_width,
357-
box_idx,
358-
c,
359-
x_int + i,
360-
cc,
361-
inum,
362-
ic,
363-
)
336+
p[i] = get_1d_pixel(data, layout, image_width, box_idx, c, x_int + i, cc, inum, ic)
364337

365338
value = _lerp(*p, x_lerp)
366339

@@ -371,17 +344,7 @@ def _cast_output(value, data_dtype="float32", out_dtype=None):
371344
# Get the surrounding values
372345
p = [0 for i in range(4)]
373346
for i in range(4):
374-
p[i] = get_1d_pixel(
375-
data,
376-
layout,
377-
image_width,
378-
box_idx,
379-
c,
380-
xint + i - 1,
381-
cc,
382-
inum,
383-
ic,
384-
)
347+
p[i] = get_1d_pixel(data, layout, image_width, box_idx, c, xint + i - 1, cc, inum, ic)
385348

386349
wx = _cubic_spline_weights(xfract, alpha)
387350
if exclude_outside:

python/tvm/topi/nn/conv2d.py

Lines changed: 15 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1224,8 +1224,7 @@ def _conv2d_winograd_nhwc_impl(
12241224
kernel_pack = te.compute(
12251225
(alpha, alpha, CO, CI),
12261226
lambda eps, nu, co, ci: te.sum(
1227-
weight[r_kh, r_kw, ci, co] * G[eps, r_kh] * G[nu, r_kw],
1228-
axis=[r_kh, r_kw],
1227+
weight[r_kh, r_kw, ci, co] * G[eps, r_kh] * G[nu, r_kw], axis=[r_kh, r_kw]
12291228
),
12301229
name="kernel_pack",
12311230
)
@@ -1243,10 +1242,7 @@ def _conv2d_winograd_nhwc_impl(
12431242
input_tile = te.compute(
12441243
(alpha, alpha, P, CI),
12451244
lambda eps, nu, p, ci: data_pad[
1246-
p // (nH * nW),
1247-
((p // nW) % nH) * m + eps,
1248-
(p % nW) * m + nu,
1249-
ci,
1245+
p // (nH * nW), ((p // nW) % nH) * m + eps, (p % nW) * m + nu, ci
12501246
],
12511247
name="input_tile",
12521248
attrs={"schedule_rule": "None"},
@@ -1258,8 +1254,7 @@ def _conv2d_winograd_nhwc_impl(
12581254
data_pack = te.compute(
12591255
(alpha, alpha, P, CI),
12601256
lambda eps, nu, p, ci: te.sum(
1261-
input_tile[r_a, r_b, p, ci] * B[r_a, eps] * B[r_b, nu],
1262-
axis=[r_a, r_b],
1257+
input_tile[r_a, r_b, p, ci] * B[r_a, eps] * B[r_b, nu], axis=[r_a, r_b]
12631258
),
12641259
name="data_pack",
12651260
attrs={
@@ -1273,8 +1268,7 @@ def _conv2d_winograd_nhwc_impl(
12731268
bgemm = te.compute(
12741269
(alpha, alpha, P, CO),
12751270
lambda eps, nu, p, co: te.sum(
1276-
data_pack[eps, nu, p, ci] * kernel_pack[eps, nu, co, ci],
1277-
axis=[ci],
1271+
data_pack[eps, nu, p, ci] * kernel_pack[eps, nu, co, ci], axis=[ci]
12781272
),
12791273
name="bgemm",
12801274
attrs=bgemm_attrs,
@@ -1290,8 +1284,7 @@ def _conv2d_winograd_nhwc_impl(
12901284
inverse = te.compute(
12911285
(m, m, P, CO),
12921286
lambda vh, vw, p, co: te.sum(
1293-
bgemm[r_a, r_b, p, co] * A[r_a, vh] * A[r_b, vw],
1294-
axis=[r_a, r_b],
1287+
bgemm[r_a, r_b, p, co] * A[r_a, vh] * A[r_b, vw], axis=[r_a, r_b]
12951288
),
12961289
name="inverse",
12971290
attrs={
@@ -1303,12 +1296,7 @@ def _conv2d_winograd_nhwc_impl(
13031296
# output
13041297
output = te.compute(
13051298
(N, H, W, CO),
1306-
lambda n, h, w, co: inverse[
1307-
h % m,
1308-
w % m,
1309-
n * nH * nW + (h // m) * nW + (w // m),
1310-
co,
1311-
],
1299+
lambda n, h, w, co: inverse[h % m, w % m, n * nH * nW + (h // m) * nW + (w // m), co],
13121300
name="conv2d_winograd",
13131301
)
13141302

@@ -1358,12 +1346,7 @@ def _conv2d_winograd_nchw_impl(
13581346
assert HSTR == 1 and WSTR == 1 and KH == 3 and KW == 3
13591347

13601348
pt, pl, pb, pr = get_pad_tuple(padding, (KH, KW))
1361-
data_pad = pad(
1362-
data,
1363-
(0, 0, pt, pl),
1364-
(0, 0, pb, pr),
1365-
name="data_pad",
1366-
)
1349+
data_pad = pad(data, (0, 0, pt, pl), (0, 0, pb, pr), name="data_pad")
13671350

13681351
r = KW
13691352
m = tile_size
@@ -1382,8 +1365,7 @@ def _conv2d_winograd_nchw_impl(
13821365
kernel_pack = te.compute(
13831366
(alpha, alpha, CI, CO),
13841367
lambda eps, nu, ci, co: te.sum(
1385-
weight[co, ci, r_kh, r_kw] * G[eps, r_kh] * G[nu, r_kw],
1386-
axis=[r_kh, r_kw],
1368+
weight[co, ci, r_kh, r_kw] * G[eps, r_kh] * G[nu, r_kw], axis=[r_kh, r_kw]
13871369
),
13881370
name="kernel_pack",
13891371
)
@@ -1401,10 +1383,7 @@ def _conv2d_winograd_nchw_impl(
14011383
input_tile = te.compute(
14021384
(CI, P, alpha, alpha),
14031385
lambda ci, p, eps, nu: data_pad[
1404-
p // (nH * nW),
1405-
ci,
1406-
((p // nW) % nH) * m + eps,
1407-
(p % nW) * m + nu,
1386+
p // (nH * nW), ci, ((p // nW) % nH) * m + eps, (p % nW) * m + nu
14081387
],
14091388
name="input_tile",
14101389
attrs={"schedule_rule": "None"},
@@ -1416,22 +1395,18 @@ def _conv2d_winograd_nchw_impl(
14161395
data_pack = te.compute(
14171396
(alpha, alpha, CI, P),
14181397
lambda eps, nu, ci, p: te.sum(
1419-
input_tile[ci, p, r_a, r_b] * B[r_a, eps] * B[r_b, nu],
1420-
axis=[r_a, r_b],
1398+
input_tile[ci, p, r_a, r_b] * B[r_a, eps] * B[r_b, nu], axis=[r_a, r_b]
14211399
),
14221400
name="data_pack",
1423-
attrs={
1424-
"schedule_rule": "conv2d_nchw_winograd_data_pack",
1425-
},
1401+
attrs={"schedule_rule": "conv2d_nchw_winograd_data_pack"},
14261402
)
14271403

14281404
# do batch gemm
14291405
ci = te.reduce_axis((0, CI), name="ci")
14301406
bgemm = te.compute(
14311407
(alpha, alpha, CO, P),
14321408
lambda eps, nu, co, p: te.sum(
1433-
data_pack[eps, nu, ci, p] * kernel_pack[eps, nu, ci, co],
1434-
axis=[ci],
1409+
data_pack[eps, nu, ci, p] * kernel_pack[eps, nu, ci, co], axis=[ci]
14351410
),
14361411
name="bgemm",
14371412
attrs=bgemm_attrs,
@@ -1443,24 +1418,16 @@ def _conv2d_winograd_nchw_impl(
14431418
inverse = te.compute(
14441419
(CO, P, m, m),
14451420
lambda co, p, vh, vw: te.sum(
1446-
bgemm[r_a, r_b, co, p] * A[r_a, vh] * A[r_b, vw],
1447-
axis=[r_a, r_b],
1421+
bgemm[r_a, r_b, co, p] * A[r_a, vh] * A[r_b, vw], axis=[r_a, r_b]
14481422
),
14491423
name="inverse",
1450-
attrs={
1451-
"schedule_rule": "conv2d_nchw_winograd_inverse",
1452-
},
1424+
attrs={"schedule_rule": "conv2d_nchw_winograd_inverse"},
14531425
)
14541426

14551427
# output
14561428
output = te.compute(
14571429
(N, CO, H, W),
1458-
lambda n, co, h, w: inverse[
1459-
co,
1460-
n * nH * nW + (h // m) * nW + (w // m),
1461-
h % m,
1462-
w % m,
1463-
],
1430+
lambda n, co, h, w: inverse[co, n * nH * nW + (h // m) * nW + (w // m), h % m, w % m],
14641431
name="conv2d_winograd",
14651432
)
14661433

python/tvm/topi/nn/depthwise_conv2d.py

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -65,27 +65,24 @@ def _get_workload(data, kernel, stride, padding, dilation, out_dtype, data_layou
6565
elif data_layout == "NCHWc":
6666
_, in_channel_chunk, height, width, in_channel_block = get_const_tuple(data.shape)
6767
in_channel = in_channel_chunk * in_channel_block
68-
(
69-
filter_channel_chunk,
70-
cm_chunk,
71-
kh,
72-
kw,
73-
cm_block,
74-
filter_channel_block,
75-
) = get_const_tuple(kernel.shape)
68+
(filter_channel_chunk, cm_chunk, kh, kw, cm_block, filter_channel_block) = get_const_tuple(
69+
kernel.shape
70+
)
7671
filter_channel = filter_channel_chunk * filter_channel_block
7772
channel_multiplier = cm_chunk * cm_block
7873

79-
assert (
80-
in_channel_block == filter_channel_block
81-
), f"Incorrect dimensions, data has block size {in_channel_block}, but filter has block size {filter_channel_block}"
74+
assert in_channel_block == filter_channel_block, (
75+
f"Incorrect dimensions, data has block size {in_channel_block}, but filter has "
76+
f"block size {filter_channel_block}"
77+
)
8278

8379
else:
8480
raise ValueError(f"Data layout {data_layout} not supported")
8581

86-
assert (
87-
in_channel == filter_channel
88-
), f"Incorrect dimensions, data has {in_channel} channels but filter expects {filter_channel} channels"
82+
assert in_channel == filter_channel, (
83+
f"Incorrect dimensions, data has {in_channel} channels but filter expects "
84+
f"{filter_channel} channels"
85+
)
8986

9087
out_channel = filter_channel * channel_multiplier
9188
dilation_h, dilation_w = (

python/tvm/topi/nn/utils.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,10 @@ def get_pad_tuple_generic(padding, kernel):
194194
if len(padding) == len(kernel):
195195
pad_dimensions = [p * 2 for p in padding]
196196
elif len(padding) == len(kernel) * 2:
197-
return [padding[i] for i in range(len(kernel))], [
198-
padding[len(kernel) + i] for i in range(len(kernel))
199-
]
197+
return (
198+
[padding[i] for i in range(len(kernel))],
199+
[padding[len(kernel) + i] for i in range(len(kernel))],
200+
)
200201
else:
201202
raise ValueError("Size of padding can only be len(kernel) or len(kernel) * 2")
202203
elif isinstance(padding, int):

0 commit comments

Comments
 (0)