From aff2c7c43c97620b73a4ce42a75ec40cad66fdb9 Mon Sep 17 00:00:00 2001 From: YashasSamaga Date: Fri, 24 Apr 2020 12:54:17 +0530 Subject: [PATCH] handle redundant slice in SliceOp --- modules/dnn/src/cuda4dnn/primitives/slice.hpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/modules/dnn/src/cuda4dnn/primitives/slice.hpp b/modules/dnn/src/cuda4dnn/primitives/slice.hpp index e5847d763728..900b580b45ac 100644 --- a/modules/dnn/src/cuda4dnn/primitives/slice.hpp +++ b/modules/dnn/src/cuda4dnn/primitives/slice.hpp @@ -10,11 +10,13 @@ #include "../csl/stream.hpp" #include "../kernels/slice.hpp" +#include "../kernels/fill_copy.hpp" #include #include #include +#include #include namespace cv { namespace dnn { namespace cuda4dnn { @@ -43,6 +45,22 @@ namespace cv { namespace dnn { namespace cuda4dnn { auto input_wrapper = inputs[0].dynamicCast(); auto input = input_wrapper->getView(); + CV_Assert(offsets.size() == outputs.size()); + + /* one output with the same shape as the input => direct copy */ + if (outputs.size() == 1) + { + auto output_wrapper = outputs[0].dynamicCast(); + auto output = output_wrapper->getSpan(); + + if (is_shape_same(output, input)) + { + CV_Assert(std::all_of(std::begin(offsets[0]), std::end(offsets[0]), [] (std::size_t x) { return x == 0; })); + kernels::copy(stream, output, input); + return; + } + } + for (int i = 0; i < outputs.size(); ++i) { auto output_wrapper = outputs[i].dynamicCast();