-
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
base: master
Are you sure you want to change the base?
Changes from all commits
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 |
---|---|---|
|
@@ -335,6 +335,55 @@ std::vector<tensor::value_type> layout::get_pitches() const { | |
return pitches; | ||
} | ||
|
||
void layout::get_axes_map(cldnn::format& fmt, int64_t* axes_map, size_t& map_size) { | ||
const auto& output_order = fmt.order(); | ||
const auto& internal_order = fmt.internal_order(); | ||
std::vector<int64_t> sizes_map(output_order.size(), 0); | ||
|
||
//output_order has more elements than allocated in axes_map | ||
if (output_order.size() > map_size) { | ||
OPENVINO_THROW("Layout dimension higher than expected" + std::to_string(output_order.size())); | ||
} | ||
|
||
map_size = output_order.size(); | ||
|
||
for (size_t i = 0; i < map_size; i++) { | ||
auto c = output_order[i]; | ||
auto pos = internal_order.find(c); | ||
|
||
if (pos == std::string::npos) | ||
OPENVINO_THROW("Unknown coord type: " + std::to_string(c)); | ||
|
||
axes_map[i] = pos; | ||
} | ||
} | ||
|
||
void layout::get_linear_offset_params(tensor& start_points, tensor& end_points, int64_t* padded_sizes, | ||
int64_t* axes_map, size_t& map_size) { | ||
auto default_fmt = format::get_default_format(format.dimension(), format::is_weights_format(format), format::is_grouped(format)); | ||
|
||
std::vector<tensor::value_type> lower_sizes, upper_sizes; | ||
lower_sizes.assign(data_padding._lower_size.begin(), data_padding._lower_size.begin() + format.dimension()); | ||
upper_sizes.assign(data_padding._upper_size.begin(), data_padding._upper_size.begin() + format.dimension()); | ||
start_points = tensor(default_fmt, lower_sizes, 0); | ||
const auto& u_padd = tensor(default_fmt, upper_sizes, 0); | ||
|
||
auto t = get_tensor(); | ||
end_points = t + start_points; | ||
|
||
std::replace(t.raw.begin(), t.raw.end(), 0, 1); | ||
|
||
get_axes_map(format, axes_map, map_size); | ||
const auto& p_sizes = (t + start_points + u_padd).sizes(format); | ||
|
||
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]; | ||
} | ||
} | ||
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. BTW, do we need this function inside the layout.cpp? 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. It is using memeber variables of layout class. For example, data_padding. Even get_tensor() call has dependency to the layout object. 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. We can get them from layout. Just like some_layout().data_padding. |
||
|
||
size_t layout::get_linear_offset(tensor element) const { | ||
auto default_fmt = format::get_default_format(format.dimension(), format::is_weights_format(format), format::is_grouped(format)); | ||
|
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.
#32371 (comment)
Also, as I mentioned in the previous comment, please move this function to format.hpp
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.
We can move get_linear_offset_params() to layout.hpp. May I know the reason or advantage you see to keep in hpp?
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.
format.hpp, instead of layout.hpp. This is more about format. layout is user of format.
you can see there similar handles in format.hpp.
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.
Something likne format::internal_to_external(idx). The function you added is similar to that.