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_RESHAPE_HPP
6 #define OPENCV_DNN_SRC_CUDA4DNN_PRIMITIVES_RESHAPE_HPP
8 #include "../../op_cuda.hpp"
10 #include "../csl/stream.hpp"
11 #include "../csl/tensor.hpp"
12 #include "../csl/tensor_ops.hpp"
16 namespace cv { namespace dnn { namespace cuda4dnn {
19 class ReshapeOp final : public CUDABackendNode {
21 using wrapper_type = GetCUDABackendWrapperType<T>;
23 ReshapeOp(csl::Stream stream_) : stream(std::move(stream_)) { }
26 const std::vector<cv::Ptr<BackendWrapper>>& inputs,
27 const std::vector<cv::Ptr<BackendWrapper>>& outputs,
28 csl::Workspace& workspace) override
30 /* sometimes the output shape is passed as extra inputs; hence, >= instead of == */
31 CV_Assert(inputs.size() >= outputs.size());
33 for (int i = 0; i < outputs.size(); i++)
35 auto input_wrapper = inputs[i].dynamicCast<wrapper_type>();
36 auto input = input_wrapper->getView();
38 auto output_wrapper = outputs[i].dynamicCast<wrapper_type>();
39 auto output = output_wrapper->getSpan();
41 if (input.get() != output.get())
43 while (input.rank() < output.rank())
46 while (output.rank() < input.rank())
49 input.reshape_as(output);
50 csl::tensor_ops::copy(stream, output, input);
59 }}} /* namespace cv::dnn::cuda4dnn */
61 #endif /* OPENCV_DNN_SRC_CUDA4DNN_PRIMITIVES_RESHAPE_HPP */