mirror of https://github.com/opencv/opencv.git
Open Source Computer Vision Library
https://opencv.org/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
312 lines
11 KiB
312 lines
11 KiB
14 years ago
|
Data Structures
|
||
|
===============
|
||
|
|
||
14 years ago
|
.. highlight:: cpp
|
||
|
|
||
13 years ago
|
|
||
14 years ago
|
|
||
12 years ago
|
gpu::PtrStepSz
|
||
12 years ago
|
--------------
|
||
12 years ago
|
.. ocv:class:: gpu::PtrStepSz
|
||
14 years ago
|
|
||
14 years ago
|
Lightweight class encapsulating pitched memory on a GPU and passed to nvcc-compiled code (CUDA kernels). Typically, it is used internally by OpenCV and by users who write device code. You can call its members from both host and device code. ::
|
||
14 years ago
|
|
||
12 years ago
|
template <typename T> struct PtrStepSz : public PtrStep<T>
|
||
14 years ago
|
{
|
||
12 years ago
|
__CV_GPU_HOST_DEVICE__ PtrStepSz() : cols(0), rows(0) {}
|
||
|
__CV_GPU_HOST_DEVICE__ PtrStepSz(int rows_, int cols_, T* data_, size_t step_)
|
||
|
: PtrStep<T>(data_, step_), cols(cols_), rows(rows_) {}
|
||
14 years ago
|
|
||
14 years ago
|
template <typename U>
|
||
12 years ago
|
explicit PtrStepSz(const PtrStepSz<U>& d) : PtrStep<T>((T*)d.data, d.step), cols(d.cols), rows(d.rows){}
|
||
14 years ago
|
|
||
12 years ago
|
int cols;
|
||
|
int rows;
|
||
14 years ago
|
};
|
||
14 years ago
|
|
||
12 years ago
|
typedef PtrStepSz<unsigned char> PtrStepSzb;
|
||
|
typedef PtrStepSz<float> PtrStepSzf;
|
||
|
typedef PtrStepSz<int> PtrStepSzi;
|
||
14 years ago
|
|
||
14 years ago
|
|
||
|
|
||
12 years ago
|
gpu::PtrStep
|
||
12 years ago
|
------------
|
||
12 years ago
|
.. ocv:class:: gpu::PtrStep
|
||
14 years ago
|
|
||
12 years ago
|
Structure similar to :ocv:class:`gpu::PtrStepSz` but containing only a pointer and row step. Width and height fields are excluded due to performance reasons. The structure is intended for internal use or for users who write device code. ::
|
||
14 years ago
|
|
||
12 years ago
|
template <typename T> struct PtrStep : public DevPtr<T>
|
||
14 years ago
|
{
|
||
12 years ago
|
__CV_GPU_HOST_DEVICE__ PtrStep() : step(0) {}
|
||
|
__CV_GPU_HOST_DEVICE__ PtrStep(T* data_, size_t step_) : DevPtr<T>(data_), step(step_) {}
|
||
14 years ago
|
|
||
12 years ago
|
//! stride between two consecutive rows in bytes. Step is stored always and everywhere in bytes!!!
|
||
|
size_t step;
|
||
14 years ago
|
|
||
12 years ago
|
__CV_GPU_HOST_DEVICE__ T* ptr(int y = 0) { return ( T*)( ( char*)DevPtr<T>::data + y * step); }
|
||
|
__CV_GPU_HOST_DEVICE__ const T* ptr(int y = 0) const { return (const T*)( (const char*)DevPtr<T>::data + y * step); }
|
||
14 years ago
|
|
||
12 years ago
|
__CV_GPU_HOST_DEVICE__ T& operator ()(int y, int x) { return ptr(y)[x]; }
|
||
|
__CV_GPU_HOST_DEVICE__ const T& operator ()(int y, int x) const { return ptr(y)[x]; }
|
||
14 years ago
|
};
|
||
14 years ago
|
|
||
12 years ago
|
typedef PtrStep<unsigned char> PtrStepb;
|
||
12 years ago
|
typedef PtrStep<float> PtrStepf;
|
||
|
typedef PtrStep<int> PtrStepi;
|
||
14 years ago
|
|
||
|
|
||
12 years ago
|
|
||
14 years ago
|
gpu::GpuMat
|
||
|
-----------
|
||
14 years ago
|
.. ocv:class:: gpu::GpuMat
|
||
14 years ago
|
|
||
13 years ago
|
Base storage class for GPU memory with reference counting. Its interface matches the :ocv:class:`Mat` interface with the following limitations:
|
||
|
|
||
|
* no arbitrary dimensions support (only 2D)
|
||
|
* no functions that return references to their data (because references on GPU are not valid for CPU)
|
||
|
* no expression templates technique support
|
||
14 years ago
|
|
||
12 years ago
|
Beware that the latter limitation may lead to overloaded matrix operators that cause memory allocations. The ``GpuMat`` class is convertible to :ocv:class:`gpu::PtrStepSz` and :ocv:class:`gpu::PtrStep` so it can be passed directly to the kernel.
|
||
14 years ago
|
|
||
13 years ago
|
.. note:: In contrast with :ocv:class:`Mat`, in most cases ``GpuMat::isContinuous() == false`` . This means that rows are aligned to a size depending on the hardware. Single-row ``GpuMat`` is always a continuous matrix.
|
||
14 years ago
|
|
||
14 years ago
|
::
|
||
14 years ago
|
|
||
14 years ago
|
class CV_EXPORTS GpuMat
|
||
14 years ago
|
{
|
||
|
public:
|
||
14 years ago
|
//! default constructor
|
||
|
GpuMat();
|
||
14 years ago
|
|
||
12 years ago
|
//! constructs GpuMat of the specified size and type
|
||
14 years ago
|
GpuMat(int rows, int cols, int type);
|
||
|
GpuMat(Size size, int type);
|
||
14 years ago
|
|
||
14 years ago
|
.....
|
||
14 years ago
|
|
||
12 years ago
|
//! builds GpuMat from host memory (Blocking call)
|
||
|
explicit GpuMat(InputArray arr);
|
||
14 years ago
|
|
||
12 years ago
|
//! returns lightweight PtrStepSz structure for passing
|
||
14 years ago
|
//to nvcc-compiled code. Contains size, data ptr and step.
|
||
12 years ago
|
template <class T> operator PtrStepSz<T>() const;
|
||
|
template <class T> operator PtrStep<T>() const;
|
||
14 years ago
|
|
||
12 years ago
|
//! pefroms upload data to GpuMat (Blocking call)
|
||
|
void upload(InputArray arr);
|
||
14 years ago
|
|
||
12 years ago
|
//! pefroms upload data to GpuMat (Non-Blocking call)
|
||
|
void upload(InputArray arr, Stream& stream);
|
||
14 years ago
|
|
||
12 years ago
|
//! pefroms download data from device to host memory (Blocking call)
|
||
|
void download(OutputArray dst) const;
|
||
|
|
||
|
//! pefroms download data from device to host memory (Non-Blocking call)
|
||
|
void download(OutputArray dst, Stream& stream) const;
|
||
14 years ago
|
};
|
||
14 years ago
|
|
||
14 years ago
|
|
||
13 years ago
|
.. note:: You are not recommended to leave static or global ``GpuMat`` variables allocated, that is, to rely on its destructor. The destruction order of such variables and CUDA context is undefined. GPU memory release function returns error if the CUDA context has been destroyed before.
|
||
|
|
||
|
.. seealso:: :ocv:class:`Mat`
|
||
|
|
||
|
|
||
|
|
||
|
gpu::createContinuous
|
||
12 years ago
|
---------------------
|
||
|
Creates a continuous matrix.
|
||
13 years ago
|
|
||
12 years ago
|
.. ocv:function:: void gpu::createContinuous(int rows, int cols, int type, OutputArray arr)
|
||
13 years ago
|
|
||
|
:param rows: Row count.
|
||
|
|
||
|
:param cols: Column count.
|
||
|
|
||
|
:param type: Type of the matrix.
|
||
|
|
||
12 years ago
|
:param arr: Destination matrix. This parameter changes only if it has a proper type and area ( :math:`\texttt{rows} \times \texttt{cols}` ).
|
||
13 years ago
|
|
||
|
Matrix is called continuous if its elements are stored continuously, that is, without gaps at the end of each row.
|
||
|
|
||
|
|
||
|
|
||
|
gpu::ensureSizeIsEnough
|
||
12 years ago
|
-----------------------
|
||
13 years ago
|
Ensures that the size of a matrix is big enough and the matrix has a proper type.
|
||
|
|
||
12 years ago
|
.. ocv:function:: void gpu::ensureSizeIsEnough(int rows, int cols, int type, OutputArray arr)
|
||
13 years ago
|
|
||
|
:param rows: Minimum desired number of rows.
|
||
|
|
||
|
:param cols: Minimum desired number of columns.
|
||
|
|
||
|
:param type: Desired matrix type.
|
||
|
|
||
12 years ago
|
:param arr: Destination matrix.
|
||
13 years ago
|
|
||
|
The function does not reallocate memory if the matrix has proper attributes already.
|
||
|
|
||
|
|
||
14 years ago
|
|
||
14 years ago
|
gpu::CudaMem
|
||
|
------------
|
||
14 years ago
|
.. ocv:class:: gpu::CudaMem
|
||
14 years ago
|
|
||
12 years ago
|
Class with reference counting wrapping special memory type allocation functions from CUDA. Its interface is also :ocv:func:`Mat`-like but with additional memory type parameters.
|
||
14 years ago
|
|
||
12 years ago
|
* **PAGE_LOCKED** sets a page locked memory type used commonly for fast and asynchronous uploading/downloading data from/to GPU.
|
||
|
* **SHARED** specifies a zero copy memory allocation that enables mapping the host memory to GPU address space, if supported.
|
||
|
* **WRITE_COMBINED** sets the write combined buffer that is not cached by CPU. Such buffers are used to supply GPU with data when GPU only reads it. The advantage is a better CPU cache utilization.
|
||
13 years ago
|
|
||
|
.. note:: Allocation size of such memory types is usually limited. For more details, see *CUDA 2.2 Pinned Memory APIs* document or *CUDA C Programming Guide*.
|
||
14 years ago
|
|
||
14 years ago
|
::
|
||
|
|
||
|
class CV_EXPORTS CudaMem
|
||
14 years ago
|
{
|
||
|
public:
|
||
12 years ago
|
enum AllocType { PAGE_LOCKED = 1, SHARED = 2, WRITE_COMBINED = 4 };
|
||
14 years ago
|
|
||
12 years ago
|
explicit CudaMem(AllocType alloc_type = PAGE_LOCKED);
|
||
14 years ago
|
|
||
12 years ago
|
CudaMem(int rows, int cols, int type, AllocType alloc_type = PAGE_LOCKED);
|
||
|
CudaMem(Size size, int type, AllocType alloc_type = PAGE_LOCKED);
|
||
14 years ago
|
|
||
12 years ago
|
//! creates from host memory with coping data
|
||
|
explicit CudaMem(InputArray arr, AllocType alloc_type = PAGE_LOCKED);
|
||
14 years ago
|
|
||
12 years ago
|
......
|
||
14 years ago
|
|
||
12 years ago
|
//! returns matrix header with disabled reference counting for CudaMem data.
|
||
|
Mat createMatHeader() const;
|
||
14 years ago
|
|
||
12 years ago
|
//! maps host memory into device address space and returns GpuMat header for it. Throws exception if not supported by hardware.
|
||
|
GpuMat createGpuMatHeader() const;
|
||
14 years ago
|
|
||
12 years ago
|
......
|
||
14 years ago
|
|
||
12 years ago
|
AllocType alloc_type;
|
||
14 years ago
|
};
|
||
14 years ago
|
|
||
14 years ago
|
|
||
|
|
||
14 years ago
|
gpu::CudaMem::createMatHeader
|
||
12 years ago
|
-----------------------------
|
||
13 years ago
|
Creates a header without reference counting to :ocv:class:`gpu::CudaMem` data.
|
||
14 years ago
|
|
||
14 years ago
|
.. ocv:function:: Mat gpu::CudaMem::createMatHeader() const
|
||
14 years ago
|
|
||
14 years ago
|
|
||
|
|
||
14 years ago
|
gpu::CudaMem::createGpuMatHeader
|
||
12 years ago
|
--------------------------------
|
||
13 years ago
|
Maps CPU memory to GPU address space and creates the :ocv:class:`gpu::GpuMat` header without reference counting for it.
|
||
14 years ago
|
|
||
14 years ago
|
.. ocv:function:: GpuMat gpu::CudaMem::createGpuMatHeader() const
|
||
14 years ago
|
|
||
12 years ago
|
This can be done only if memory was allocated with the ``SHARED`` flag and if it is supported by the hardware. Laptops often share video and CPU memory, so address spaces can be mapped, which eliminates an extra copy.
|
||
|
|
||
13 years ago
|
|
||
14 years ago
|
|
||
12 years ago
|
gpu::registerPageLocked
|
||
|
-----------------------
|
||
|
Page-locks the memory of matrix and maps it for the device(s).
|
||
|
|
||
|
.. ocv:function:: void gpu::registerPageLocked(Mat& m)
|
||
|
|
||
|
:param m: Input matrix.
|
||
|
|
||
|
|
||
|
|
||
|
gpu::unregisterPageLocked
|
||
|
-------------------------
|
||
|
Unmaps the memory of matrix and makes it pageable again.
|
||
14 years ago
|
|
||
12 years ago
|
.. ocv:function:: void gpu::unregisterPageLocked(Mat& m)
|
||
13 years ago
|
|
||
12 years ago
|
:param m: Input matrix.
|
||
14 years ago
|
|
||
|
|
||
14 years ago
|
|
||
|
gpu::Stream
|
||
|
-----------
|
||
14 years ago
|
.. ocv:class:: gpu::Stream
|
||
14 years ago
|
|
||
12 years ago
|
This class encapsulates a queue of asynchronous calls.
|
||
14 years ago
|
|
||
13 years ago
|
.. note:: Currently, you may face problems if an operation is enqueued twice with different data. Some functions use the constant GPU memory, and next call may update the memory before the previous one has been finished. But calling different operations asynchronously is safe because each operation has its own constant buffer. Memory copy/upload/download/set operations to the buffers you hold are also safe.
|
||
14 years ago
|
|
||
14 years ago
|
::
|
||
14 years ago
|
|
||
14 years ago
|
class CV_EXPORTS Stream
|
||
14 years ago
|
{
|
||
|
public:
|
||
12 years ago
|
Stream();
|
||
14 years ago
|
|
||
12 years ago
|
//! queries an asynchronous stream for completion status
|
||
|
bool queryIfComplete() const;
|
||
14 years ago
|
|
||
12 years ago
|
//! waits for stream tasks to complete
|
||
12 years ago
|
void waitForCompletion();
|
||
14 years ago
|
|
||
12 years ago
|
//! makes a compute stream wait on an event
|
||
|
void waitEvent(const Event& event);
|
||
14 years ago
|
|
||
12 years ago
|
//! adds a callback to be called on the host after all currently enqueued items in the stream have completed
|
||
|
void enqueueHostCallback(StreamCallback callback, void* userData);
|
||
14 years ago
|
|
||
12 years ago
|
//! return Stream object for default CUDA stream
|
||
|
static Stream& Null();
|
||
12 years ago
|
|
||
12 years ago
|
//! returns true if stream object is not default (!= 0)
|
||
|
operator bool_type() const;
|
||
14 years ago
|
};
|
||
14 years ago
|
|
||
14 years ago
|
|
||
|
|
||
14 years ago
|
gpu::Stream::queryIfComplete
|
||
12 years ago
|
----------------------------
|
||
13 years ago
|
Returns ``true`` if the current stream queue is finished. Otherwise, it returns false.
|
||
|
|
||
14 years ago
|
.. ocv:function:: bool gpu::Stream::queryIfComplete()
|
||
14 years ago
|
|
||
|
|
||
|
|
||
14 years ago
|
gpu::Stream::waitForCompletion
|
||
12 years ago
|
------------------------------
|
||
13 years ago
|
Blocks the current CPU thread until all operations in the stream are complete.
|
||
|
|
||
14 years ago
|
.. ocv:function:: void gpu::Stream::waitForCompletion()
|
||
14 years ago
|
|
||
|
|
||
|
|
||
12 years ago
|
gpu::Stream::waitEvent
|
||
|
----------------------
|
||
|
Makes a compute stream wait on an event.
|
||
12 years ago
|
|
||
12 years ago
|
.. ocv:function:: void gpu::Stream::waitEvent(const Event& event)
|
||
12 years ago
|
|
||
|
|
||
|
|
||
|
gpu::Stream::enqueueHostCallback
|
||
|
--------------------------------
|
||
|
Adds a callback to be called on the host after all currently enqueued items in the stream have completed.
|
||
|
|
||
|
.. ocv:function:: void gpu::Stream::enqueueHostCallback(StreamCallback callback, void* userData)
|
||
|
|
||
|
.. note:: Callbacks must not make any CUDA API calls. Callbacks must not perform any synchronization that may depend on outstanding device work or other callbacks that are not mandated to run earlier. Callbacks without a mandated order (in independent streams) execute in undefined order and may be serialized.
|
||
|
|
||
|
|
||
|
|
||
14 years ago
|
gpu::StreamAccessor
|
||
|
-------------------
|
||
13 years ago
|
.. ocv:struct:: gpu::StreamAccessor
|
||
14 years ago
|
|
||
13 years ago
|
Class that enables getting ``cudaStream_t`` from :ocv:class:`gpu::Stream` and is declared in ``stream_accessor.hpp`` because it is the only public header that depends on the CUDA Runtime API. Including it brings a dependency to your code. ::
|
||
14 years ago
|
|
||
14 years ago
|
struct StreamAccessor
|
||
|
{
|
||
14 years ago
|
CV_EXPORTS static cudaStream_t getStream(const Stream& stream);
|
||
14 years ago
|
};
|