GpuMat 1.0.1
A GpuMat for CS205 C/C++ Project4
Loading...
Searching...
No Matches
Public Member Functions | Friends | List of all members
Matrix< T > Class Template Reference

Base MAT class for GPU memory with reference counting. More...

Public Member Functions

 Matrix (size_t rows, size_t cols, int device=0)
 Constructor for the first time.
 
 ~Matrix ()
 Destructor.
 
 Matrix (const Matrix &other)
 拷贝构造函数,增加引用计数
 
size_t getRows () const noexcept
 Getters.
 
size_t getCols () const noexcept
 Get the Cols object.
 
size_t getSize () const noexcept
 Get the Size object.
 
TgetData () const noexcept
 Get the Data object.
 
T getRolColData (size_t row, size_t col) const
 Get the Device object.
 
__device__ __host__ Toperator() (size_t row, size_t col)
 重载():给矩阵赋值
 
__device__ __host__ const Toperator() (size_t row, size_t col) const
 重载():获取矩阵值
 
Matrix< Toperator+ (const Matrix< T > &other)
 重写+运算符
 
Matrix< T > & operator+= (const Matrix< T > &other)
 
Matrix< Toperator- (const Matrix< T > &other)
 重写 - 运算符
 
Matrix operator* (const Matrix &other)
 Matrix multiplication,重写 * 运算符
 
void SetParentMatrix (const Matrix &other)
 Set our Matrix as the ROI (Region of Interest) of other.
 
void setROIas (size_t startRow, size_t startCol, size_t numRows, size_t numCols, const Matrix &other)
 设置ROI
 
Matrixoperator= (const Matrix &other)
 浅拷贝
 
bool operator== (const Matrix &other) const
 重写 == 运算符
 
void multiply (const Matrix &other, Matrix *result_ptr)
 Mul two matrices.
 
void changeGPU (int device_num)
 change GPU where the matrix is stored
 
bool isEqual (const Matrix &other) const
 判断两个矩阵是否相等
 
bool checkRowsCols (size_t row, size_t col) const
 
void print () const
 
bool shape_equals (const Matrix &other) const
 
void ensure_unique ()
 
void deepCopy (const T *src_data, size_t size) const
 深拷贝函数,用于在CUDA设备之间复制数据
 
void deepCopy (const T *src_data, size_t size, int device)
 深拷贝函数,用于在CUDA设备之间复制数据
 
void upload (T *device_data)
 上传数据到 GPU
 
Tdownload ()
 从 GPU 下载数据到 CPU
 

Friends

std::ostream & operator<< (std::ostream &os, const Matrix< T > &matrix)
 友函数,输出矩阵
 

Detailed Description

template<typename T>
class Matrix< T >

Base MAT class for GPU memory with reference counting.

Its limitations:

Note
In contrast with 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.
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.

Some member functions are described as a "Blocking Call" while some are described as a "Non-Blocking Call". Blocking functions are synchronous to host. It is guaranteed that the GPU operation is finished when the function returns. However, non-blocking functions are asynchronous to host. Those functions may return even if the GPU operation is not finished.

Compared to their blocking counterpart, non-blocking functions accept Stream as an additional argument. If a non-default stream is passed, the GPU operation may overlap with operations in other streams.

See also
cv::Mat, cv::GpuMat

Constructor & Destructor Documentation

◆ Matrix() [1/2]

template<typename T >
Matrix< T >::Matrix ( size_t rows,
size_t cols,
int device = 0 )
inline

Constructor for the first time.

Parameters
rows,cols,device

◆ ~Matrix()

template<typename T >
Matrix< T >::~Matrix ( )
inline

Destructor.

Returns
nullptr of data if ref_count == 0

◆ Matrix() [2/2]

template<typename T >
Matrix< T >::Matrix ( const Matrix< T > & other)
inline

拷贝构造函数,增加引用计数

Parameters
other_Matrix
Returns
ref_count += 1

Member Function Documentation

◆ changeGPU()

template<typename T >
void Matrix< T >::changeGPU ( int device_num)
inline

change GPU where the matrix is stored

Parameters
device_num

◆ checkRowsCols()

template<typename T >
bool Matrix< T >::checkRowsCols ( size_t row,
size_t col ) const
inline
Parameters
row
col
Returns
false if row,col are bigger than 1000000 or smaller than 0

◆ deepCopy() [1/2]

template<typename T >
void Matrix< T >::deepCopy ( const T * src_data,
size_t size ) const
inline

深拷贝函数,用于在CUDA设备之间复制数据

◆ deepCopy() [2/2]

template<typename T >
void Matrix< T >::deepCopy ( const T * src_data,
size_t size,
int device )
inline

深拷贝函数,用于在CUDA设备之间复制数据

◆ download()

template<typename T >
T * Matrix< T >::download ( )
inline

从 GPU 下载数据到 CPU

Parameters
返回主机上的数据

◆ ensure_unique()

template<typename T >
void Matrix< T >::ensure_unique ( )
inline
Parameters
私有辅助函数,用于确保数据的唯一性

◆ getCols()

template<typename T >
size_t Matrix< T >::getCols ( ) const
inlinenoexcept

Get the Cols object.

Returns
size_t

◆ getData()

template<typename T >
T * Matrix< T >::getData ( ) const
inlinenoexcept

Get the Data object.

Returns
T*

◆ getRolColData()

template<typename T >
T Matrix< T >::getRolColData ( size_t row,
size_t col ) const
inline

Get the Device object.

Parameters
row,col
Returns
T[row*cols + col]

◆ getRows()

template<typename T >
size_t Matrix< T >::getRows ( ) const
inlinenoexcept

Getters.

Returns
rows

◆ getSize()

template<typename T >
size_t Matrix< T >::getSize ( ) const
inlinenoexcept

Get the Size object.

Returns
size_t

◆ isEqual()

template<typename T >
bool Matrix< T >::isEqual ( const Matrix< T > & other) const
inline

判断两个矩阵是否相等

Parameters
other
Returns
所有数值是否一致

◆ multiply()

template<typename T >
void Matrix< T >::multiply ( const Matrix< T > & other,
Matrix< T > * result_ptr )
inline

Mul two matrices.

Parameters
other_Matrix,result_ptr

◆ operator()() [1/2]

template<typename T >
__device__ __host__ T & Matrix< T >::operator() ( size_t row,
size_t col )
inline

重载():给矩阵赋值

Parameters
row,col
See also
const T& operator()

◆ operator()() [2/2]

template<typename T >
__device__ __host__ const T & Matrix< T >::operator() ( size_t row,
size_t col ) const
inline

重载():获取矩阵值

Parameters
row,col
See also
const T& operator()

◆ operator*()

template<typename T >
Matrix Matrix< T >::operator* ( const Matrix< T > & other)
inline

Matrix multiplication,重写 * 运算符

Parameters
othermatrix
Returns
result matrix

◆ operator+()

template<typename T >
Matrix< T > Matrix< T >::operator+ ( const Matrix< T > & other)
inline

重写+运算符

Parameters
other_Matrix
Returns
result Matrix

◆ operator+=()

template<typename T >
Matrix< T > & Matrix< T >::operator+= ( const Matrix< T > & other)
inline
Returns
Matrix A += B

◆ operator-()

template<typename T >
Matrix< T > Matrix< T >::operator- ( const Matrix< T > & other)
inline

重写 - 运算符

Parameters
other_Matrix
Returns
result Matrix

◆ operator=()

template<typename T >
Matrix & Matrix< T >::operator= ( const Matrix< T > & other)
inline

浅拷贝

Parameters
Matrix&other

◆ operator==()

template<typename T >
bool Matrix< T >::operator== ( const Matrix< T > & other) const
inline

重写 == 运算符

◆ print()

template<typename T >
void Matrix< T >::print ( ) const
inline
Parameters
printmatrix

◆ SetParentMatrix()

template<typename T >
void Matrix< T >::SetParentMatrix ( const Matrix< T > & other)
inline

Set our Matrix as the ROI (Region of Interest) of other.

Parameters
startRow,startCol,roiRows,roiCols

◆ setROIas()

template<typename T >
void Matrix< T >::setROIas ( size_t startRow,
size_t startCol,
size_t numRows,
size_t numCols,
const Matrix< T > & other )
inline

设置ROI

Parameters
startRow,startCol,numRows,numCols,other

◆ shape_equals()

template<typename T >
bool Matrix< T >::shape_equals ( const Matrix< T > & other) const
inline

◆ upload()

template<typename T >
void Matrix< T >::upload ( T * device_data)
inline

上传数据到 GPU

Parameters
上传到GPU上的数据的指针

Friends And Related Symbol Documentation

◆ operator<<

template<typename T >
std::ostream & operator<< ( std::ostream & os,
const Matrix< T > & matrix )
friend

友函数,输出矩阵

Parameters
os
matrix
Returns
Output stream