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

Extract RowBuffer class for SparseRowMatrix. #863

Merged
merged 9 commits into from
Jan 18, 2017

Conversation

reyoung
Copy link
Collaborator

@reyoung reyoung commented Dec 13, 2016

  • The original SparseRowMatrix use two fields to store each row,
    which make code very confusing. Try to extract a RowBuffer class,
    for SparseRowMatrix data storage, and manage auto-growth logic.

* The original SparseRowMatrix use two fields to store each rows,
  which let code very confusing. Try to extract a RowBuffer class,
  for SparseRowMatrix data storage, and manage auto-growth logic.
*/
inline void resize(int rowCnt) {
if (preallocatedBuf_) {
CHECK(preallocatedBuf_->getSize() < rowCnt * width_ * sizeof(real));
Copy link
Contributor

Choose a reason for hiding this comment

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

这里写反了吧?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done.


private:
CpuMemHandlePtr preallocatedBuf_;
std::vector<real, AlignedAllocator<real, 32>> rowStore_;
Copy link
Contributor

Choose a reason for hiding this comment

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

rowStore_是不是直接用CpuMemoryHandle就可以了,只是resize greater的时候需要一次copy。

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

有道理,不过再下一个PR里面加吧。

加了一个TODO注释

*/
inline size_t getRowCount() const {
if (preallocatedBuf_) {
return preallocatedBuf_->getSize() / sizeof(float) / width_;
Copy link
Contributor

Choose a reason for hiding this comment

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

sizeof(real)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done.

* @brief get is this buffer can automatically grow or not.
* @return ture if can automacitally grow.
*/
inline bool isAutoGrowth() const { return preallocatedBuf_ == nullptr; }
Copy link
Contributor

Choose a reason for hiding this comment

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

return !preallocatedBuf_;

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done.

@reyoung reyoung merged commit 7000cb6 into PaddlePaddle:develop Jan 18, 2017
@reyoung reyoung deleted the feature/clean_sparse_row_matrix branch January 18, 2017 06:06
zhhsplendid pushed a commit to zhhsplendid/Paddle that referenced this pull request Sep 25, 2019
wangxicoding pushed a commit to wangxicoding/Paddle that referenced this pull request Dec 9, 2021
* optimize the time cost for the wordtag

* update the optimize code for the predictor
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