This is a simple lightweight class that encapsulate pitched memory on GPU. It is untented to pass to nvcc-compiled code, i.e. CUDA kernels. Its members can be called both from host and from device code.
This is a simple lightweight class that encapsulate pitched memory on GPU. It is untented to pass to nvcc-compiled code, i.e. CUDA kernels. Its members can be called both from host and from device code.
This is class like DevMem2D\_ but contain only pointer and row step in elements. Image sizes are excluded due to performance reasons. This class is can only be constructed if sizeof(T) is multiple of 256.
This is structure is similar to DevMem2D\_ but contains only pointer and row step in elements. Width and height fields are excluded due to performance reasons. This class is can only be constructed if sizeof(T) is a multiple of 256.
\begin{lstlisting}
\begin{lstlisting}
template<typename T> struct PtrElemStep_ : public PtrStep_<T>
template<typename T> struct PtrElemStep_ : public PtrStep_<T>
The base storage class for GPU memory with reference counting. Its interface is almost \cvCppCross{Mat} interface with some limitations, so using it won't be a problem. The limitations are no arbitrary dimensions support (only 2D), no functions that returns references to its data (because references on GPU are not valid for CPU), no expression templates technique support. Because of last limitation please take care with overloaded matrix operators - they cause memory allocations. The GpuMat class is convertible to cv::gpu::DevMem2D\_ and cv::gpu::PtrStep\_ so it can be passed to directly to kernel.
The base storage class for GPU memory with reference counting. Its interface is almost \cvCppCross{Mat} interface with some limitations, so using it won't be a problem. The limitations are no arbitrary dimensions support (only 2D), no functions that returns references to its data (because references on GPU are not valid for CPU), no expression templates technique support. Because of last limitation please take care with overloaded matrix operators - they cause memory allocations. The GpuMat class is convertible to \hyperref[cppfunc.gpu.DevMem2D]{cv::gpu::DevMem2D\_} and \hyperref[cppfunc.gpu.PtrStep]{cv::gpu::PtrStep\_} so it can be passed to directly to kernel.
\textbf{Please note:} In contrast with \cvCppCross{Mat}, I most cases \texttt{GpuMat::isContinuous() == false}, i.e. rows are aligned to size depending on hardware.
\textbf{Please note:} In contrast with \cvCppCross{Mat}, In most cases \texttt{GpuMat::isContinuous() == false}, i.e. rows are aligned to size depending on hardware. Also single row GpuMat is always a continuous matrix.
\begin{lstlisting}
\begin{lstlisting}
class CV_EXPORTS GpuMat
class CV_EXPORTS GpuMat
...
@@ -88,8 +93,8 @@ public:
...
@@ -88,8 +93,8 @@ public:
//! returns lightweight DevMem2D_ structure for passing
//! returns lightweight DevMem2D_ structure for passing
//to nvcc-compiled code. Contains size, data ptr and step.
//to nvcc-compiled code. Contains size, data ptr and step.
This is a class with reference counting that wraps special memory type allocation functions from CUDA. Its interface is also \cvCppCross{Mat}-like but with additional memory type parameter:
This is a class with reference counting that wraps special memory type allocation functions from CUDA. Its interface is also \cvCppCross{Mat}-like but with additional memory type parameter:
\begin{itemize}
\begin{itemize}
\item\texttt{ALLOC\_PAGE\_LOCKED} Sets page locked memory type, used commonly for fast and asynchronous upload/download data from/to GPU.
\item\texttt{ALLOC\_PAGE\_LOCKED} Set page locked memory type, used commonly for fast and asynchronous upload/download data from/to GPU.
\item\texttt{ALLOC\_ZEROCOPY} Specifies zero copy memory allocation, i.e. with possibility to map host memory to GPU address space if supported.
\item\texttt{ALLOC\_ZEROCOPY} Specifies zero copy memory allocation, i.e. with possibility to map host memory to GPU address space if supported.
\item\texttt{ALLOC\_WRITE\_COMBINED} Sets write combined buffer which is not cached by CPU. Such buffers are used to supply GPU with data when GPU only reads it. The advantage is better CPU cache utilization.
\item\texttt{ALLOC\_WRITE\_COMBINED} Sets write combined buffer which is not cached by CPU. Such buffers are used to supply GPU with data when GPU only reads it. The advantage is better CPU cache utilization.
This class is a queue class used for asynchronous calls. Some functions have overloads with additional \cvCppCross{gpu::Stream} parameter. The overloads do initialization work (allocate output buffers, upload constants, etc.), start GPU kernel and return before results are ready. A check if all operation are complete can be performed via \cvCppCross{gpu::Stream::queryIfComplete()}. Asynchronous upload/download have to be performed from/to page-locked buffers, i.e. using \cvCppCross{gpu::CudaMem} or \cvCppCross{Mat} header that points to a region of \cvCppCross{gpu::CudaMem}.
This class encapsulated queue of the asynchronous calls. Some functions have overloads with additional \cvCppCross{gpu::Stream} parameter. The overloads do initialization work (allocate output buffers, upload constants, etc.), start GPU kernel and return before results are ready. A check if all operation are complete can be performed via \cvCppCross{gpu::Stream::queryIfComplete()}. Asynchronous upload/download have to be performed from/to page-locked buffers, i.e. using \cvCppCross{gpu::CudaMem} or \cvCppCross{Mat} header that points to a region of \cvCppCross{gpu::CudaMem}.
\textbf{Please note the limitation}: currently it is not guaranteed that all will work properly if one operation will be enqueued twice with different data. Some functions use constant GPU memory and next call may update the memory before previous has been finished. But calling asynchronously different operations is safe because each operation has own constant buffer. Memory copy/upload/download/set operations to buffers hold by user are also safe.
\textbf{Please note the limitation}: currently it is not guaranteed that all will work properly if one operation will be enqueued twice with different data. Some functions use constant GPU memory and next call may update the memory before previous has been finished. But calling asynchronously different operations is safe because each operation has own constant buffer. Memory copy/upload/download/set operations to buffers hold by user are also safe.
...
@@ -217,7 +222,7 @@ public:
...
@@ -217,7 +222,7 @@ public:
\end{lstlisting}
\end{lstlisting}
\cvCppFunc{gpu::Stream::queryIfComplete}
\cvCppFunc{gpu::Stream::queryIfComplete}
Returns true if current stream queue is finished, otherwise false.
Returns true if the current stream queue is finished, otherwise false.
\cvdefCpp{bool Stream::queryIfComplete()}
\cvdefCpp{bool Stream::queryIfComplete()}
\cvCppFunc{gpu::Stream::waitForCompletion}
\cvCppFunc{gpu::Stream::waitForCompletion}
...
@@ -227,7 +232,7 @@ Blocks until all operations in the stream are complete.
...
@@ -227,7 +232,7 @@ Blocks until all operations in the stream are complete.
\cvclass{gpu::StreamAccessor}
\cvclass{gpu::StreamAccessor}
This class provides possibility to get \texttt{cudaStream\_t} from \cvCppCross{gpu::Stream}. This class is declared in \texttt{stream\_accessor.hpp} because this is only public header that depend on Cuda Runtime API. Including it will bring the dependency to your code.
This class provides possibility to get \texttt{cudaStream\_t} from \cvCppCross{gpu::Stream}. This class is declared in \texttt{stream\_accessor.hpp} because that is only public header that depend on Cuda Runtime API. Including it will bring the dependency to your code.
@@ -8,7 +8,7 @@ Returns number of CUDA-enabled devices installed. It is to be used before any ot
...
@@ -8,7 +8,7 @@ Returns number of CUDA-enabled devices installed. It is to be used before any ot
\cvCppFunc{gpu::setDevice}
\cvCppFunc{gpu::setDevice}
Sets device and initializes it for current thread. Call of this function can be omitted, but in this case a default device will be initialized on fist GPU usage.
Sets device and initializes it for the current thread. Call of this function can be omitted, but in this case a default device will be initialized on fist GPU usage.
\cvdefCpp{void setDevice(int device);}
\cvdefCpp{void setDevice(int device);}
\begin{description}
\begin{description}
...
@@ -17,13 +17,13 @@ Sets device and initializes it for current thread. Call of this function can be
...
@@ -17,13 +17,13 @@ Sets device and initializes it for current thread. Call of this function can be
\cvCppFunc{gpu::getDevice}
\cvCppFunc{gpu::getDevice}
Returns current device index, which was set by \cvCppCross{gpu::getDevice} of initialized by default.
Returns the current device index, which was set by \cvCppCross{gpu::getDevice} or initialized by default.
\cvdefCpp{int getDevice();}
\cvdefCpp{int getDevice();}
\cvCppFunc{gpu::getComputeCapability}
\cvCppFunc{gpu::getComputeCapability}
Returns compute capability version for given device.
Returns compute capability version for the given device.