From 868788bf0074c42b5fd6b8546d9422f25d4171ee Mon Sep 17 00:00:00 2001 From: Kellen Sunderland Date: Sat, 25 Aug 2018 18:05:09 +0200 Subject: [PATCH 1/2] [MXNET-860] - Fix some unneeded copies --- src/ndarray/ndarray.cc | 4 ++-- src/operator/contrib/roi_align.cc | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/ndarray/ndarray.cc b/src/ndarray/ndarray.cc index 853838a87f4c..ddffa28cfd31 100644 --- a/src/ndarray/ndarray.cc +++ b/src/ndarray/ndarray.cc @@ -1031,7 +1031,7 @@ inline void CopyFromToRspImpl(const NDArray& from, const NDArray& to, RunContext op::FillZerosRspImpl(s, to); return; } - auto aux_shape = from.aux_shape(rowsparse::kIdx); + const auto& aux_shape = from.aux_shape(rowsparse::kIdx); to.CheckAndAlloc({aux_shape}); TBlob val = to.data(); TBlob idx = to.aux_data(rowsparse::kIdx); @@ -1122,7 +1122,7 @@ void CopyFromToImpl(const NDArray& from, const NDArray& to, if (from_stype == to_stype) { casted_nd = from; // same stype, no need to cast from } else { // different stypes on different ctx needs an temporary casted_nd - TShape shape = from.shape(); + const TShape& shape = from.shape(); if (to_stype == kDefaultStorage) { casted_nd = NDArray(shape, from_ctx); } else { diff --git a/src/operator/contrib/roi_align.cc b/src/operator/contrib/roi_align.cc index 22611273cf50..7e548481980b 100644 --- a/src/operator/contrib/roi_align.cc +++ b/src/operator/contrib/roi_align.cc @@ -422,7 +422,7 @@ void ROIAlignForwardCompute(const nnvm::NodeAttrs& attrs, CHECK_EQ(out_data.size(), expected_out); CHECK_EQ(out_data[roialign::kOut].shape_[0], in_data[roialign::kBox].shape_[0]); - const ROIAlignParam param = nnvm::get(attrs.parsed); + const ROIAlignParam& param = nnvm::get(attrs.parsed); const int count = out_data[roialign::kOut].Size(); // const int num_rois = in_data[roialign::kBox].size(0); @@ -466,7 +466,7 @@ void ROIAlignBackwardCompute(const nnvm::NodeAttrs& attrs, CHECK_NE(req[1], kWriteInplace) << "ROIAlign: Backward doesn't support kWriteInplace."; - const ROIAlignParam param = nnvm::get(attrs.parsed); + const ROIAlignParam& param = nnvm::get(attrs.parsed); const int count = out_grad[0].Size(); const int num_rois = in_data[0].size(0); @@ -534,7 +534,7 @@ He, Kaiming, et al. "Mask R-CNN." ICCV, 2017 .set_attr("FInferShape", [](const nnvm::NodeAttrs& attrs, std::vector *in_shape, std::vector *out_shape){ using namespace mshadow; - const ROIAlignParam param = nnvm::get(attrs.parsed); + const ROIAlignParam& param = nnvm::get(attrs.parsed); CHECK_EQ(in_shape->size(), 2) << "Input:[data, rois]"; // data: [batch_size, c, h, w] TShape dshape = in_shape->at(roialign::kData); From 1aacbb657d4bea2aac2f3532781ff9c83e6368c6 Mon Sep 17 00:00:00 2001 From: Kellen Sunderland Date: Sun, 2 Sep 2018 15:21:11 +0200 Subject: [PATCH 2/2] [MXNET-860] - Add unnecessary copy check to clang-tidy --- .clang-tidy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.clang-tidy b/.clang-tidy index 993656e12766..c84ba323b604 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -54,7 +54,7 @@ Checks: > # In order to trigger an error, you must have a rule defined both in checks and in this section. WarningsAsErrors: > - cppcoreguidelines-no-malloc + cppcoreguidelines-no-malloc, performance-unnecessary-copy-initialization # Todo: define a better regex match that includes most project headers, but excludes third party # code.