Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of gr-peach-opencv-project-sd-card by
private.cuda.hpp
00001 /*M/////////////////////////////////////////////////////////////////////////////////////// 00002 // 00003 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. 00004 // 00005 // By downloading, copying, installing or using the software you agree to this license. 00006 // If you do not agree to this license, do not download, install, 00007 // copy or use the software. 00008 // 00009 // 00010 // License Agreement 00011 // For Open Source Computer Vision Library 00012 // 00013 // Copyright (C) 2000-2008, Intel Corporation, all rights reserved. 00014 // Copyright (C) 2009, Willow Garage Inc., all rights reserved. 00015 // Copyright (C) 2013, OpenCV Foundation, all rights reserved. 00016 // Third party copyrights are property of their respective owners. 00017 // 00018 // Redistribution and use in source and binary forms, with or without modification, 00019 // are permitted provided that the following conditions are met: 00020 // 00021 // * Redistribution's of source code must retain the above copyright notice, 00022 // this list of conditions and the following disclaimer. 00023 // 00024 // * Redistribution's in binary form must reproduce the above copyright notice, 00025 // this list of conditions and the following disclaimer in the documentation 00026 // and/or other materials provided with the distribution. 00027 // 00028 // * The name of the copyright holders may not be used to endorse or promote products 00029 // derived from this software without specific prior written permission. 00030 // 00031 // This software is provided by the copyright holders and contributors "as is" and 00032 // any express or implied warranties, including, but not limited to, the implied 00033 // warranties of merchantability and fitness for a particular purpose are disclaimed. 00034 // In no event shall the Intel Corporation or contributors be liable for any direct, 00035 // indirect, incidental, special, exemplary, or consequential damages 00036 // (including, but not limited to, procurement of substitute goods or services; 00037 // loss of use, data, or profits; or business interruption) however caused 00038 // and on any theory of liability, whether in contract, strict liability, 00039 // or tort (including negligence or otherwise) arising in any way out of 00040 // the use of this software, even if advised of the possibility of such damage. 00041 // 00042 //M*/ 00043 00044 #ifndef __OPENCV_CORE_PRIVATE_CUDA_HPP__ 00045 #define __OPENCV_CORE_PRIVATE_CUDA_HPP__ 00046 00047 #ifndef __OPENCV_BUILD 00048 //# error this is a private header which should not be used from outside of the OpenCV library 00049 #endif 00050 00051 #include "cvconfig.h" 00052 00053 #include "opencv2/core/cvdef.h" 00054 #include "opencv2/core/base.hpp" 00055 00056 #ifdef HAVE_CUDA 00057 #include "opencv2/core/cuda.hpp" 00058 #endif 00059 00060 #ifdef HAVE_CUDA 00061 # include <cuda.h> 00062 # include <cuda_runtime.h> 00063 # include <npp.h> 00064 # include "opencv2/core/cuda_stream_accessor.hpp" 00065 # include "opencv2/core/cuda/common.hpp " 00066 00067 # define NPP_VERSION (NPP_VERSION_MAJOR * 1000 + NPP_VERSION_MINOR * 100 + NPP_VERSION_BUILD) 00068 00069 # define CUDART_MINIMUM_REQUIRED_VERSION 4020 00070 00071 # if (CUDART_VERSION < CUDART_MINIMUM_REQUIRED_VERSION) 00072 # error "Insufficient Cuda Runtime library version, please update it." 00073 # endif 00074 00075 # if defined(CUDA_ARCH_BIN_OR_PTX_10) 00076 # error "OpenCV CUDA module doesn't support NVIDIA compute capability 1.0" 00077 # endif 00078 #endif 00079 00080 //! @cond IGNORED 00081 00082 namespace cv { namespace cuda { 00083 CV_EXPORTS cv::String getNppErrorMessage(int code); 00084 CV_EXPORTS cv::String getCudaDriverApiErrorMessage(int code); 00085 00086 CV_EXPORTS GpuMat getInputMat(InputArray _src, Stream& stream); 00087 00088 CV_EXPORTS GpuMat getOutputMat(OutputArray _dst, int rows, int cols, int type, Stream& stream); 00089 #ifdef HAVE_CUDA 00090 static inline GpuMat getOutputMat(OutputArray _dst, Size size, int type, Stream& stream) 00091 { 00092 return getOutputMat(_dst, size.height, size.width, type, stream); 00093 } 00094 #endif 00095 00096 CV_EXPORTS void syncOutput(const GpuMat& dst, OutputArray _dst, Stream& stream); 00097 }} 00098 00099 #ifndef HAVE_CUDA 00100 00101 static inline void throw_no_cuda() { CV_Error(cv::Error::GpuNotSupported, "The library is compiled without CUDA support"); } 00102 00103 #else // HAVE_CUDA 00104 00105 static inline void throw_no_cuda() { CV_Error(cv::Error::StsNotImplemented, "The called functionality is disabled for current build or platform"); } 00106 00107 namespace cv { namespace cuda 00108 { 00109 class CV_EXPORTS BufferPool 00110 { 00111 public: 00112 explicit BufferPool(Stream& stream); 00113 00114 GpuMat getBuffer(int rows, int cols, int type); 00115 GpuMat getBuffer(Size size, int type) { return getBuffer(size.height, size.width, type); } 00116 00117 GpuMat::Allocator* getAllocator() const { return allocator_; } 00118 00119 private: 00120 GpuMat::Allocator* allocator_; 00121 }; 00122 00123 static inline void checkNppError(int code, const char* file, const int line, const char* func) 00124 { 00125 if (code < 0) 00126 cv::error(cv::Error::GpuApiCallError, getNppErrorMessage(code), func, file, line); 00127 } 00128 00129 static inline void checkCudaDriverApiError(int code, const char* file, const int line, const char* func) 00130 { 00131 if (code != CUDA_SUCCESS) 00132 cv::error(cv::Error::GpuApiCallError, getCudaDriverApiErrorMessage(code), func, file, line); 00133 } 00134 00135 template<int n> struct NPPTypeTraits; 00136 template<> struct NPPTypeTraits<CV_8U> { typedef Npp8u npp_type; }; 00137 template<> struct NPPTypeTraits<CV_8S> { typedef Npp8s npp_type; }; 00138 template<> struct NPPTypeTraits<CV_16U> { typedef Npp16u npp_type; }; 00139 template<> struct NPPTypeTraits<CV_16S> { typedef Npp16s npp_type; }; 00140 template<> struct NPPTypeTraits<CV_32S> { typedef Npp32s npp_type; }; 00141 template<> struct NPPTypeTraits<CV_32F> { typedef Npp32f npp_type; }; 00142 template<> struct NPPTypeTraits<CV_64F> { typedef Npp64f npp_type; }; 00143 00144 class NppStreamHandler 00145 { 00146 public: 00147 inline explicit NppStreamHandler(Stream& newStream) 00148 { 00149 oldStream = nppGetStream(); 00150 nppSetStream(StreamAccessor::getStream(newStream)); 00151 } 00152 00153 inline explicit NppStreamHandler(cudaStream_t newStream) 00154 { 00155 oldStream = nppGetStream(); 00156 nppSetStream(newStream); 00157 } 00158 00159 inline ~NppStreamHandler() 00160 { 00161 nppSetStream(oldStream); 00162 } 00163 00164 private: 00165 cudaStream_t oldStream; 00166 }; 00167 }} 00168 00169 #define nppSafeCall(expr) cv::cuda::checkNppError(expr, __FILE__, __LINE__, CV_Func) 00170 #define cuSafeCall(expr) cv::cuda::checkCudaDriverApiError(expr, __FILE__, __LINE__, CV_Func) 00171 00172 #endif // HAVE_CUDA 00173 00174 //! @endcond 00175 00176 #endif // __OPENCV_CORE_CUDA_PRIVATE_HPP__ 00177
Generated on Tue Jul 12 2022 14:47:32 by
1.7.2
