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

Add method converting Tensor to Eigen TensorMap #2805

Merged
merged 19 commits into from
Jul 18, 2017

Conversation

QiJune
Copy link
Member

@QiJune QiJune commented Jul 11, 2017

No description provided.

@QiJune QiJune changed the title [WIP]Add method converting Tensor to Eigen TensorMap Add method converting Tensor to Eigen TensorMap Jul 17, 2017
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>();
Copy link
Collaborator

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<>()

auto input1 = context.Input(1)->Get<framework::Tensor>();
auto* output = context.Output(0)->GetMutable<framework::Tensor>();

output->mutable_data<T>(Place());
Copy link
Collaborator

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.

Copy link
Member Author

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());

Copy link
Member Author

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.

Copy link
Collaborator

@reyoung reyoung left a 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 {
Copy link
Collaborator

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

@QiJune QiJune merged commit 3208914 into PaddlePaddle:develop Jul 18, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants