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

inference/unify output buffer management #11569

Merged

Conversation

Superjomn
Copy link
Contributor

@Superjomn Superjomn commented Jun 19, 2018

  • Make PaddleBuf possible to manage the buffer

@Superjomn Superjomn requested a review from panyx0718 June 19, 2018 09:51

namespace paddle {

PaddleBuf::PaddleBuf(PaddleBuf&& other)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this used?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Free();
data_ = new char[length];
length_ = length;
memory_owned_ = true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why assign again?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reset a new length.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean memory_owned_ is already true, as assert before.

std::memcpy(
outputs->at(i).data.data, data.data(), outputs->at(i).data.length);
auto &buffer = outputs->at(i).data;
if (buffer.empty() || buffer.length() < sizeof(float) * data.size()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we don't want to allow buffer.length() > sizeof(float) * data.size()? If that's the case, how does client know how many bytes to use?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is safe to Resize here.

If the client doesn't know how much to allocate or Resize, just init with a large enough memory, and do not resize it.

// Only the owned memory can be reset, the external memory can't be changed.
assert(memory_owned_);
Free();
data_ = new char[length];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the length == length_, can return early?

Free();
data_ = new char[length];
length_ = length;
memory_owned_ = true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean memory_owned_ is already true, as assert before.

@Superjomn Superjomn merged commit a009272 into PaddlePaddle:develop Jun 20, 2018
@Superjomn Superjomn deleted the enhance/inference-api-out-buffer branch June 20, 2018 07:25
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