Skip to content

fix tile op #6487

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 2 commits into from
Jul 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
13 changes: 11 additions & 2 deletions lite/kernels/arm/reduce_sum_compute.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ template <typename T, PrecisionType Ptype>
void ReduceSumCompute<T, Ptype>::Run() {
auto& param = this->template Param<operators::ReduceParam>();
auto* input = param.X->template data<T>();
auto x_dims = param.X->dims();
int x_rank = x_dims.size();
auto x_vec = param.X->dims().Vectorize();
int x_rank = param.X->dims().size();
auto* Out = param.Out->template mutable_data<T>();
std::vector<int> dim = param.dim;
bool keep_dim = param.keep_dim;
Expand All @@ -41,6 +41,15 @@ void ReduceSumCompute<T, Ptype>::Run() {
}
}

for (;;) {
if (x_vec.size() >= 5 && x_vec[0] == 1) {
x_vec.erase(x_vec.begin());
for (auto& val : dim) val--;
} else
break;
}
auto x_dims = lite::DDim(x_vec);

if (reduce_all) {
lite::arm::math::reduce_sum_all(input, Out, x_dims.production());
} else {
Expand Down
11 changes: 7 additions & 4 deletions lite/kernels/host/tile_compute.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,20 @@ void TileCompute<T, PType>::Run() {
auto tmp_dst = tmp_dst_tensor.mutable_data<T>();
for (int i = 0; i < in_dims.production(); i++) {
tmp_src[i] = in_data[i];
tmp_dst[i] = in_data[i];
}

int right = 1;
for (int i = bcast_dims.size() - 1; i >= 0; i--) {
right *= bcast_dims[i];
if (bcast_dims[i] > 1) {
int num = in_stride[1] / in_stride[i + 1];
int dst_stride = in_stride[i + 1] * bcast_dims[i + 1];
int dst_stride = in_stride[i + 1] * right;
for (int m = 0; m < num; m++) {
for (int j = 0; j < bcast_dims[i]; j++) {
std::memcpy(tmp_dst + j * dst_stride + m * bcast_dims[i] * dst_stride,
tmp_src + m * in_stride[i + 1],
dst_stride * sizeof(T));
std::memcpy(tmp_dst + j * dst_stride / bcast_dims[i] + m * dst_stride,
tmp_src + m * dst_stride / bcast_dims[i],
dst_stride / bcast_dims[i] * sizeof(T));
}
}
tmp_src_tensor.CopyDataFrom(tmp_dst_tensor);
Expand Down