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

Bug in "paddle/fluid/framework/tensor_impl.h" and inefficient code in "paddle/fluid/framework/reader.cc" #11037

Closed
sneaxiy opened this issue May 30, 2018 · 0 comments · Fixed by #11038

Comments

@sneaxiy
Copy link
Collaborator

sneaxiy commented May 30, 2018

Bug in paddle/fluid/framework/tensor_impl.h

In functions const T* Tensor::data() const and T* Tensor::data(), the inner type holder_ holds must be the same as T. It is implemented by comparing hash codes in the current version, i.e., holder_->type().hash_code() == typeid(T).hash_code().

However, C++ does not guarantee the hash codes of different types must be different. It is recommended to change it to be holder_->type() == std::type_index(typeid(T)).

Inefficient code in paddle/fluid/framework/reader.cc

Inside the first for loop of function void FileReader::ReadNext(std::vector<LoDTensor> *out), std::vector<LodTensor>::at is called to access the data in the read-out result out. Therefore, std::vector<LodTensor>::at would check the size bound of out during each loop and thus it is inefficient.

A better choice is to add PADDLE_ENFORCE_EQ to compare out->size() to dims_.size() before the loop, rather than check the bounds in each loop.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant