openCV library for Renesas RZ/A
Dependents: RZ_A2M_Mbed_samples
include/opencv2/core/private.cuda.hpp@0:0e0631af0305, 2021-01-29 (annotated)
- Committer:
- RyoheiHagimoto
- Date:
- Fri Jan 29 04:53:38 2021 +0000
- Revision:
- 0:0e0631af0305
copied from https://github.com/d-kato/opencv-lib.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
RyoheiHagimoto | 0:0e0631af0305 | 1 | /*M/////////////////////////////////////////////////////////////////////////////////////// |
RyoheiHagimoto | 0:0e0631af0305 | 2 | // |
RyoheiHagimoto | 0:0e0631af0305 | 3 | // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. |
RyoheiHagimoto | 0:0e0631af0305 | 4 | // |
RyoheiHagimoto | 0:0e0631af0305 | 5 | // By downloading, copying, installing or using the software you agree to this license. |
RyoheiHagimoto | 0:0e0631af0305 | 6 | // If you do not agree to this license, do not download, install, |
RyoheiHagimoto | 0:0e0631af0305 | 7 | // copy or use the software. |
RyoheiHagimoto | 0:0e0631af0305 | 8 | // |
RyoheiHagimoto | 0:0e0631af0305 | 9 | // |
RyoheiHagimoto | 0:0e0631af0305 | 10 | // License Agreement |
RyoheiHagimoto | 0:0e0631af0305 | 11 | // For Open Source Computer Vision Library |
RyoheiHagimoto | 0:0e0631af0305 | 12 | // |
RyoheiHagimoto | 0:0e0631af0305 | 13 | // Copyright (C) 2000-2008, Intel Corporation, all rights reserved. |
RyoheiHagimoto | 0:0e0631af0305 | 14 | // Copyright (C) 2009, Willow Garage Inc., all rights reserved. |
RyoheiHagimoto | 0:0e0631af0305 | 15 | // Copyright (C) 2013, OpenCV Foundation, all rights reserved. |
RyoheiHagimoto | 0:0e0631af0305 | 16 | // Third party copyrights are property of their respective owners. |
RyoheiHagimoto | 0:0e0631af0305 | 17 | // |
RyoheiHagimoto | 0:0e0631af0305 | 18 | // Redistribution and use in source and binary forms, with or without modification, |
RyoheiHagimoto | 0:0e0631af0305 | 19 | // are permitted provided that the following conditions are met: |
RyoheiHagimoto | 0:0e0631af0305 | 20 | // |
RyoheiHagimoto | 0:0e0631af0305 | 21 | // * Redistribution's of source code must retain the above copyright notice, |
RyoheiHagimoto | 0:0e0631af0305 | 22 | // this list of conditions and the following disclaimer. |
RyoheiHagimoto | 0:0e0631af0305 | 23 | // |
RyoheiHagimoto | 0:0e0631af0305 | 24 | // * Redistribution's in binary form must reproduce the above copyright notice, |
RyoheiHagimoto | 0:0e0631af0305 | 25 | // this list of conditions and the following disclaimer in the documentation |
RyoheiHagimoto | 0:0e0631af0305 | 26 | // and/or other materials provided with the distribution. |
RyoheiHagimoto | 0:0e0631af0305 | 27 | // |
RyoheiHagimoto | 0:0e0631af0305 | 28 | // * The name of the copyright holders may not be used to endorse or promote products |
RyoheiHagimoto | 0:0e0631af0305 | 29 | // derived from this software without specific prior written permission. |
RyoheiHagimoto | 0:0e0631af0305 | 30 | // |
RyoheiHagimoto | 0:0e0631af0305 | 31 | // This software is provided by the copyright holders and contributors "as is" and |
RyoheiHagimoto | 0:0e0631af0305 | 32 | // any express or implied warranties, including, but not limited to, the implied |
RyoheiHagimoto | 0:0e0631af0305 | 33 | // warranties of merchantability and fitness for a particular purpose are disclaimed. |
RyoheiHagimoto | 0:0e0631af0305 | 34 | // In no event shall the Intel Corporation or contributors be liable for any direct, |
RyoheiHagimoto | 0:0e0631af0305 | 35 | // indirect, incidental, special, exemplary, or consequential damages |
RyoheiHagimoto | 0:0e0631af0305 | 36 | // (including, but not limited to, procurement of substitute goods or services; |
RyoheiHagimoto | 0:0e0631af0305 | 37 | // loss of use, data, or profits; or business interruption) however caused |
RyoheiHagimoto | 0:0e0631af0305 | 38 | // and on any theory of liability, whether in contract, strict liability, |
RyoheiHagimoto | 0:0e0631af0305 | 39 | // or tort (including negligence or otherwise) arising in any way out of |
RyoheiHagimoto | 0:0e0631af0305 | 40 | // the use of this software, even if advised of the possibility of such damage. |
RyoheiHagimoto | 0:0e0631af0305 | 41 | // |
RyoheiHagimoto | 0:0e0631af0305 | 42 | //M*/ |
RyoheiHagimoto | 0:0e0631af0305 | 43 | |
RyoheiHagimoto | 0:0e0631af0305 | 44 | #ifndef OPENCV_CORE_PRIVATE_CUDA_HPP |
RyoheiHagimoto | 0:0e0631af0305 | 45 | #define OPENCV_CORE_PRIVATE_CUDA_HPP |
RyoheiHagimoto | 0:0e0631af0305 | 46 | |
RyoheiHagimoto | 0:0e0631af0305 | 47 | #ifndef __OPENCV_BUILD |
RyoheiHagimoto | 0:0e0631af0305 | 48 | # error this is a private header which should not be used from outside of the OpenCV library |
RyoheiHagimoto | 0:0e0631af0305 | 49 | #endif |
RyoheiHagimoto | 0:0e0631af0305 | 50 | |
RyoheiHagimoto | 0:0e0631af0305 | 51 | #include "cvconfig.h" |
RyoheiHagimoto | 0:0e0631af0305 | 52 | |
RyoheiHagimoto | 0:0e0631af0305 | 53 | #include "opencv2/core/cvdef.h" |
RyoheiHagimoto | 0:0e0631af0305 | 54 | #include "opencv2/core/base.hpp" |
RyoheiHagimoto | 0:0e0631af0305 | 55 | |
RyoheiHagimoto | 0:0e0631af0305 | 56 | #include "opencv2/core/cuda.hpp" |
RyoheiHagimoto | 0:0e0631af0305 | 57 | |
RyoheiHagimoto | 0:0e0631af0305 | 58 | #ifdef HAVE_CUDA |
RyoheiHagimoto | 0:0e0631af0305 | 59 | # include <cuda.h> |
RyoheiHagimoto | 0:0e0631af0305 | 60 | # include <cuda_runtime.h> |
RyoheiHagimoto | 0:0e0631af0305 | 61 | # include <npp.h> |
RyoheiHagimoto | 0:0e0631af0305 | 62 | # include "opencv2/core/cuda_stream_accessor.hpp" |
RyoheiHagimoto | 0:0e0631af0305 | 63 | # include "opencv2/core/cuda/common.hpp" |
RyoheiHagimoto | 0:0e0631af0305 | 64 | |
RyoheiHagimoto | 0:0e0631af0305 | 65 | # define NPP_VERSION (NPP_VERSION_MAJOR * 1000 + NPP_VERSION_MINOR * 100 + NPP_VERSION_BUILD) |
RyoheiHagimoto | 0:0e0631af0305 | 66 | |
RyoheiHagimoto | 0:0e0631af0305 | 67 | # define CUDART_MINIMUM_REQUIRED_VERSION 6050 |
RyoheiHagimoto | 0:0e0631af0305 | 68 | |
RyoheiHagimoto | 0:0e0631af0305 | 69 | # if (CUDART_VERSION < CUDART_MINIMUM_REQUIRED_VERSION) |
RyoheiHagimoto | 0:0e0631af0305 | 70 | # error "Insufficient Cuda Runtime library version, please update it." |
RyoheiHagimoto | 0:0e0631af0305 | 71 | # endif |
RyoheiHagimoto | 0:0e0631af0305 | 72 | |
RyoheiHagimoto | 0:0e0631af0305 | 73 | # if defined(CUDA_ARCH_BIN_OR_PTX_10) |
RyoheiHagimoto | 0:0e0631af0305 | 74 | # error "OpenCV CUDA module doesn't support NVIDIA compute capability 1.0" |
RyoheiHagimoto | 0:0e0631af0305 | 75 | # endif |
RyoheiHagimoto | 0:0e0631af0305 | 76 | #endif |
RyoheiHagimoto | 0:0e0631af0305 | 77 | |
RyoheiHagimoto | 0:0e0631af0305 | 78 | //! @cond IGNORED |
RyoheiHagimoto | 0:0e0631af0305 | 79 | |
RyoheiHagimoto | 0:0e0631af0305 | 80 | namespace cv { namespace cuda { |
RyoheiHagimoto | 0:0e0631af0305 | 81 | CV_EXPORTS cv::String getNppErrorMessage(int code); |
RyoheiHagimoto | 0:0e0631af0305 | 82 | CV_EXPORTS cv::String getCudaDriverApiErrorMessage(int code); |
RyoheiHagimoto | 0:0e0631af0305 | 83 | |
RyoheiHagimoto | 0:0e0631af0305 | 84 | CV_EXPORTS GpuMat getInputMat(InputArray _src, Stream& stream); |
RyoheiHagimoto | 0:0e0631af0305 | 85 | |
RyoheiHagimoto | 0:0e0631af0305 | 86 | CV_EXPORTS GpuMat getOutputMat(OutputArray _dst, int rows, int cols, int type, Stream& stream); |
RyoheiHagimoto | 0:0e0631af0305 | 87 | static inline GpuMat getOutputMat(OutputArray _dst, Size size, int type, Stream& stream) |
RyoheiHagimoto | 0:0e0631af0305 | 88 | { |
RyoheiHagimoto | 0:0e0631af0305 | 89 | return getOutputMat(_dst, size.height, size.width, type, stream); |
RyoheiHagimoto | 0:0e0631af0305 | 90 | } |
RyoheiHagimoto | 0:0e0631af0305 | 91 | |
RyoheiHagimoto | 0:0e0631af0305 | 92 | CV_EXPORTS void syncOutput(const GpuMat& dst, OutputArray _dst, Stream& stream); |
RyoheiHagimoto | 0:0e0631af0305 | 93 | }} |
RyoheiHagimoto | 0:0e0631af0305 | 94 | |
RyoheiHagimoto | 0:0e0631af0305 | 95 | #ifndef HAVE_CUDA |
RyoheiHagimoto | 0:0e0631af0305 | 96 | |
RyoheiHagimoto | 0:0e0631af0305 | 97 | static inline void throw_no_cuda() { CV_Error(cv::Error::GpuNotSupported, "The library is compiled without CUDA support"); } |
RyoheiHagimoto | 0:0e0631af0305 | 98 | |
RyoheiHagimoto | 0:0e0631af0305 | 99 | #else // HAVE_CUDA |
RyoheiHagimoto | 0:0e0631af0305 | 100 | |
RyoheiHagimoto | 0:0e0631af0305 | 101 | static inline void throw_no_cuda() { CV_Error(cv::Error::StsNotImplemented, "The called functionality is disabled for current build or platform"); } |
RyoheiHagimoto | 0:0e0631af0305 | 102 | |
RyoheiHagimoto | 0:0e0631af0305 | 103 | namespace cv { namespace cuda |
RyoheiHagimoto | 0:0e0631af0305 | 104 | { |
RyoheiHagimoto | 0:0e0631af0305 | 105 | class CV_EXPORTS BufferPool |
RyoheiHagimoto | 0:0e0631af0305 | 106 | { |
RyoheiHagimoto | 0:0e0631af0305 | 107 | public: |
RyoheiHagimoto | 0:0e0631af0305 | 108 | explicit BufferPool(Stream& stream); |
RyoheiHagimoto | 0:0e0631af0305 | 109 | |
RyoheiHagimoto | 0:0e0631af0305 | 110 | GpuMat getBuffer(int rows, int cols, int type); |
RyoheiHagimoto | 0:0e0631af0305 | 111 | GpuMat getBuffer(Size size, int type) { return getBuffer(size.height, size.width, type); } |
RyoheiHagimoto | 0:0e0631af0305 | 112 | |
RyoheiHagimoto | 0:0e0631af0305 | 113 | GpuMat::Allocator* getAllocator() const { return allocator_; } |
RyoheiHagimoto | 0:0e0631af0305 | 114 | |
RyoheiHagimoto | 0:0e0631af0305 | 115 | private: |
RyoheiHagimoto | 0:0e0631af0305 | 116 | GpuMat::Allocator* allocator_; |
RyoheiHagimoto | 0:0e0631af0305 | 117 | }; |
RyoheiHagimoto | 0:0e0631af0305 | 118 | |
RyoheiHagimoto | 0:0e0631af0305 | 119 | static inline void checkNppError(int code, const char* file, const int line, const char* func) |
RyoheiHagimoto | 0:0e0631af0305 | 120 | { |
RyoheiHagimoto | 0:0e0631af0305 | 121 | if (code < 0) |
RyoheiHagimoto | 0:0e0631af0305 | 122 | cv::error(cv::Error::GpuApiCallError, getNppErrorMessage(code), func, file, line); |
RyoheiHagimoto | 0:0e0631af0305 | 123 | } |
RyoheiHagimoto | 0:0e0631af0305 | 124 | |
RyoheiHagimoto | 0:0e0631af0305 | 125 | static inline void checkCudaDriverApiError(int code, const char* file, const int line, const char* func) |
RyoheiHagimoto | 0:0e0631af0305 | 126 | { |
RyoheiHagimoto | 0:0e0631af0305 | 127 | if (code != CUDA_SUCCESS) |
RyoheiHagimoto | 0:0e0631af0305 | 128 | cv::error(cv::Error::GpuApiCallError, getCudaDriverApiErrorMessage(code), func, file, line); |
RyoheiHagimoto | 0:0e0631af0305 | 129 | } |
RyoheiHagimoto | 0:0e0631af0305 | 130 | |
RyoheiHagimoto | 0:0e0631af0305 | 131 | template<int n> struct NPPTypeTraits; |
RyoheiHagimoto | 0:0e0631af0305 | 132 | template<> struct NPPTypeTraits<CV_8U> { typedef Npp8u npp_type; }; |
RyoheiHagimoto | 0:0e0631af0305 | 133 | template<> struct NPPTypeTraits<CV_8S> { typedef Npp8s npp_type; }; |
RyoheiHagimoto | 0:0e0631af0305 | 134 | template<> struct NPPTypeTraits<CV_16U> { typedef Npp16u npp_type; }; |
RyoheiHagimoto | 0:0e0631af0305 | 135 | template<> struct NPPTypeTraits<CV_16S> { typedef Npp16s npp_type; }; |
RyoheiHagimoto | 0:0e0631af0305 | 136 | template<> struct NPPTypeTraits<CV_32S> { typedef Npp32s npp_type; }; |
RyoheiHagimoto | 0:0e0631af0305 | 137 | template<> struct NPPTypeTraits<CV_32F> { typedef Npp32f npp_type; }; |
RyoheiHagimoto | 0:0e0631af0305 | 138 | template<> struct NPPTypeTraits<CV_64F> { typedef Npp64f npp_type; }; |
RyoheiHagimoto | 0:0e0631af0305 | 139 | |
RyoheiHagimoto | 0:0e0631af0305 | 140 | class NppStreamHandler |
RyoheiHagimoto | 0:0e0631af0305 | 141 | { |
RyoheiHagimoto | 0:0e0631af0305 | 142 | public: |
RyoheiHagimoto | 0:0e0631af0305 | 143 | inline explicit NppStreamHandler(Stream& newStream) |
RyoheiHagimoto | 0:0e0631af0305 | 144 | { |
RyoheiHagimoto | 0:0e0631af0305 | 145 | oldStream = nppGetStream(); |
RyoheiHagimoto | 0:0e0631af0305 | 146 | nppSetStream(StreamAccessor::getStream(newStream)); |
RyoheiHagimoto | 0:0e0631af0305 | 147 | } |
RyoheiHagimoto | 0:0e0631af0305 | 148 | |
RyoheiHagimoto | 0:0e0631af0305 | 149 | inline explicit NppStreamHandler(cudaStream_t newStream) |
RyoheiHagimoto | 0:0e0631af0305 | 150 | { |
RyoheiHagimoto | 0:0e0631af0305 | 151 | oldStream = nppGetStream(); |
RyoheiHagimoto | 0:0e0631af0305 | 152 | nppSetStream(newStream); |
RyoheiHagimoto | 0:0e0631af0305 | 153 | } |
RyoheiHagimoto | 0:0e0631af0305 | 154 | |
RyoheiHagimoto | 0:0e0631af0305 | 155 | inline ~NppStreamHandler() |
RyoheiHagimoto | 0:0e0631af0305 | 156 | { |
RyoheiHagimoto | 0:0e0631af0305 | 157 | nppSetStream(oldStream); |
RyoheiHagimoto | 0:0e0631af0305 | 158 | } |
RyoheiHagimoto | 0:0e0631af0305 | 159 | |
RyoheiHagimoto | 0:0e0631af0305 | 160 | private: |
RyoheiHagimoto | 0:0e0631af0305 | 161 | cudaStream_t oldStream; |
RyoheiHagimoto | 0:0e0631af0305 | 162 | }; |
RyoheiHagimoto | 0:0e0631af0305 | 163 | }} |
RyoheiHagimoto | 0:0e0631af0305 | 164 | |
RyoheiHagimoto | 0:0e0631af0305 | 165 | #define nppSafeCall(expr) cv::cuda::checkNppError(expr, __FILE__, __LINE__, CV_Func) |
RyoheiHagimoto | 0:0e0631af0305 | 166 | #define cuSafeCall(expr) cv::cuda::checkCudaDriverApiError(expr, __FILE__, __LINE__, CV_Func) |
RyoheiHagimoto | 0:0e0631af0305 | 167 | |
RyoheiHagimoto | 0:0e0631af0305 | 168 | #endif // HAVE_CUDA |
RyoheiHagimoto | 0:0e0631af0305 | 169 | |
RyoheiHagimoto | 0:0e0631af0305 | 170 | //! @endcond |
RyoheiHagimoto | 0:0e0631af0305 | 171 | |
RyoheiHagimoto | 0:0e0631af0305 | 172 | #endif // OPENCV_CORE_PRIVATE_CUDA_HPP |