-
Notifications
You must be signed in to change notification settings - Fork 3.9k
[TOPI] Depth wise Conv for NHWC #325
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
Merged
Merged
Changes from 13 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
2b586d2
rename the nchw and pass the unit test; going to do it for nhwc depth…
b65d03f
bug with fusion
0c01fc0
resolved conflicts
68f1292
nchw works fine; nhwc float32 problem remains
a9a2975
still cannot bind them together
f6108c4
fusion works
ac264c2
resolved conflicts
d935fce
modify after pr 328
1f373f9
Merge branch 'master' of https://github.com/dmlc/tvm
ce5da31
Merge branch 'master' of https://github.com/dmlc/tvm
83703c1
syntax fix
4edcb4a
after merge, not working; cannot bind
c1ae53d
all bugs fixed; test cases pass
183e145
minor fix on nn.h
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -287,7 +287,7 @@ inline tvm::Tensor depthwise_conv2d_nchw(const tvm::Tensor& I, | |
| int stride_h = 1, | ||
| int stride_w = 1, | ||
| std::string name = "tensor", | ||
| std::string tag = kDepthwiseConv2d) { | ||
| std::string tag = kDepthwiseConv2dNCHW) { | ||
| CHECK_EQ(4, I->shape.size()); | ||
| CHECK_EQ(4, W->shape.size()); | ||
| auto pH = I->shape[2]; | ||
|
|
@@ -313,6 +313,39 @@ inline tvm::Tensor depthwise_conv2d_nchw(const tvm::Tensor& I, | |
| return tvm::compute(output_shape, l, name, tag); | ||
| } | ||
|
|
||
| inline tvm::Tensor depthwise_conv2d_nhwc(const tvm::Tensor& I, | ||
| const tvm::Tensor& W, | ||
| int pad_h = 0, | ||
| int pad_w = 0, | ||
| int stride_h = 1, | ||
| int stride_w = 1, | ||
| std::string name = "tensor", | ||
| std::string tag = kDepthwiseConv2d_nhwc) { | ||
| CHECK_EQ(4, I->shape.size()); | ||
| CHECK_EQ(4, W->shape.size()); | ||
| auto pH = I->shape[1]; | ||
| auto pW = I->shape[2]; | ||
| auto pCM = W->shape[1]; // channel_multiplier | ||
| tvm::Array<tvm::Expr> output_shape{ | ||
| I->shape[0], // B | ||
| (I->shape[1] - W->shape[1] + 2 * pad_h) / stride_h + 1, // H | ||
| (I->shape[2] - W->shape[2] + 2 * pad_w) / stride_w + 1, // W | ||
| W->shape[3], // O | ||
| }; | ||
| auto i = tvm::reduce_axis(tvm::Range{0, I->shape[3]}, "i"); | ||
| auto kh = tvm::reduce_axis(tvm::Range{0, W->shape[0]}, "kh"); | ||
| auto kw = tvm::reduce_axis(tvm::Range{0, W->shape[1]}, "kw"); | ||
| auto T = (pad_h == 0 && pad_w == 0) | ||
| ? I | ||
| : pad(I, {tvm::Expr(0), tvm::Expr(0), pad_h, pad_w}); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be {0, pad_h, pad_w, 0} |
||
| auto l = [&](tvm::Var b, tvm::Var h, tvm::Var w, tvm::Var o) { | ||
| return tvm::sum(T(b, stride_h * h + kh, stride_w * w + kw, i / pCM) * | ||
| W(kh, kw, i / pCM, o % pCM), | ||
| {kh, kw, i}); | ||
| }; | ||
| return tvm::compute(output_shape, l, name, tag); | ||
| } | ||
|
|
||
| /*! | ||
| * \brief Creates an operation that performs a 2-D group convolution with | ||
| * an NGCHW-layout | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
should be kDepthwiseConv2dNHWC