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_CONST_HPP
6 #define OPENCV_DNN_SRC_CUDA4DNN_PRIMITIVES_CONST_HPP
8 #include "../../op_cuda.hpp"
10 #include "../csl/stream.hpp"
11 #include "../csl/tensor.hpp"
12 #include "../csl/tensor_ops.hpp"
14 #include <opencv2/core.hpp>
18 namespace cv { namespace dnn { namespace cuda4dnn {
21 class ConstOp final : public CUDABackendNode {
23 using wrapper_type = GetCUDABackendWrapperType<T>;
25 ConstOp(csl::Stream stream_, const cv::Mat& data)
26 : stream(std::move(stream_))
28 constTensor = csl::makeTensorHeader<T>(data);
29 csl::copyMatToTensor<T>(data, constTensor, stream);
33 const std::vector<cv::Ptr<BackendWrapper>>& inputs,
34 const std::vector<cv::Ptr<BackendWrapper>>& outputs,
35 csl::Workspace& workspace) override
37 CV_Assert(outputs.size() == 1 && inputs.size() == 0);
39 auto output_wrapper = outputs[0].dynamicCast<wrapper_type>();
40 auto output = output_wrapper->getSpan();
41 csl::tensor_ops::copy<T>(stream, output, constTensor);
46 csl::Tensor<T> constTensor;
49 }}} /* namespace cv::dnn::cuda4dnn */
51 #endif /* OPENCV_DNN_SRC_CUDA4DNN_PRIMITIVES_CONST_HPP */