Skip to content
This repository was archived by the owner on Nov 17, 2023. It is now read-only.

Removing unnecessary copies from backward pass of binary elementwise ops #5935

Merged
merged 1 commit into from
Apr 26, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions src/operator/tensor/elemwise_binary_op.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,24 @@ void BinaryBackwardUseNone(const nnvm::NodeAttrs& attrs,
Tensor<xpu, 1, DType> lgrad = outputs[0].FlatTo1D<xpu, DType>(s);
Tensor<xpu, 1, DType> rgrad = outputs[1].FlatTo1D<xpu, DType>(s);
Tensor<xpu, 1, DType> ograd = inputs[0].FlatTo1D<xpu, DType>(s);
ASSIGN_DISPATCH(lgrad, req[0], F<LOP>(ograd));
ASSIGN_DISPATCH(rgrad, req[1], F<ROP>(ograd));
if (std::is_same<LOP, mshadow_op::identity>::value) {
if (req[0] == kWriteInplace) {
CHECK_EQ(ograd.dptr_, lgrad.dptr_);
} else {
ASSIGN_DISPATCH(lgrad, req[0], F<LOP>(ograd));
Copy link
Contributor

Choose a reason for hiding this comment

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

you can do copy here if req[0] == kwriteto

}
} else {
ASSIGN_DISPATCH(lgrad, req[0], F<LOP>(ograd));
}
if (std::is_same<ROP, mshadow_op::identity>::value) {
if (req[1] == kWriteInplace) {
CHECK_EQ(ograd.dptr_, rgrad.dptr_);
} else {
ASSIGN_DISPATCH(rgrad, req[1], F<ROP>(ograd));
}
} else {
ASSIGN_DISPATCH(rgrad, req[1], F<ROP>(ograd));
}
});
}

Expand Down