common.hpp
Go to the documentation of this file.
1 /*M///////////////////////////////////////////////////////////////////////////////////////
2 //
3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
4 //
5 // By downloading, copying, installing or using the software you agree to this license.
6 // If you do not agree to this license, do not download, install,
7 // copy or use the software.
8 //
9 //
10 // License Agreement
11 // For Open Source Computer Vision Library
12 //
13 // Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
14 // Copyright (C) 2009, Willow Garage Inc., all rights reserved.
15 // Third party copyrights are property of their respective owners.
16 //
17 // Redistribution and use in source and binary forms, with or without modification,
18 // are permitted provided that the following conditions are met:
19 //
20 // * Redistribution's of source code must retain the above copyright notice,
21 // this list of conditions and the following disclaimer.
22 //
23 // * Redistribution's in binary form must reproduce the above copyright notice,
24 // this list of conditions and the following disclaimer in the documentation
25 // and/or other materials provided with the distribution.
26 //
27 // * The name of the copyright holders may not be used to endorse or promote products
28 // derived from this software without specific prior written permission.
29 //
30 // This software is provided by the copyright holders and contributors "as is" and
31 // any express or implied warranties, including, but not limited to, the implied
32 // warranties of merchantability and fitness for a particular purpose are disclaimed.
33 // In no event shall the Intel Corporation or contributors be liable for any direct,
34 // indirect, incidental, special, exemplary, or consequential damages
35 // (including, but not limited to, procurement of substitute goods or services;
36 // loss of use, data, or profits; or business interruption) however caused
37 // and on any theory of liability, whether in contract, strict liability,
38 // or tort (including negligence or otherwise) arising in any way out of
39 // the use of this software, even if advised of the possibility of such damage.
40 //
41 //M*/
42 
43 #ifndef __OPENCV_GPU_COMMON_HPP__
44 #define __OPENCV_GPU_COMMON_HPP__
45 
46 #include <cuda_runtime.h>
48 
49 #ifndef CV_PI
50  #define CV_PI 3.1415926535897932384626433832795
51 #endif
52 
53 #ifndef CV_PI_F
54  #ifndef CV_PI
55  #define CV_PI_F 3.14159265f
56  #else
57  #define CV_PI_F ((float)CV_PI)
58  #endif
59 #endif
60 
61 #if defined(__GNUC__)
62  #define cudaSafeCall(expr) ___cudaSafeCall(expr, __FILE__, __LINE__, __func__)
63 #else /* defined(__CUDACC__) || defined(__MSVC__) */
64  #define cudaSafeCall(expr) ___cudaSafeCall(expr, __FILE__, __LINE__)
65 #endif
66 
67 namespace cv { namespace gpu
68 {
69  void error(const char *error_string, const char *file, const int line, const char *func);
70 
71  template <typename T> static inline bool isAligned(const T* ptr, size_t size)
72  {
73  return reinterpret_cast<size_t>(ptr) % size == 0;
74  }
75 
76  static inline bool isAligned(size_t step, size_t size)
77  {
78  return step % size == 0;
79  }
80 }}
81 
82 static inline void ___cudaSafeCall(cudaError_t err, const char *file, const int line, const char *func = "")
83 {
84  if (cudaSuccess != err)
85  cv::gpu::error(cudaGetErrorString(err), file, line, func);
86 }
87 
88 namespace cv { namespace gpu
89 {
90  __host__ __device__ __forceinline__ int divUp(int total, int grain)
91  {
92  return (total + grain - 1) / grain;
93  }
94 
95  namespace device
96  {
97  using cv::gpu::divUp;
98 
99 #ifdef __CUDACC__
100  typedef unsigned char uchar;
101  typedef unsigned short ushort;
102  typedef signed char schar;
103  #if defined (_WIN32) || defined (__APPLE__)
104  typedef unsigned int uint;
105  #endif
106 
107  template<class T> inline void bindTexture(const textureReference* tex, const PtrStepSz<T>& img)
108  {
109  cudaChannelFormatDesc desc = cudaCreateChannelDesc<T>();
110  cudaSafeCall( cudaBindTexture2D(0, tex, img.ptr(), &desc, img.cols, img.rows, img.step) );
111  }
112 #endif // __CUDACC__
113  }
114 }}
115 
116 
117 
118 #endif // __OPENCV_GPU_COMMON_HPP__
int int void int total
Definition: core_c.h:1048
CvCmpFunc func
Definition: core_c.h:1072
int cols
Definition: cuda_devptrs.hpp:113
const CvMat const CvMat const CvMat CvMat CvMat CvMat CvMat CvSize CvMat CvMat * T
Definition: calib3d.hpp:270
__host__ __device__ __forceinline__ int divUp(int total, int grain)
Definition: common.hpp:90
void int step
Definition: core_c.h:403
Definition: cuda_devptrs.hpp:104
GLint GLvoid * img
Definition: legacy.hpp:1150
signed char schar
Definition: common.hpp:102
unsigned char uchar
Definition: common.hpp:100
CV_EXPORTS void error(const char *error_string, const char *file, const int line, const char *func="")
unsigned int uint
Definition: common.hpp:104
size_t step
stride between two consecutive rows in bytes. Step is stored always and everywhere in bytes!!! ...
Definition: cuda_devptrs.hpp:95
unsigned short ushort
Definition: common.hpp:101
__CV_GPU_HOST_DEVICE__ T * ptr(int y=0)
Definition: cuda_devptrs.hpp:97
const char const char const char int line
Definition: core_c.h:1743
const char * ptr
Definition: core_c.h:942
int rows
Definition: cuda_devptrs.hpp:114
void bindTexture(const textureReference *tex, const PtrStepSz< T > &img)
Definition: common.hpp:107
GLsizeiptr size
Definition: core_c.h:939
CV_EXPORTS_W void line(CV_IN_OUT Mat &img, Point pt1, Point pt2, const Scalar &color, int thickness=1, int lineType=8, int shift=0)
draws the line segment (pt1, pt2) in the image