Skip to content
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

ref_impl - Concat: buffer calculation of shape sizes #4240

Merged
merged 2 commits into from
Feb 12, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions ngraph/core/reference/src/runtime/reference/concat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,20 @@ namespace ngraph
{
namespace reference
{
namespace
{
std::vector<size_t> calculate_shape_sizes(const std::vector<Shape>& in_shapes)
{
std::vector<size_t> sizes;
sizes.reserve(in_shapes.size());
for (size_t in_index = 0; in_index != in_shapes.size(); ++in_index)
{
sizes.push_back(shape_size(in_shapes[in_index]));
}
return sizes;
}
pelszkow marked this conversation as resolved.
Show resolved Hide resolved
} // namespace

void concat(const std::vector<const char*>& args,
char* out,
const std::vector<Shape>& in_shapes,
Expand All @@ -37,13 +51,15 @@ namespace ngraph
steps *= out_shape[i];
}

const auto& shape_sizes = calculate_shape_sizes(in_shapes);

size_t out_offset = 0;
for (size_t step = 0; step < steps; ++step)
{
for (size_t in_index = 0; in_index < args.size(); ++in_index)
{
size_t size = shape_size(in_shapes[in_index]) / steps;
size_t in_offset = step * size;
const size_t size = shape_sizes[in_index] / steps;
const size_t in_offset = step * size;

std::memcpy(&out[out_offset * elem_size],
&args[in_index][in_offset * elem_size],
Expand Down