Skip to content

[caffe2] use AddNAlreadyReserved() when serializing blobs#53400

Closed
simpkins wants to merge 2 commits intogh/simpkins/3/basefrom
gh/simpkins/3/head
Closed

[caffe2] use AddNAlreadyReserved() when serializing blobs#53400
simpkins wants to merge 2 commits intogh/simpkins/3/basefrom
gh/simpkins/3/head

Conversation

@simpkins
Copy link
Copy Markdown
Contributor

@simpkins simpkins commented Mar 5, 2021

Stack from ghstack:

This is a reland of D26617038 after rebasing onto D26802576.

Optimize the blob serialization code by using AddNAlreadyReserved() when
serializing tensor data, rather than making N separate Add() calls.
AddNAlreadyReserved() is a simple addition operation, while each Add()
call checks to see if it needs to reserve new space, and then updates the
element data, which is unnecessary in this case.

Differential Revision: D26853941

This is a reland of D26617038 after rebasing onto D26802576.

Optimize the blob serialization code by using `AddNAlreadyReserved()` when
serializing tensor data, rather than making N separate `Add()` calls.
`AddNAlreadyReserved()` is a simple addition operation, while each `Add()`
call checks to see if it needs to reserve new space, and then updates the
element data, which is unnecessary in this case.

Differential Revision: [D26853941](https://our.internmc.facebook.com/intern/diff/D26853941/)

[ghstack-poisoned]
@facebook-github-bot
Copy link
Copy Markdown
Contributor

facebook-github-bot commented Mar 5, 2021

💊 CI failures summary and remediations

As of commit 2ae6940 (more details on the Dr. CI page):


💚 💚 Looks good so far! There are no failures yet. 💚 💚


This comment was automatically generated by Dr. CI (expand for details).Follow this link to opt-out of these comments for your Pull Requests.

Please report bugs/suggestions to the (internal) Dr. CI Users group.

This is a reland of D26617038 after rebasing onto D26802576.

Optimize the blob serialization code by using `AddNAlreadyReserved()` when
serializing tensor data, rather than making N separate `Add()` calls.
`AddNAlreadyReserved()` is a simple addition operation, while each `Add()`
call checks to see if it needs to reserve new space, and then updates the
element data, which is unnecessary in this case.

Differential Revision: [D26853941](https://our.internmc.facebook.com/intern/diff/D26853941/)

[ghstack-poisoned]
@facebook-github-bot
Copy link
Copy Markdown
Contributor

This pull request has been merged in 99d7c8f.

@facebook-github-bot facebook-github-bot deleted the gh/simpkins/3/head branch March 14, 2021 14:14
xsacha pushed a commit to xsacha/pytorch that referenced this pull request Mar 31, 2021
)

Summary:
Pull Request resolved: pytorch#53400

This is a reland of D26617038 (pytorch@b4a8d98) after rebasing onto D26802576 (pytorch@f595ba1).

Optimize the blob serialization code by using `AddNAlreadyReserved()` when
serializing tensor data, rather than making N separate `Add()` calls.
`AddNAlreadyReserved()` is a simple addition operation, while each `Add()`
call checks to see if it needs to reserve new space, and then updates the
element data, which is unnecessary in this case.
ghstack-source-id: 123567030

Test Plan:
This appears to improve raw serialization performance by 30 to 35% for float,
double, and int64_t types which use this function.  This improvement appears
relatively consistent across large and small tensor sizes.

Reviewed By: mraway

Differential Revision: D26853941

fbshipit-source-id: 4ccaa5bc1dd7f7864068d71a0cde210c699cbdba
laurentdupin pushed a commit to laurentdupin/pytorch that referenced this pull request Apr 24, 2026
)

Summary:
Pull Request resolved: pytorch#53400

This is a reland of D26617038 (pytorch@aff01bc) after rebasing onto D26802576 (pytorch@2fad0d9).

Optimize the blob serialization code by using `AddNAlreadyReserved()` when
serializing tensor data, rather than making N separate `Add()` calls.
`AddNAlreadyReserved()` is a simple addition operation, while each `Add()`
call checks to see if it needs to reserve new space, and then updates the
element data, which is unnecessary in this case.
ghstack-source-id: 123567030

Test Plan:
This appears to improve raw serialization performance by 30 to 35% for float,
double, and int64_t types which use this function.  This improvement appears
relatively consistent across large and small tensor sizes.

Reviewed By: mraway

Differential Revision: D26853941

fbshipit-source-id: 4ccaa5bc1dd7f7864068d71a0cde210c699cbdba
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants