GPUMLib  0.2.2
GPU Machine Learning Library
Public Member Functions | List of all members
CudaMatrix< Type > Class Template Reference

Create a matrix of any type, that automatically manages the memory used to hold its elements (data will be stored both on the host and on the device). More...

#include <CudaMatrix.h>

Public Member Functions

 CudaMatrix (StoringOrder storingOrder=RowMajor)
 
 CudaMatrix (int rows, int columns, StoringOrder storingOrder=RowMajor)
 
 CudaMatrix (const CudaMatrix< Type > &other)
 
 CudaMatrix (const HostMatrix< Type > &other)
 
 CudaMatrix (const DeviceMatrix< Type > &other)
 
 CudaMatrix (CudaMatrix< Type > &&temporaryMatrix)
 
CudaMatrix< Type > & operator= (const HostMatrix< Type > &other)
 
CudaMatrix< Type > & operator= (const DeviceMatrix< Type > &other)
 
CudaMatrix< Type > & operator= (const CudaMatrix< Type > &other)
 
CudaMatrix< Type > & operator= (const CudaMatrix< Type > &&temporaryMatrix)
 
void UpdateDevice ()
 
void UpdateHost ()
 
Type * HostPointer () const
 
Type * DevicePointer () const
 
DeviceMatrix< Type > & GetDeviceMatrix ()
 
HostMatrix< Type > & GetHostMatrix ()
 
Type & operator() (int row, int column)
 
Type operator() (int row, int column) const
 
int Rows () const
 
int Columns () const
 
int Elements () const
 
bool IsRowMajor () const
 
void ReplaceByTranspose ()
 
CudaMatrix< Type > Transpose ()
 
int ResizeWithoutPreservingData (int rows, int columns)
 
void Dispose ()
 Disposes the matrix.
 
void DisposeDevice ()
 //! Updates the host information and disposes the device matrix
 
void DisposeHost ()
 Updates the device information and disposes the host matrix.
 

Detailed Description

template<class Type>
class GPUMLib::CudaMatrix< Type >

Create a matrix of any type, that automatically manages the memory used to hold its elements (data will be stored both on the host and on the device).

Attention
The data on the host might differ from the data on the device. Use UpdateDevice and UpdateHost to synchronize data.

Definition at line 35 of file BaseMatrix.h.

Constructor & Destructor Documentation

CudaMatrix ( StoringOrder  storingOrder = RowMajor)
inline

Constructs an empty matrix

Parameters
storingOrderdefines if the matrix uses the row-major or column-major order to store the information

Definition at line 45 of file CudaMatrix.h.

CudaMatrix ( int  rows,
int  columns,
StoringOrder  storingOrder = RowMajor 
)
inline

Constructs a matrix with a given number of rows and columns

Parameters
rowsthe number of rows
columnsthe number of columns
storingOrderdefines if the matrix uses the row-major or column-major order to store the information

Definition at line 51 of file CudaMatrix.h.

CudaMatrix ( const CudaMatrix< Type > &  other)
inline

Constructs a matrix identical to another matrix

Parameters
otheranother matrix

Definition at line 55 of file CudaMatrix.h.

CudaMatrix ( const HostMatrix< Type > &  other)
inline

Constructs a matrix identical to an host matrix

Parameters
otheranother matrix

Definition at line 59 of file CudaMatrix.h.

CudaMatrix ( const DeviceMatrix< Type > &  other)
inline

Constructs a matrix identical to a device matrix

Parameters
otherdevice matrix

Definition at line 63 of file CudaMatrix.h.

CudaMatrix ( CudaMatrix< Type > &&  temporaryMatrix)
inline

Constructs a matrix using the elements of a temporary matrix (rvalue)

Parameters
temporaryMatrixtemporary matrix containing the elements

Definition at line 67 of file CudaMatrix.h.

Member Function Documentation

int Columns ( ) const
inline

Gets the number of columns of the matrix

Returns
the number of columns of the matrix

Definition at line 188 of file CudaMatrix.h.

Type* DevicePointer ( ) const
inline

Gets a pointer to the device matrix data

Attention
Use with caution
Returns
a pointer to the device matrix data

Definition at line 146 of file CudaMatrix.h.

int Elements ( ) const
inline

Gets the number of elements contained in the matrix

Returns
the number of elements contained in the matrix

Definition at line 194 of file CudaMatrix.h.

DeviceMatrix<Type>& GetDeviceMatrix ( )
inline

Gets a the device matrix

Attention
Use with caution
Returns
The device matrix

Definition at line 153 of file CudaMatrix.h.

HostMatrix<Type>& GetHostMatrix ( )
inline

Gets a the host matrix

Attention
Use with caution
Returns
The host matrix

Definition at line 160 of file CudaMatrix.h.

Type* HostPointer ( ) const
inline

Gets a pointer to the host matrix data

Attention
Use with caution. Special attention should be given to how the matrix information is stored (row-major or column-major).
Returns
a pointer to the matrix data
See also
IsRowMajor

Definition at line 139 of file CudaMatrix.h.

bool IsRowMajor ( ) const
inline

Indicates if the information in the matrix is stored in row-major order.

Returns
True if the matrix information is stored in row-major order. False if the information is stored in column-major format.

Definition at line 200 of file CudaMatrix.h.

Type& operator() ( int  row,
int  column 
)
inline

Gets a reference to an element of the host matrix

Parameters
rowrow of the desired element
columncolumn of the desired element
Returns
a reference to an element desired, based on the row and column specified

Definition at line 168 of file CudaMatrix.h.

Type operator() ( int  row,
int  column 
) const
inline

Gets an element of the host matrix

Parameters
rowrow of the desired element
columncolumn of the desired element
Returns
the element desired, based on the row and column specified

Definition at line 176 of file CudaMatrix.h.

CudaMatrix<Type>& operator= ( const HostMatrix< Type > &  other)
inline

Transforms this matrix into an matrix identical to a host matrix

Parameters
otherhost matrix
Returns
a reference to this matrix
Attention
The storing order (major-row or major-column) becomes the same of the other matrix.
See also
IsRowMajor

Definition at line 76 of file CudaMatrix.h.

CudaMatrix<Type>& operator= ( const DeviceMatrix< Type > &  other)
inline

Transforms this matrix into a matrix identical to a device matrix

Parameters
otherdevice matrix
Returns
a reference to this matrix
Attention
The storing order (major-row or major-column) becomes the same of the other matrix.
See also
IsRowMajor

Definition at line 88 of file CudaMatrix.h.

CudaMatrix<Type>& operator= ( const CudaMatrix< Type > &  other)
inline

Transforms this matrix into a matrix identical to another

Parameters
otherother matrix
Returns
a reference to this matrix
Attention
The storing order (major-row or major-column) becomes the same of the other matrix.
See also
IsRowMajor

Definition at line 100 of file CudaMatrix.h.

CudaMatrix<Type>& operator= ( const CudaMatrix< Type > &&  temporaryMatrix)
inline

Replaces this matrix using a temporary matrix (rvalue)

Parameters
temporaryMatrixtemporary matrix
Returns
a reference to this matrix
Attention
The storing order (major-row or major-column) becomes the same of the other matrix.
See also
IsRowMajor

Definition at line 112 of file CudaMatrix.h.

void ReplaceByTranspose ( )
inline

Replaces this matrix by its transpose

Attention
This method is very fast, however it changes the method for storing information in the matrix (row-major or column-major).
See also
IsRowMajor

Definition at line 207 of file CudaMatrix.h.

int ResizeWithoutPreservingData ( int  rows,
int  columns 
)
inline

Resizes the matrix without preserving its data

Parameters
rowsthe new number of rows
columnsthe new number of columns
Returns
the number of elements of the matrix after being resized.

Definition at line 226 of file CudaMatrix.h.

int Rows ( ) const
inline

Gets the number of rows of the matrix

Returns
the number of rows of the matrix

Definition at line 182 of file CudaMatrix.h.

CudaMatrix<Type> Transpose ( )
inline

Gets the transposed of the matrix

Returns
the transposed of the matrix
Attention
The returned matrix does not use the same method (row-major or column-major) for storing information as this matrix.
See also
ReplaceByTranspose, IsRowMajor

Definition at line 216 of file CudaMatrix.h.

void UpdateDevice ( )
inline

Updates the device matrix data with the host matrix data

Attention
The storing order (major-row or major-column) of the device matrix becomes the same as the host matrix.
See also
IsRowMajor

Definition at line 124 of file CudaMatrix.h.

void UpdateHost ( )
inline

Updates the host matrix data with the device matrix data

Attention
The storing order (major-row or major-column) of the host matrix becomes the same as the device matrix.
See also
IsRowMajor

Definition at line 131 of file CudaMatrix.h.


The documentation for this class was generated from the following files: