From: Сергей Баранников/AI Tools Lab /SRR/Engineer/삼성전자 Date: Tue, 3 Sep 2019 18:38:46 +0000 (+0300) Subject: [mir] Pass aggregate arguments by const reference (#7143) X-Git-Tag: accepted/tizen/unified/20190904.110638~14 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6a3dbdfc574dcd4266bb31d7a57ecbaf9b0a4888;p=platform%2Fcore%2Fml%2Fnnfw.git [mir] Pass aggregate arguments by const reference (#7143) clang-tidy suggests to pass by value and use `std::move`, but it is easy to forget and does not give significant benefits. Signed-off-by: Sergei Barannikov --- diff --git a/compiler/mir/include/mir/Shape.h b/compiler/mir/include/mir/Shape.h index f3082e8..18fa812 100644 --- a/compiler/mir/include/mir/Shape.h +++ b/compiler/mir/include/mir/Shape.h @@ -40,7 +40,8 @@ public: Shape(std::initializer_list &&dims) : _dims(std::move(dims)) {} - explicit Shape(const std::vector &dims) : _dims(std::begin(dims), std::end(dims)) {} + // TODO Make it 'explicit'. + Shape(const std::vector &dims) : _dims(std::begin(dims), std::end(dims)) {} int32_t rank() const { return static_cast(_dims.size()); } diff --git a/compiler/mir/include/mir/ops/AvgPool2DOp.h b/compiler/mir/include/mir/ops/AvgPool2DOp.h index 394e537..c53cd79 100644 --- a/compiler/mir/include/mir/ops/AvgPool2DOp.h +++ b/compiler/mir/include/mir/ops/AvgPool2DOp.h @@ -31,12 +31,13 @@ namespace ops class AvgPool2DOp : public Operation { public: - AvgPool2DOp(Output *arg, std::vector window_size, std::vector strides, - std::vector padding_before, std::vector padding_after, - bool include_pad, DataFormat data_format) - : Operation(Type::avgPool2D, {arg}), _window_size(std::move(window_size)), - _strides(std::move(strides)), _padding_before(std::move(padding_before)), - _padding_after(std::move(padding_after)), _include_pad(include_pad), + AvgPool2DOp(Output *arg, const std::vector &window_size, + const std::vector &strides, + const std::vector &padding_before, + const std::vector &padding_after, bool include_pad, + DataFormat data_format) + : Operation(Type::avgPool2D, {arg}), _window_size(window_size), _strides(strides), + _padding_before(padding_before), _padding_after(padding_after), _include_pad(include_pad), _data_format(data_format) { inferOutputShapes(); diff --git a/compiler/mir/include/mir/ops/Conv2DOp.h b/compiler/mir/include/mir/ops/Conv2DOp.h index cfb9723..7acd2fd 100644 --- a/compiler/mir/include/mir/ops/Conv2DOp.h +++ b/compiler/mir/include/mir/ops/Conv2DOp.h @@ -29,11 +29,12 @@ namespace ops class Conv2DOp : public Operation { public: - Conv2DOp(Output *input, Output *kernel, const Shape &strides, std::vector padding_before, - std::vector padding_after, DataFormat data_format = DataFormat::NHWC) + Conv2DOp(Output *input, Output *kernel, const Shape &strides, + const std::vector &padding_before, + const std::vector &padding_after, + DataFormat data_format = DataFormat::NHWC) : Operation(Type::conv2D, {input, kernel}), _strides(strides), - _padding_before(std::move(padding_before)), _padding_after(std::move(padding_after)), - _data_format(data_format) + _padding_before(padding_before), _padding_after(padding_after), _data_format(data_format) { inferOutputShapes(); } diff --git a/compiler/mir/include/mir/ops/DepthwiseConv2DOp.h b/compiler/mir/include/mir/ops/DepthwiseConv2DOp.h index 6198a72..e4c9790 100644 --- a/compiler/mir/include/mir/ops/DepthwiseConv2DOp.h +++ b/compiler/mir/include/mir/ops/DepthwiseConv2DOp.h @@ -30,11 +30,11 @@ class DepthwiseConv2DOp : public Operation { public: DepthwiseConv2DOp(Output *input, Output *kernel, const Shape &strides, - std::vector padding_before, std::vector padding_after, + const std::vector &padding_before, + const std::vector &padding_after, DataFormat data_format = DataFormat::NHWC) : Operation(Type::depthwiseConv, {input, kernel}), _strides(strides), - _padding_before(std::move(padding_before)), _padding_after(std::move(padding_after)), - _data_format(data_format) + _padding_before(padding_before), _padding_after(padding_after), _data_format(data_format) { inferOutputShapes(); } diff --git a/compiler/mir/include/mir/ops/MaxPool2DOp.h b/compiler/mir/include/mir/ops/MaxPool2DOp.h index 691fad4..2a9d55c 100644 --- a/compiler/mir/include/mir/ops/MaxPool2DOp.h +++ b/compiler/mir/include/mir/ops/MaxPool2DOp.h @@ -31,12 +31,12 @@ namespace ops class MaxPool2DOp : public Operation { public: - MaxPool2DOp(Output *arg, std::vector window_size, std::vector strides, - std::vector padding_before, std::vector padding_after, - DataFormat data_format) - : Operation(Type::maxPool2D, {arg}), _window_size(std::move(window_size)), - _strides(std::move(strides)), _padding_before(std::move(padding_before)), - _padding_after(std::move(padding_after)), _data_format(data_format) + MaxPool2DOp(Output *arg, const std::vector &window_size, + const std::vector &strides, + const std::vector &padding_before, + const std::vector &padding_after, DataFormat data_format) + : Operation(Type::maxPool2D, {arg}), _window_size(window_size), _strides(strides), + _padding_before(padding_before), _padding_after(padding_after), _data_format(data_format) { inferOutputShapes(); } diff --git a/compiler/mir/include/mir/ops/PadOp.h b/compiler/mir/include/mir/ops/PadOp.h index e1e59f3..1b109e5 100644 --- a/compiler/mir/include/mir/ops/PadOp.h +++ b/compiler/mir/include/mir/ops/PadOp.h @@ -31,10 +31,10 @@ public: /// @param padding_before The padding to be added before the tensor. /// @param padding_after The padding to be added after the tensor. /// @param padding_value The value to be used for padding. - PadOp(Output *arg, std::vector padding_before, - std::vector padding_after, float padding_value) - : Operation(Type::pad, {arg}), _padding_before(std::move(padding_before)), - _padding_after(std::move(padding_after)), _padding_value(padding_value) + PadOp(Output *arg, const std::vector &padding_before, + const std::vector &padding_after, float padding_value) + : Operation(Type::pad, {arg}), _padding_before(padding_before), _padding_after(padding_after), + _padding_value(padding_value) { assert(_padding_before.size() == _padding_after.size()); inferOutputShapes(); diff --git a/compiler/mir/include/mir/ops/ReduceMeanOp.h b/compiler/mir/include/mir/ops/ReduceMeanOp.h index 957bd7e..add47ac 100644 --- a/compiler/mir/include/mir/ops/ReduceMeanOp.h +++ b/compiler/mir/include/mir/ops/ReduceMeanOp.h @@ -28,8 +28,8 @@ namespace ops class ReduceMeanOp : public ReduceOp { public: - ReduceMeanOp(Output *arg, std::vector reduction_dims, bool keep_dims) - : ReduceOp(Type::reduceMean, arg, std::move(reduction_dims), keep_dims) + ReduceMeanOp(Output *arg, const std::vector &reduction_dims, bool keep_dims) + : ReduceOp(Type::reduceMean, arg, reduction_dims, keep_dims) { } diff --git a/compiler/mir/include/mir/ops/ReduceOp.h b/compiler/mir/include/mir/ops/ReduceOp.h index a9171a1..f8a2de8 100644 --- a/compiler/mir/include/mir/ops/ReduceOp.h +++ b/compiler/mir/include/mir/ops/ReduceOp.h @@ -28,8 +28,8 @@ namespace ops class ReduceOp : public Operation { protected: - ReduceOp(Type type, Output *arg, std::vector reduction_dims, bool keep_dims) - : Operation(type, {arg}), _reduction_dims(std::move(reduction_dims)), _keep_dims(keep_dims) + ReduceOp(Type type, Output *arg, const std::vector &reduction_dims, bool keep_dims) + : Operation(type, {arg}), _reduction_dims(reduction_dims), _keep_dims(keep_dims) { inferOutputShapes(); } diff --git a/compiler/mir/include/mir/ops/ResizeOp.h b/compiler/mir/include/mir/ops/ResizeOp.h index a8ca393..d4ef4a2 100644 --- a/compiler/mir/include/mir/ops/ResizeOp.h +++ b/compiler/mir/include/mir/ops/ResizeOp.h @@ -39,8 +39,8 @@ public: nearestNeighbor, // TODO: BICUBIC and BILINEAR }; - ResizeOp(Output *arg, ResizeMethod mode, std::vector scales) - : Operation(Type::resizeIm, {arg}), _mode(mode), _scales(std::move(scales)) + ResizeOp(Output *arg, ResizeMethod mode, const std::vector &scales) + : Operation(Type::resizeIm, {arg}), _mode(mode), _scales(scales) { // Infer output shape based on given scales. auto &input_shape = getInputShape(0); diff --git a/compiler/mir/include/mir/ops/SqueezeOp.h b/compiler/mir/include/mir/ops/SqueezeOp.h index bc90e8c..23e119e 100644 --- a/compiler/mir/include/mir/ops/SqueezeOp.h +++ b/compiler/mir/include/mir/ops/SqueezeOp.h @@ -28,8 +28,8 @@ namespace ops class SqueezeOp : public Operation { public: - SqueezeOp(Output *arg, std::vector dims_to_squeeze) - : Operation(Type::squeeze, {arg}), _dims_to_squeeze(std::move(dims_to_squeeze)) + SqueezeOp(Output *arg, const std::vector &dims_to_squeeze) + : Operation(Type::squeeze, {arg}), _dims_to_squeeze(dims_to_squeeze) { // Infer output shape. inferOutputShapes(); diff --git a/compiler/mir/include/mir/ops/TransposeOp.h b/compiler/mir/include/mir/ops/TransposeOp.h index 001eedf..53fa084 100644 --- a/compiler/mir/include/mir/ops/TransposeOp.h +++ b/compiler/mir/include/mir/ops/TransposeOp.h @@ -33,7 +33,7 @@ namespace ops class TransposeOp : public Operation { public: - TransposeOp(Output *arg, std::vector axis_order); + TransposeOp(Output *arg, const std::vector &axis_order); const std::vector &getAxisOrder() const { return _axis_order; } diff --git a/compiler/mir/src/ops/TransposeOp.cpp b/compiler/mir/src/ops/TransposeOp.cpp index 9d7f1ea..d626506 100644 --- a/compiler/mir/src/ops/TransposeOp.cpp +++ b/compiler/mir/src/ops/TransposeOp.cpp @@ -21,8 +21,8 @@ namespace mir namespace ops { -TransposeOp::TransposeOp(Output *arg, std::vector axis_order) - : Operation(Type::transpose, {arg}), _axis_order(std::move(axis_order)) +TransposeOp::TransposeOp(Output *arg, const std::vector &axis_order) + : Operation(Type::transpose, {arg}), _axis_order(axis_order) { assert(_axis_order.size() == static_cast(getInputShape(0).rank())); inferOutputShapes(); @@ -33,7 +33,7 @@ void TransposeOp::inferOutputShapes() auto &input_shape = getInputShape(0); Shape output_shape(input_shape.rank()); for (std::size_t i = 0; i < _axis_order.size(); ++i) - output_shape.dim(static_cast(i)) = + output_shape.dim(static_cast(i)) = input_shape.dim(static_cast(_axis_order.at(i))); setOutputShape(0, output_shape); } diff --git a/compiler/mir/unittests/ShapeRange.cpp b/compiler/mir/unittests/ShapeRange.cpp index 30d151b..3b32d0c 100644 --- a/compiler/mir/unittests/ShapeRange.cpp +++ b/compiler/mir/unittests/ShapeRange.cpp @@ -75,4 +75,4 @@ TEST(ShapeRange, Contains) ASSERT_TRUE(range.contains(idx)); } } -} +} // namespace