-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Optimze copy tensor with padding #32461
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
Open
susbhere
wants to merge
4
commits into
openvinotoolkit:master
Choose a base branch
from
susbhere:optimize_padded_copy
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+77
−10
Open
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
d06ad11
Optimze copy tensor with padding
susbhere 2cc83e0
Moved the calculations to format.hpp and common_utils.cpp from
susbhere f056da3
Moved the calculations to format.hpp and common_utils.cpp from
susbhere 654910a
Optimze copy tensor with padding
susbhere 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,37 @@ | |
|
||
namespace { | ||
|
||
using namespace cldnn; | ||
|
||
#define MAX_NUM_AXES 6 | ||
void get_linear_offset_params(layout& layout, tensor& start_points, tensor& end_points, int64_t* padded_sizes, int64_t* axes_map, size_t& map_size) { | ||
auto fmt = layout.get_format(); | ||
auto data_padding = layout.get_padding(); | ||
auto default_fmt = format::get_default_format(fmt.dimension(), format::is_weights_format(fmt), format::is_grouped(fmt)); | ||
|
||
std::vector<tensor::value_type> lower_sizes, upper_sizes; | ||
lower_sizes.assign(data_padding._lower_size.begin(), data_padding._lower_size.begin() + fmt.dimension()); | ||
upper_sizes.assign(data_padding._upper_size.begin(), data_padding._upper_size.begin() + fmt.dimension()); | ||
start_points = tensor(default_fmt, lower_sizes, 0); | ||
const auto& u_padd = tensor(default_fmt, upper_sizes, 0); | ||
|
||
auto t = layout.get_tensor(); | ||
end_points = t + start_points; | ||
|
||
std::replace(t.raw.begin(), t.raw.end(), 0, 1); | ||
|
||
format::get_axes_map(fmt, axes_map, map_size); | ||
const auto& p_sizes = (t + start_points + u_padd).sizes(fmt); | ||
|
||
if (p_sizes.size() < map_size) { | ||
OPENVINO_THROW("Unsupported padded layout dimension" + std::to_string(p_sizes.size())); | ||
} | ||
|
||
for (size_t i = 0; i < p_sizes.size(); i++) { | ||
padded_sizes[i] = p_sizes[i]; | ||
} | ||
} | ||
|
||
template <typename src_t, typename dst_t> | ||
void convert_and_copy_no_pad(const src_t* src, dst_t* dst, size_t size) { | ||
OPENVINO_ASSERT(src && dst, "[GPU] Src or Dst ptr is null"); | ||
|
@@ -26,15 +57,26 @@ void convert_and_copy_no_pad(const src_t* src, dst_t* dst, size_t size) { | |
} | ||
|
||
template <typename src_t, typename dst_t> | ||
void convert_and_copy_padded_source(const src_t* src, dst_t* dst, cldnn::layout layout) { | ||
cldnn::tensor size = layout.get_tensor(); | ||
for (int64_t b = 0; b < size.batch[0]; b++) { | ||
for (int64_t f = 0; f < size.feature[0]; f++) { | ||
for (int64_t w = 0; w < size.spatial[3]; w++) { | ||
for (int64_t z = 0; z < size.spatial[2]; z++) { | ||
for (int64_t y = 0; y < size.spatial[1]; y++) { | ||
for (int64_t x = 0; x < size.spatial[0]; x++) { | ||
*dst++ = static_cast<dst_t>(src[layout.get_linear_offset(cldnn::tensor(b, f, x, y, z, w))]); | ||
void convert_and_copy_padded_source(const src_t* src, dst_t* dst, layout& layout) { | ||
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 only works for plain format. So please apply it for plain format only. For other (e.g., blocked) formats, please use original method. |
||
tensor axes_start_point, axes_end_point; | ||
int64_t padded_sizes[MAX_NUM_AXES], axes_map[MAX_NUM_AXES]; | ||
size_t map_len = MAX_NUM_AXES; | ||
|
||
get_linear_offset_params(layout, axes_start_point, axes_end_point, padded_sizes, axes_map, map_len); | ||
|
||
for (int64_t b = axes_start_point.batch[0]; b < axes_end_point.batch[0]; b++) { | ||
for (int64_t f = axes_start_point.feature[0]; f < axes_end_point.feature[0]; f++) { | ||
for (int64_t w = axes_start_point.spatial[3]; w < axes_end_point.spatial[3]; w++) { | ||
for (int64_t z = axes_start_point.spatial[2]; z < axes_end_point.spatial[2]; z++) { | ||
for (int64_t y = axes_start_point.spatial[1]; y < axes_end_point.spatial[1]; y++) { | ||
for (int64_t x = axes_start_point.spatial[0]; x < axes_end_point.spatial[0]; x++) { | ||
int64_t element_sizes[MAX_NUM_AXES] = {b, f, x, y, z, w}; | ||
size_t offset = element_sizes[axes_map[0]]; | ||
|
||
for (size_t i = 1; i < map_len; i++) | ||
offset = offset * padded_sizes[i] + element_sizes[axes_map[i]]; | ||
|
||
*dst++ = static_cast<dst_t>(src[offset]); | ||
} | ||
} | ||
} | ||
|
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.
Uh oh!
There was an error while loading. Please reload this page.