-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[Hexagon] Enable depthwise conv2d NHWC with an HWIO kernel layout #13414
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
c621db9
fc2b365
6cdb2d0
e582efb
ce70659
dfff52d
e34374b
0bf433f
de68e67
4239414
5155ebd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,7 @@ | |
| from __future__ import absolute_import as _abs | ||
| from collections import namedtuple | ||
| import tvm | ||
| import numpy as np | ||
| from tvm import te | ||
|
|
||
| from .dilate import dilate | ||
|
|
@@ -211,7 +212,7 @@ def depthwise_conv2d_nchw(Input, Filter, stride, padding, dilation, out_dtype=No | |
| return Output | ||
|
|
||
|
|
||
| def depthwise_conv2d_nhwc(Input, Filter, stride, padding, dilation, out_dtype=None): | ||
| def depthwise_conv2d_nhwc(Input, Filter, stride, padding, dilation, kernel_layout, out_dtype=None): | ||
| """Depthwise convolution nhwc forward operator. | ||
|
|
||
| Parameters | ||
|
|
@@ -252,8 +253,18 @@ def depthwise_conv2d_nhwc(Input, Filter, stride, padding, dilation, out_dtype=No | |
| dilation_h, dilation_w = dilation | ||
|
|
||
| batch, in_height, in_width, in_channel = Input.shape | ||
|
|
||
| dim = len(Input.shape) - 2 | ||
|
|
||
| # shape of dilated kernel | ||
| filter_height, filter_width, filter_channel, channel_multiplier = Filter.shape | ||
| if kernel_layout == "HWOI": | ||
| filter_height, filter_width, filter_channel, channel_multiplier = Filter.shape | ||
| kernel_permutation_to = [0, 1] + list(range(2, dim + 2)) | ||
| elif kernel_layout == "HWIO": | ||
| filter_height, filter_width, channel_multiplier, filter_channel = Filter.shape | ||
| kernel_permutation_to = [dim + 1, dim] + list(range(dim)) | ||
|
|
||
| kernel_permutation_from = np.argsort(kernel_permutation_to) | ||
|
||
|
|
||
| dilated_kernel_h = (filter_height - 1) * dilation_h + 1 | ||
| dilated_kernel_w = (filter_width - 1) * dilation_w + 1 | ||
|
|
@@ -284,9 +295,13 @@ def depthwise_conv2d_nhwc(Input, Filter, stride, padding, dilation, out_dtype=No | |
| j * stride_w + dj * dilation_w, | ||
| idxdiv(c, channel_multiplier), | ||
| ].astype(out_dtype) | ||
| * Filter[ | ||
| di, dj, idxdiv(c, channel_multiplier), idxmod(c, channel_multiplier) | ||
| ].astype(out_dtype) | ||
| * Filter.__getitem__( | ||
|
||
| tuple( | ||
| np.array( | ||
| [di, dj, idxdiv(c, channel_multiplier), idxmod(c, channel_multiplier)] | ||
| )[kernel_permutation_from] | ||
| ) | ||
| ).astype(out_dtype) | ||
| ), | ||
| axis=[di, dj], | ||
| ), | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not seeing how this permutation generates
HWIO. This defineskernel_permutation_toas[3, 2, 0, 1], sokernel_permutation_fromis[2, 3, 1, 0]. With the usage below, that would permute from[di, dj, c//channel_multiplier, c%channel_multiplier]to[c//channel_multiplier, c%channel_multiplier, dj, di], which would beOIWH.Should this be
list(range(dim)) + [dim + 1, dim]instead?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Lunderberg You are right, my bad. Not sure why I thought this would result in
HWIO. Thanks so much for catching this bug.