-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Add method converting Tensor to Eigen TensorMap #2805
Conversation
paddle/operators/add_op.h
Outdated
void Compute(const KernelContext& context) const override { | ||
auto input0 = context.Input(0)->Get<framework::Tensor>(); | ||
auto input1 = context.Input(1)->Get<framework::Tensor>(); | ||
auto* output = context.Output(0)->GetMutable<framework::Tensor>(); |
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.
Maybe output->mutable_data could hide in context.GetOutputTensor<>()
paddle/operators/add_op.h
Outdated
auto input1 = context.Input(1)->Get<framework::Tensor>(); | ||
auto* output = context.Output(0)->GetMutable<framework::Tensor>(); | ||
|
||
output->mutable_data<T>(Place()); |
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.
Only Place as argument is not enough.
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.
Output's dim have been set in InferShape method. So just pass a Place is enough.
The following code is a little repeated
output->mutable_data<T>(output->dims(), Place());
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.
Got it and have fix it.
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.
LGTM.
@@ -37,6 +39,13 @@ class Tensor { | |||
} | |||
|
|||
template <typename T> | |||
T* raw_data() const { |
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.
Since we always use raw_data
in OpKernel. The mutable_data is only used for allocation. Maybe we could change mutable_data
to allocation
467b044
to
4d49f1d
Compare
No description provided.