1 // This file is part of OpenCV project.
2 // It is subject to the license terms in the LICENSE file found in the top-level directory
3 // of this distribution and at http://opencv.org/license.html.
5 #ifndef OPENCV_DNN_SRC_CUDA4DNN_PRIMITIVES_SLICE_HPP
6 #define OPENCV_DNN_SRC_CUDA4DNN_PRIMITIVES_SLICE_HPP
8 #include "../../op_cuda.hpp"
10 #include "../csl/stream.hpp"
12 #include "../kernels/slice.hpp"
14 #include <opencv2/core.hpp>
20 namespace cv { namespace dnn { namespace cuda4dnn {
23 class SliceOp final : public CUDABackendNode {
25 using wrapper_type = GetCUDABackendWrapperType<T>;
27 /* offsets is indexed by output number and each subvector is indexed by axis number */
28 SliceOp(csl::Stream stream_, std::vector<std::vector<std::size_t>> offsets)
29 : stream(std::move(stream_)), offsets(std::move(offsets))
34 const std::vector<cv::Ptr<BackendWrapper>>& inputs,
35 const std::vector<cv::Ptr<BackendWrapper>>& outputs,
36 csl::Workspace& workspace) override
38 /* sometimes the output shape is passed in the form of a second input tensor
39 * it's only required for initialization and not here
41 CV_Assert(inputs.size() == 1 || inputs.size() == 2);
43 auto input_wrapper = inputs[0].dynamicCast<wrapper_type>();
44 auto input = input_wrapper->getView();
46 for (int i = 0; i < outputs.size(); ++i)
48 auto output_wrapper = outputs[i].dynamicCast<wrapper_type>();
49 auto output = output_wrapper->getSpan();
51 kernels::slice<T>(stream, output, input, offsets[i]);
57 std::vector<std::vector<std::size_t>> offsets;
60 }}} /* namespace cv::dnn::cuda4dnn */
62 #endif /* OPENCV_DNN_SRC_CUDA4DNN_PRIMITIVES_SLICE_HPP */