Skip to content

Commit

Permalink
handle redundant slice in SliceOp
Browse files Browse the repository at this point in the history
  • Loading branch information
YashasSamaga committed Apr 24, 2020
1 parent 51a42c0 commit aff2c7c
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions modules/dnn/src/cuda4dnn/primitives/slice.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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>();
Expand Down

0 comments on commit aff2c7c

Please sign in to comment.