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_SOFTMAX_HPP
6 #define OPENCV_DNN_SRC_CUDA4DNN_PRIMITIVES_SOFTMAX_HPP
8 #include "../../op_cuda.hpp"
10 #include "../csl/cudnn.hpp"
11 #include "../csl/tensor_ops.hpp"
16 namespace cv { namespace dnn { namespace cuda4dnn {
19 class SoftmaxOp final : public CUDABackendNode {
21 using wrapper_type = GetCUDABackendWrapperType<T>;
23 SoftmaxOp(csl::cudnn::Handle handle, std::size_t axis_, bool log_)
24 : cudnnHandle(std::move(handle)), channel_axis{ axis_ }, log{ log_ }
29 const std::vector<cv::Ptr<BackendWrapper>>& inputs,
30 const std::vector<cv::Ptr<BackendWrapper>>& outputs,
31 csl::Workspace& workspace) override
33 for (int i = 0; i < inputs.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 csl::tensor_ops::softmax<T>(cudnnHandle, output, input, channel_axis, log);
46 csl::cudnn::Handle cudnnHandle;
47 std::size_t channel_axis;
51 }}} /* namespace cv::dnn::cuda4dnn */
53 #endif /* OPENCV_DNN_SRC_CUDA4DNN_PRIMITIVES_SOFTMAX_HPP */