You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by "Anndrey24 (via GitHub)" <gi...@apache.org> on 2023/08/31 10:44:11 UTC
[GitHub] [tvm] Anndrey24 opened a new pull request, #15648: [Relay][TOPI] Remove input padding for arm_cpu conv2d int8 native schedule in Legalize pass
Anndrey24 opened a new pull request, #15648:
URL: https://github.com/apache/tvm/pull/15648
The Legalize pass was unnecessarily padding the input channels for conv2d int8 native implementations. Since the conv2d schedule itself can add padding more efficiently, I skipped padding during the pass and further optimised the schedule to deal with it.
For the int8 interleaved implementation, I kept the Legalize pass padding, which transforms the input channels into a multiple of 8, and modified the schedule to ensure vectorization of the input data.
I also added a test to check whether or not the Legalize pass pads the conv2d input data.
The benchmark results of a single int8 conv2d operation where input padding along the K axis is necessary, with input = (1 x 224 x 224 x 3), filter = (16 x 3 x 3 x 3), output = (1 x 112 x 112 x 16), tested for 3 different targets before and after the changes, is given below:
- generic = `"llvm --device=arm_cpu --mtriple=aarch64-linux-gnu -mattr=+v8.2a"` (interleaved)
- dotprod = `"llvm --device=arm_cpu --mtriple=aarch64-linux-gnu -mattr=+v8.2a,+dotprod"` (native)
- i8mm = `"llvm --device=arm_cpu --mtriple=aarch64-linux-gnu -mattr=+v8.2a,+i8mm"` (interleaved)
| Target | Before (ms) | After (ms) | Speedup (%) |
|---------|-------------|------------|-------------|
| generic | 0.13 | 0.1154 | 11.23 |
| dotprod | 0.5186 | 0.0663 | 87.22 |
| i8mm | 0.0982 | 0.0829 | 15.58 |
cc @ekalda @neildhickey @lhutton1 @leandron
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] Anndrey24 commented on pull request #15648: [Relay][TOPI] Remove input padding for arm_cpu conv2d int8 native schedule in Legalize pass
Posted by "Anndrey24 (via GitHub)" <gi...@apache.org>.
Anndrey24 commented on PR #15648:
URL: https://github.com/apache/tvm/pull/15648#issuecomment-1706406306
Regarding the tests, it seems that all of the padding cases are already visited at least once in: https://github.com/apache/tvm/blob/476d9d1d41980ad35cd6a4d044c17fea2210f352/tests/python/topi/python/test_topi_conv2d_int8.py#L110
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] Anndrey24 commented on a diff in pull request #15648: [Relay][TOPI] Remove input padding for arm_cpu conv2d int8 native schedule in Legalize pass
Posted by "Anndrey24 (via GitHub)" <gi...@apache.org>.
Anndrey24 commented on code in PR #15648:
URL: https://github.com/apache/tvm/pull/15648#discussion_r1315722536
##########
python/tvm/topi/arm_cpu/conv2d_gemm.py:
##########
@@ -326,7 +328,12 @@ def schedule_conv2d_gemm_interleaved(cfg, s, out, final_out):
b, m, n = data_im2col.op.axis
if data_im2col.op.name == "data_im2col":
- n_outer, n_inner = s[data_im2col].split(n, 16)
+ n_size = data_im2col.shape[2]
+ if n_size % 16 == 0:
+ split_factor = 16
+ else:
+ split_factor = 8
+ n_outer, n_inner = s[data_im2col].split(n, split_factor)
Review Comment:
That does make more sense. I'll split it out into a separate PR
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] lhutton1 commented on a diff in pull request #15648: [Relay][TOPI] Remove input padding for arm_cpu conv2d int8 native schedule in Legalize pass
Posted by "lhutton1 (via GitHub)" <gi...@apache.org>.
lhutton1 commented on code in PR #15648:
URL: https://github.com/apache/tvm/pull/15648#discussion_r1315667771
##########
python/tvm/topi/arm_cpu/conv2d_gemm.py:
##########
@@ -428,12 +435,29 @@ def schedule_conv2d_gemm_native(cfg, s, out, final_out):
b, m, n = data_im2col.op.axis
if data_im2col.op.name == "data_im2col":
- n_outer, n_inner = s[data_im2col].split(n, 16)
+ if A.op.name == "A_padded_K":
+ s[data_im2col].compute_at(s[A], A.op.axis[1])
+ s[A].parallel(A.op.axis[1])
+ elif A.op.name == "A_padded_M":
+ s[data_im2col].parallel(m)
+ s[A].parallel(A.op.axis[1])
+ else:
+ s[data_im2col].parallel(m)
+
+ split_factor = 16
+ n_size = data_im2col.shape[2]
+ if n_size % split_factor != 0:
+ # Split by kernel area (KH * KW) to ensure proper vectorization
+ ic = data_im2col.op.input_tensors[0].shape[3]
+ split_factor = n_size // ic
+
+ n_outer, n_inner = s[data_im2col].split(n, split_factor)
s[data_im2col].unroll(n_outer)
s[data_im2col].vectorize(n_inner)
- s[data_im2col].parallel(m)
elif padding_A:
s[data_im2col].compute_inline()
+ _, n_inner = s[A].split(A.op.axis[2], 16)
Review Comment:
For the 16 here, let's make it a variable to maintain the link to https://github.com/apache/tvm/pull/15648/files#diff-42b1313a1be464c7f2c94f75d656be725f1ccb54b9391cd5b27c33009ac0e2d5R421
##########
python/tvm/topi/arm_cpu/conv2d_gemm.py:
##########
@@ -326,7 +328,12 @@ def schedule_conv2d_gemm_interleaved(cfg, s, out, final_out):
b, m, n = data_im2col.op.axis
if data_im2col.op.name == "data_im2col":
- n_outer, n_inner = s[data_im2col].split(n, 16)
+ n_size = data_im2col.shape[2]
+ if n_size % 16 == 0:
+ split_factor = 16
+ else:
+ split_factor = 8
+ n_outer, n_inner = s[data_im2col].split(n, split_factor)
Review Comment:
nit: as its a separate change, could it be split into a new PR?
##########
python/tvm/topi/arm_cpu/conv2d_gemm.py:
##########
@@ -428,12 +435,29 @@ def schedule_conv2d_gemm_native(cfg, s, out, final_out):
b, m, n = data_im2col.op.axis
if data_im2col.op.name == "data_im2col":
- n_outer, n_inner = s[data_im2col].split(n, 16)
+ if A.op.name == "A_padded_K":
Review Comment:
would be good to add a comment here stating that if there are both "padding_K" and "padding_M" ops, this path will be selected
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] lhutton1 commented on pull request #15648: [Relay][TOPI] Remove input padding for arm_cpu conv2d int8 native schedule in Legalize pass
Posted by "lhutton1 (via GitHub)" <gi...@apache.org>.
lhutton1 commented on PR #15648:
URL: https://github.com/apache/tvm/pull/15648#issuecomment-1706540666
Awesome, thanks for checking!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] lhutton1 merged pull request #15648: [Relay][TOPI] Remove input padding for arm_cpu conv2d int8 native schedule in Legalize pass
Posted by "lhutton1 (via GitHub)" <gi...@apache.org>.
lhutton1 merged PR #15648:
URL: https://github.com/apache/tvm/pull/15648
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] lhutton1 commented on pull request #15648: [Relay][TOPI] Remove input padding for arm_cpu conv2d int8 native schedule in Legalize pass
Posted by "lhutton1 (via GitHub)" <gi...@apache.org>.
lhutton1 commented on PR #15648:
URL: https://github.com/apache/tvm/pull/15648#issuecomment-1717219542
Thanks @Anndrey24!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org