Skip to content

Commit

Permalink
Optimize CPU and Memory performance for Resize linear mode parser
Browse files Browse the repository at this point in the history
Revise based on reviewer comments.
Rebase to develop HEAD.

Signed-off-by: Colin Xu <[email protected]>
  • Loading branch information
coxuamd committed Jan 10, 2025
1 parent 0f7dff4 commit 772862d
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions src/onnx/parse_resize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,24 +99,21 @@ calc_neighbor_points(const std::vector<std::vector<std::vector<std::size_t>>>& v

if(n_bits >= std::numeric_limits<std::size_t>::digits)
{
throw std::runtime_error("Shape dimension " + std::to_string(n_bits) + " exceeds " +
std::to_string(std::numeric_limits<std::size_t>::digits));
MIGRAPHX_THROW("PARSE_RESIZE: Shape dimension " + std::to_string(n_bits) + " exceeds " +

Check warning on line 102 in src/onnx/parse_resize.cpp

View check run for this annotation

Codecov / codecov/patch

src/onnx/parse_resize.cpp#L102

Added line #L102 was not covered by tests
std::to_string(std::numeric_limits<std::size_t>::digits));
}

for(std::size_t val = 0; val < (std::size_t{1} << n_bits); val++)
{
std::bitset<std::numeric_limits<std::size_t>::digits> bits_val = val;
std::vector<std::size_t> indices(n_bits);
transform(
range(m_elements), std::back_inserter(vec_ind), [&](const std::size_t& i_element) {
transform(vvv_ind,
range(n_bits),
indices.begin(),
[&](const auto& vv_ind, const std::size_t& bit) {
return vv_ind[bits_val[bit]][i_element];
});
return in_s.index(indices);
});
transform(range(m_elements), std::back_inserter(vec_ind), [&](std::size_t i_element) {
transform(
vvv_ind, range(n_bits), indices.begin(), [&](const auto& vv_ind, std::size_t bit) {
return vv_ind[bits_val[bit]][i_element];
});
return in_s.index(indices);
});
}

return vec_ind;
Expand Down

0 comments on commit 772862d

Please sign in to comment.