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

fix trace offset out of shape #33922

Merged
merged 1 commit into from
Jul 2, 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
fix trace offset out of shape
  • Loading branch information
jeff41404 committed Jul 1, 2021
commit 4992bd444c1ec17473669137e734703ccdaaeaf1
4 changes: 4 additions & 0 deletions paddle/fluid/operators/trace_op.cu
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include <thrust/device_vector.h>
#include <thrust/host_vector.h>
#include "paddle/fluid/operators/math/math_function.h"
#include "paddle/fluid/operators/reduce_ops/cub_reduce.h"
#include "paddle/fluid/operators/trace_op.h"

Expand Down Expand Up @@ -50,6 +51,9 @@ class TraceCUDAKernel : public framework::OpKernel<T> {
TensorReduce<T, T, cub::Sum, IdentityFunctor>(
diag, out, reduce_dims, static_cast<T>(0), cub::Sum(),
IdentityFunctor(), stream);
} else {
math::SetConstant<DeviceContext, T> functor;
functor(context.device_context<DeviceContext>(), out, static_cast<T>(0));
}
}
};
Expand Down
4 changes: 3 additions & 1 deletion paddle/fluid/operators/trace_op.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ class TraceKernel : public framework::OpKernel<T> {

auto output_dims = out->dims();

out->mutable_data<T>(context.GetPlace());
T* out_data = out->mutable_data<T>(context.GetPlace());

const framework::Tensor diag =
Diagonal<DeviceContext, T>(context, input, offset, dim1, dim2);
Expand All @@ -191,6 +191,8 @@ class TraceKernel : public framework::OpKernel<T> {
auto reduce_dim = Eigen::array<int, 1>({1});
output.device(place) = x.sum(reduce_dim);
out->Resize(output_dims);
} else {
std::fill(out_data, out_data + out->numel(), static_cast<T>(0));
}
}
};
Expand Down