handle redundant slice in SliceOp

pull/17144/head
YashasSamaga 5 years ago
parent 51a42c0647
commit aff2c7c43c
  1. 18
      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 <opencv2/core.hpp>
#include <cstddef>
#include <vector>
#include <algorithm>
#include <utility>
namespace cv { namespace dnn { namespace cuda4dnn {
@ -43,6 +45,22 @@ namespace cv { namespace dnn { namespace cuda4dnn {
auto input_wrapper = inputs[0].dynamicCast<wrapper_type>();
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<wrapper_type>();
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<T>(stream, output, input);
return;
}
}
for (int i = 0; i < outputs.size(); ++i)
{
auto output_wrapper = outputs[i].dynamicCast<wrapper_type>();

Loading…
Cancel
Save