43#ifndef OPENCV_CUDA_COMMON_HPP
44#define OPENCV_CUDA_COMMON_HPP
46#include <cuda_runtime.h>
48#include "opencv2/core/cvdef.h"
49#include "opencv2/core/base.hpp"
59 #define CV_PI_F 3.14159265f
61 #define CV_PI_F ((float)CV_PI)
65namespace cv {
namespace cuda {
66 static inline void checkCudaError(cudaError_t err,
const char* file,
const int line,
const char* func)
68 if (cudaSuccess != err)
69 cv::error(cv::Error::GpuApiCallError, cudaGetErrorString(err), func, file,
line);
74 #define cudaSafeCall(expr) cv::cuda::checkCudaError(expr, __FILE__, __LINE__, CV_Func)
77namespace cv {
namespace cuda
79 template <
typename T>
static inline bool isAligned(
const T* ptr,
size_t size)
81 return reinterpret_cast<size_t>(ptr) % size == 0;
84 static inline bool isAligned(
size_t step,
size_t size)
86 return step % size == 0;
90namespace cv {
namespace cuda
94 __host__ __device__ __forceinline__
int divUp(
int total,
int grain)
96 return (total + grain - 1) / grain;
99 template<
class T>
inline void bindTexture(
const textureReference* tex,
const PtrStepSz<T>& img)
101 cudaChannelFormatDesc desc = cudaCreateChannelDesc<T>();
102 cudaSafeCall( cudaBindTexture2D(0, tex, img.ptr(), &desc, img.cols, img.rows, img.step) );
105 template<
class T>
inline void createTextureObjectPitch2D(cudaTextureObject_t* tex, PtrStepSz<T>& img,
const cudaTextureDesc& texDesc)
107 cudaResourceDesc resDesc;
108 memset(&resDesc, 0,
sizeof(resDesc));
109 resDesc.resType = cudaResourceTypePitch2D;
110 resDesc.res.pitch2D.devPtr =
static_cast<void*
>(img.ptr());
111 resDesc.res.pitch2D.height = img.rows;
112 resDesc.res.pitch2D.width = img.cols;
113 resDesc.res.pitch2D.pitchInBytes = img.step;
114 resDesc.res.pitch2D.desc = cudaCreateChannelDesc<T>();
116 cudaSafeCall( cudaCreateTextureObject(tex, &resDesc, &texDesc, NULL) );
static int divUp(int a, unsigned int b)
Integer division with result round up.
Definition: utility.hpp:482
CV_EXPORTS CV_NORETURN void error(const Exception &exc)
Signals an error and raises the exception.
static bool isAligned(const T &data)
Alignment check of passed values
Definition: utility.hpp:517
CV_EXPORTS_W void line(InputOutputArray img, Point pt1, Point pt2, const Scalar &color, int thickness=1, int lineType=LINE_8, int shift=0)
Draws a line segment connecting two points.
"black box" representation of the file storage associated with a file on disk.
Definition: aruco.hpp:75