-
Notifications
You must be signed in to change notification settings - Fork 6.8k
[performance] Avoid uneccesary vector copies in imperative_utils.cc #14665
Conversation
@mxnet-label-bot add [performance,pr-awaiting-review] |
@mxnet-label-bot add [backend,memory] |
inline std::vector<NDArray*> NodeInputs(const nnvm::IndexedGraph& idx, | ||
const int node_idx, | ||
const std::vector<NDArray*> arrays) { | ||
std::vector<NDArray*> NodeInputs(const nnvm::IndexedGraph& idx, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we pass in the returned vector std::vector<NDArray*>
so we can save another copy?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would be unnecessary and non idiomatic. Return value optimization (RVO) will kick in and eliminate any extra copies on return values.
inline std::vector<NDArray*> NodeOutputs(const nnvm::IndexedGraph& idx, | ||
const int node_idx, | ||
const std::vector<NDArray*> arrays) { | ||
std::vector<NDArray*> NodeOutputs(const nnvm::IndexedGraph& idx, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we pass in the returned vector std::vector<NDArray*>
so we can save another copy?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there will be not any another copy because of the right-value reference of std::vector.
inline std::vector<OpReqType> NodeReq(const nnvm::IndexedGraph& idx, | ||
const int node_idx, | ||
const std::vector<OpReqType> array_reqs) { | ||
std::vector<OpReqType> NodeReq(const nnvm::IndexedGraph& idx, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we pass in the returned vector std::vector<OpReqType>
so we can save another copy?
|
||
inline std::vector<NDArray*> NodeInputs(const nnvm::IndexedGraph& idx, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why remove inline?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the point of inline here? These are private functions so they are moved to anonymous namespace. Let the compiler do the inline as the compiler is better at this than us. We are abusing inline in the codebase.
https://stackoverflow.com/questions/1932311/when-to-use-inline-function-and-when-not-to-use-it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we measure the impact here? Because this logic is part of core engine and gets exposed to every job, I was wondering if it would be good to measure the performance impact.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thank you for the fix!
@mxnet-label-bot add [pr-awaiting-merge] |
@mxnet-label-bot remove [pr-awaiting-review] |
Merged. Thank you! |
@larroy - I had quick question on this PR - Can we measure the impact here? |
@sandeep-krishnamurthy Do we have some default go-to performance metric for our countributions? I find this would be very useful. |
Description
see title
Checklist
Essentials
Please feel free to remove inapplicable items for your PR.