opencv on mbed

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers private.cuda.hpp Source File

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 #include "opencv2/core/cuda.hpp"
00057 
00058 #ifdef HAVE_CUDA
00059 #  include <cuda.h>
00060 #  include <cuda_runtime.h>
00061 #  include <npp.h>
00062 #  include "opencv2/core/cuda_stream_accessor.hpp"
00063 #  include "opencv2/core/cuda/common.hpp"
00064 
00065 #  define NPP_VERSION (NPP_VERSION_MAJOR * 1000 + NPP_VERSION_MINOR * 100 + NPP_VERSION_BUILD)
00066 
00067 #  define CUDART_MINIMUM_REQUIRED_VERSION 4020
00068 
00069 #  if (CUDART_VERSION < CUDART_MINIMUM_REQUIRED_VERSION)
00070 #    error "Insufficient Cuda Runtime library version, please update it."
00071 #  endif
00072 
00073 #  if defined(CUDA_ARCH_BIN_OR_PTX_10)
00074 #    error "OpenCV CUDA module doesn't support NVIDIA compute capability 1.0"
00075 #  endif
00076 #endif
00077 
00078 //! @cond IGNORED
00079 
00080 namespace cv { namespace cuda {
00081     CV_EXPORTS cv::String getNppErrorMessage(int code);
00082     CV_EXPORTS cv::String getCudaDriverApiErrorMessage(int code);
00083 
00084     CV_EXPORTS GpuMat getInputMat(InputArray _src, Stream& stream);
00085 
00086     CV_EXPORTS GpuMat getOutputMat(OutputArray _dst, int rows, int cols, int type, Stream& stream);
00087     static inline GpuMat getOutputMat(OutputArray _dst, Size size, int type, Stream& stream)
00088     {
00089         return getOutputMat(_dst, size.height, size.width, type, stream);
00090     }
00091 
00092     CV_EXPORTS void syncOutput(const GpuMat& dst, OutputArray _dst, Stream& stream);
00093 }}
00094 
00095 #ifndef HAVE_CUDA
00096 
00097 static inline void throw_no_cuda() { CV_Error(cv::Error::GpuNotSupported, "The library is compiled without CUDA support"); }
00098 
00099 #else // HAVE_CUDA
00100 
00101 static inline void throw_no_cuda() { CV_Error(cv::Error::StsNotImplemented, "The called functionality is disabled for current build or platform"); }
00102 
00103 namespace cv { namespace cuda
00104 {
00105     class CV_EXPORTS BufferPool
00106     {
00107     public:
00108         explicit BufferPool(Stream& stream);
00109 
00110         GpuMat getBuffer(int rows, int cols, int type);
00111         GpuMat getBuffer(Size size, int type) { return getBuffer(size.height, size.width, type); }
00112 
00113         GpuMat::Allocator* getAllocator() const { return allocator_; }
00114 
00115     private:
00116         GpuMat::Allocator* allocator_;
00117     };
00118 
00119     static inline void checkNppError(int code, const char* file, const int line, const char* func)
00120     {
00121         if (code < 0)
00122             cv::error(cv::Error::GpuApiCallError, getNppErrorMessage(code), func, file, line);
00123     }
00124 
00125     static inline void checkCudaDriverApiError(int code, const char* file, const int line, const char* func)
00126     {
00127         if (code != CUDA_SUCCESS)
00128             cv::error(cv::Error::GpuApiCallError, getCudaDriverApiErrorMessage(code), func, file, line);
00129     }
00130 
00131     template<int n> struct NPPTypeTraits;
00132     template<> struct NPPTypeTraits<CV_8U>  { typedef Npp8u npp_type; };
00133     template<> struct NPPTypeTraits<CV_8S>  { typedef Npp8s npp_type; };
00134     template<> struct NPPTypeTraits<CV_16U> { typedef Npp16u npp_type; };
00135     template<> struct NPPTypeTraits<CV_16S> { typedef Npp16s npp_type; };
00136     template<> struct NPPTypeTraits<CV_32S> { typedef Npp32s npp_type; };
00137     template<> struct NPPTypeTraits<CV_32F> { typedef Npp32f npp_type; };
00138     template<> struct NPPTypeTraits<CV_64F> { typedef Npp64f npp_type; };
00139 
00140     class NppStreamHandler
00141     {
00142     public:
00143         inline explicit NppStreamHandler(Stream& newStream)
00144         {
00145             oldStream = nppGetStream();
00146             nppSetStream(StreamAccessor::getStream(newStream));
00147         }
00148 
00149         inline explicit NppStreamHandler(cudaStream_t newStream)
00150         {
00151             oldStream = nppGetStream();
00152             nppSetStream(newStream);
00153         }
00154 
00155         inline ~NppStreamHandler()
00156         {
00157             nppSetStream(oldStream);
00158         }
00159 
00160     private:
00161         cudaStream_t oldStream;
00162     };
00163 }}
00164 
00165 #define nppSafeCall(expr)  cv::cuda::checkNppError(expr, __FILE__, __LINE__, CV_Func)
00166 #define cuSafeCall(expr)  cv::cuda::checkCudaDriverApiError(expr, __FILE__, __LINE__, CV_Func)
00167 
00168 #endif // HAVE_CUDA
00169 
00170 //! @endcond
00171 
00172 #endif // __OPENCV_CORE_CUDA_PRIVATE_HPP__
00173