-
Notifications
You must be signed in to change notification settings - Fork 5.9k
[Sparse conv] Implement implicit gemm algo for SubmConv3D #62747
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 12 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
98a427b
sparse conv: implement implicit gemm algo
Wong4j 3f8fc96
add ut
Wong4j fb17ddd
remove redundant file
Wong4j 881bea1
fix error
Wong4j b0b3c68
support 2d input for sparse_conv_igemm
Wong4j 32ae706
fix 3d bug
Wong4j bc12530
skip ut when arch < 75
Wong4j 8a9ee31
minor change
Wong4j dcc9b0b
fix cache
Wong4j 87bc6a5
rm print
Wong4j 289e8c7
skip ut for win32
Wong4j 4851677
fix code style
Wong4j 7530c0a
add more ut
Wong4j bd1cebf
minor change
Wong4j ba131b2
add more UTs
Wong4j 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| // Copyright (c) 2024 PaddlePaddle Authors. All Rights Reserved. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| #pragma once | ||
|
|
||
| #include "paddle/phi/core/dense_tensor.h" | ||
| #include "paddle/phi/core/device_context.h" | ||
|
|
||
| namespace phi { | ||
|
|
||
| struct KmapCache { | ||
| DenseTensor* out_in_map = nullptr; | ||
| DenseTensor* coords = nullptr; | ||
| DenseTensor* hashmap_keys = nullptr; | ||
| DenseTensor* hashmap_values = nullptr; | ||
| // std::vector<int>* spatial_range; | ||
|
|
||
| // destructor | ||
| ~KmapCache() { | ||
| if (out_in_map) { | ||
| delete out_in_map; | ||
| } | ||
| if (coords) { | ||
| delete coords; | ||
| } | ||
| if (hashmap_keys) { | ||
| delete hashmap_keys; | ||
| } | ||
| if (hashmap_values) { | ||
| delete hashmap_values; | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| } // namespace phi | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -121,6 +121,43 @@ void Conv3dInferMeta(const MetaTensor& x, | |
| counter->set_dims({1}); | ||
| } | ||
|
|
||
| void Conv3dImplicitGemmInferMeta(const MetaTensor& x, | ||
|
Contributor
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. ci的代码没有覆盖到这个OP,可以针对这个OP增加单测
Collaborator
Author
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. Done |
||
| const MetaTensor& kernel, | ||
| const std::vector<int>& paddings, | ||
| const std::vector<int>& dilations, | ||
| const std::vector<int>& strides, | ||
| const int groups, | ||
| const bool subm, | ||
| const std::string& key, | ||
| MetaTensor* out) { | ||
| const auto& x_dims = x.dims(); | ||
| const bool is2D = x_dims.size() == 4 ? true : false; | ||
| const auto& kernel_dims = kernel.dims(); | ||
|
|
||
| int rank = is2D ? 4 : 5; | ||
| std::vector<int> out_dims_vec(rank, 1); | ||
| DDim out_dims = common::make_ddim(out_dims_vec); | ||
|
|
||
| std::vector<int> kernel_sizes(kernel_dims.size()); | ||
| for (int i = 0; i < kernel_dims.size(); i++) { | ||
| kernel_sizes[i] = static_cast<int>(kernel_dims[i]); | ||
| } | ||
|
|
||
| std::vector<int> subm_paddings(paddings), subm_strides(strides); | ||
| if (subm) { | ||
| // the out shape of subm_conv is same as input shape | ||
| // reset the padding=kernel_size/2 and strides=1 | ||
| ResetSubmKernelSizeAndStrides(kernel.dims(), &subm_paddings, &subm_strides); | ||
| } | ||
|
|
||
| GetOutShape( | ||
| x_dims, kernel_sizes, subm_paddings, dilations, subm_strides, &out_dims); | ||
|
|
||
| out->set_dtype(x.dtype()); | ||
| out->set_dims(out_dims); | ||
| out->set_layout(x.layout()); | ||
| } | ||
|
|
||
| inline const std::vector<int> PoolResetKernel( | ||
| const std::vector<int>& kernel_sizes, | ||
| const int in_channels, | ||
|
|
||
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.
单测中没有执行这个析构,可以增加一下
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.
我增加了单测,本地跑单测会跑到这个析构,但是CI仍然显示没有跑到。