Merge pull request #14827 from YashasSamaga:cuda4dnn-csl-low
[platform/upstream/opencv.git] / modules / dnn / src / cuda4dnn / primitives / split.hpp
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.
4
5 #ifndef OPENCV_DNN_SRC_CUDA4DNN_PRIMITIVES_SPLIT_HPP
6 #define OPENCV_DNN_SRC_CUDA4DNN_PRIMITIVES_SPLIT_HPP
7
8 #include "../../op_cuda.hpp"
9
10 #include "../csl/stream.hpp"
11 #include "../csl/tensor_ops.hpp"
12
13 #include <opencv2/core.hpp>
14
15 #include <utility>
16
17 namespace cv { namespace dnn { namespace cuda4dnn {
18
19     template <class T>
20     class SplitOp final : public CUDABackendNode {
21     public:
22         using wrapper_type = GetCUDABackendWrapperType<T>;
23
24         SplitOp(csl::Stream stream_)
25             : stream(std::move(stream_))
26         {
27         }
28
29         void forward(
30             const std::vector<cv::Ptr<BackendWrapper>>& inputs,
31             const std::vector<cv::Ptr<BackendWrapper>>& outputs,
32             csl::Workspace& workspace) override
33         {
34             CV_Assert(inputs.size() == 1);
35
36             auto input_wrapper = inputs[0].dynamicCast<wrapper_type>();
37             auto input = input_wrapper->getView();
38
39             for (int i = 0; i < outputs.size(); i++)
40             {
41                 auto output_wrapper = outputs[i].dynamicCast<wrapper_type>();
42                 auto output = output_wrapper->getSpan();
43
44                 csl::tensor_ops::copy<T>(stream, output, input);
45             }
46         }
47
48     private:
49         csl::Stream stream;
50     };
51
52 }}} /* namespace cv::dnn::cuda4dnn */
53
54 #endif /* OPENCV_DNN_SRC_CUDA4DNN_PRIMITIVES_SPLIT_HPP */