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

Create a matrix of any type, on the device, that automatically manages the memory used to hold its elements. More...

#include <DeviceMatrix.h>

Inheritance diagram for DeviceMatrix< Type >:
BaseMatrix< Type >

Public Member Functions

void Dispose ()
 Disposes the matrix.
 
 DeviceMatrix (StoringOrder storingOrder=RowMajor)
 
 DeviceMatrix (int rows, int columns, StoringOrder storingOrder=RowMajor)
 
 DeviceMatrix (const DeviceMatrix< Type > &other)
 
 DeviceMatrix (const HostMatrix< Type > &other)
 
 DeviceMatrix (DeviceMatrix< Type > &&temporaryMatrix)
 
 ~DeviceMatrix ()
 Destructor.
 
DeviceMatrix< Type > & operator= (const HostMatrix< Type > &other)
 
DeviceMatrix< Type > & operator= (const DeviceMatrix< Type > &other)
 
DeviceMatrix< Type > & operator= (DeviceMatrix< Type > &&temporaryMatrix)
 
void TransferOwnerShipFrom (DeviceMatrix< Type > &other)
 
DeviceMatrix< Type > Transpose ()
 
void MultiplyBySelfTranspose (DeviceMatrix< Type > &C, cudafloat alpha=CUDA_VALUE(1.0), cudafloat beta=CUDA_VALUE(0.0))
 
int Rows () const
 
int Columns () const
 
Type * Pointer () const
 
int Elements () const
 
bool IsRowMajor () const
 
void ReplaceByTranspose ()
 
int ResizeWithoutPreservingData (int rows, int columns)
 

Static Public Member Functions

static void Multiply (DeviceMatrix< Type > &A, DeviceMatrix< Type > &B, DeviceMatrix< Type > &C, cudafloat alpha=CUDA_VALUE(1.0), cudafloat beta=CUDA_VALUE(0.0))
 

Protected Member Functions

void Init ()
 
void MoveFrom (BaseMatrix< Type > &other)
 

Protected Attributes

Type * matrixData
 
int rows
 
int columns
 
StoringOrder storingOrder
 

Detailed Description

template<class Type>
class GPUMLib::DeviceMatrix< Type >

Create a matrix of any type, on the device, that automatically manages the memory used to hold its elements.

Definition at line 35 of file DeviceMatrix.h.

Constructor & Destructor Documentation

DeviceMatrix ( 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 70 of file DeviceMatrix.h.

DeviceMatrix ( 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 76 of file DeviceMatrix.h.

DeviceMatrix ( const DeviceMatrix< Type > &  other)
inline

Constructs a matrix identical to another

Parameters
otheranother matrix

Definition at line 83 of file DeviceMatrix.h.

DeviceMatrix ( const HostMatrix< Type > &  other)
inline

Constructs a matrix identical to an host matrix

Parameters
otherhost matrix

Definition at line 89 of file DeviceMatrix.h.

DeviceMatrix ( DeviceMatrix< Type > &&  temporaryMatrix)
inline

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

Parameters
temporaryMatrixtemporary device matrix containing the elements

Definition at line 95 of file DeviceMatrix.h.

Member Function Documentation

int Columns ( ) const
inlineinherited

Gets the number of columns of the matrix

Returns
the number of columns of the matrix

Definition at line 80 of file BaseMatrix.h.

int Elements ( ) const
inlineinherited

Gets the number of elements contained in the matrix

Returns
the number of elements contained in the matrix

Definition at line 94 of file BaseMatrix.h.

bool IsRowMajor ( ) const
inlineinherited

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 100 of file BaseMatrix.h.

static void Multiply ( DeviceMatrix< Type > &  A,
DeviceMatrix< Type > &  B,
DeviceMatrix< Type > &  C,
cudafloat  alpha = CUDA_VALUE(1.0),
cudafloat  beta = CUDA_VALUE(0.0) 
)
inlinestatic

Multiplies matrix A by Matrix B and places the result in C. More specifically C = alpha * (A * B) + beta * C. This method uses the CUBLAS library.

Attention
Matrix C is returned in column-major order. If beta is different than zero, Matrix C must already be in column-major order.
Best performance is achieved when all matrices are in column-major order.
Parameters
Amatrix A. The number of columns of A must be identical to the number of B rows.
Bmatrix B. The number of rows of B must be identical to the number of A columns.
Cmatrix C. The number of rows of C must be identical to the number of rows of A and the number of columns of C must be identical to the number of columns of B.
alphaalpha scalar parameter (default value is 1.0).
betabeta scalar parameter (default value is 0.0). If beta is different than zero, Matrix C must already be in column-major order.
See also
IsRowMajor, ReplaceByTranspose, Transpose
Warning
The CUBLAS library must be initialized prior to the use of this method. Use cublasInit() to initialize the CUBLAS library. Don't forget to call cublasShutdown() when you no longer need to use the CUBLAS library.

Definition at line 192 of file DeviceMatrix.h.

void MultiplyBySelfTranspose ( DeviceMatrix< Type > &  C,
cudafloat  alpha = CUDA_VALUE(1.0),
cudafloat  beta = CUDA_VALUE(0.0) 
)
inline

Multiplies the matrix by its own transpose and places the result in matrix C. More specifically C = alpha * (A * transpose(A)) + beta * C. This method uses the CUBLAS library.

Attention
Matrix C is returned in column-major order. If beta is different than zero, Matrix C must already be in column-major order.
Parameters
Cmatrix C. The number of rows and columns of C must be identical to the number of rows of A.
alphaalpha scalar parameter (default value is 1.0).
betabeta scalar parameter (default value is 0.0). If beta is different than zero, Matrix C must already be in column-major order.
See also
IsRowMajor
Warning
The CUBLAS library must be initialized prior to the use of this method. Use cublasInit() to initialize the CUBLAS library. Don't forget to call cublasShutdown() when you no longer need to use the CUBLAS library.

Definition at line 170 of file DeviceMatrix.h.

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

Transforms this matrix into an matrix identical to an 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 109 of file DeviceMatrix.h.

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

Transforms this matrix into an matrix identical to the other

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 119 of file DeviceMatrix.h.

DeviceMatrix<Type>& operator= ( DeviceMatrix< Type > &&  temporaryMatrix)
inline

Replaces this matrix using a temporary matrix (rvalue)

Parameters
temporaryMatrixtemporary matrix
Returns
a reference to this matrix

Definition at line 127 of file DeviceMatrix.h.

Type* Pointer ( ) const
inlineinherited

Gets a pointer to the 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 88 of file BaseMatrix.h.

void ReplaceByTranspose ( )
inlineinherited

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 107 of file BaseMatrix.h.

int ResizeWithoutPreservingData ( int  rows,
int  columns 
)
inlineinherited

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 119 of file BaseMatrix.h.

int Rows ( ) const
inlineinherited

Gets the number of rows of the matrix

Returns
the number of rows of the matrix

Definition at line 74 of file BaseMatrix.h.

void TransferOwnerShipFrom ( DeviceMatrix< Type > &  other)
inline

Releases its own resources (elements) and obtains ownership of another matrix resources. The other matrix will no longer have any elements. In other words, it moves the elements from one device matrix to another.

Parameters
othermatrix containing the elements to be moved.

Definition at line 140 of file DeviceMatrix.h.

DeviceMatrix<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 156 of file DeviceMatrix.h.


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