/matrix_inversion_cuda

Use CUDA to compute matrix inversion

Primary LanguageCuda

Matrix Inversion

main() function

description: call GPU functions to compute inverse matrix, and record the running time.

GPU functions

double *gpuMatrixInverse(double *inputMatrix, const int rows, const int cols)

description:
@param inputMatrix a pointer to an address which stores the input matrix on host
@param rows num of rows in input matrix
@param cols num of cols in input matrix
This function initializes the variables on GPU, and translates the data to GPU. Do Gaussian Elimination on each row of the matrix. Then translate the data back to CPU.


__global__ void augmentMatrixKernel(double *d_augmentedMatrix, double *d_inputMatrix, const int rows, const int cols)

description:
@param d_augmentedMatrix a pointer to an address which stores the augmented Matrix
@param d_inputMatrix a pointer to an address where stores the input matrix
@param rows num of rows in augmented matrix
@param cols num of cols in augmented matrix
This function translates the input matrix to augmented matrix


__global__ void computeRowsKernel(double *d_augmentedMatrix, const int rowId, const int size)

description:
@param d_augmentedMatrix a pointer to an address which stores the augmented Matrix
@param rowId the ID of row to be divided by its pivot
@param size the size of matrix
the row which rowId points is divided by its pivot (whoes row ID equals col ID)


__global__ void harnessZeroKernel(double *d_augmentedMatrix, const int rowId1, const int rowId2, const int size)

description @param d_augmentedMatrix a pointer to an address which stores the augmented Matrix
@param rowId1 the ID of row 1
@param rowId2 the ID of row 2
@param size the size of matrix
if a row's pivot is equal to zero, we can't do row operation, we need add another non-zero row to the current row


__global__ void computeColsKernel(double *d_augmentedMatrix, const int colId, const int size)

description @param d_augmentedMatrix a pointer to an address which stores the augmented Matrix
@param colId ID of col which needs to be zero, except the pivot is 1
@param size the size of matrix
Other rows except colId row are subtracted by the corresponding coefficient.


__global__ void getInverseMatrixKernel(double *d_augmentedMatrix, double *d_inverseMatrix, const int rows, const int cols)

description @param d_augmentedMatrix a pointer to an address which stores the augmented Matrix
@param d_inverseMatrix a pointer to an address which stores the final inversed matrix
@param rows num of rows in augmented matrix
@param cols num of cols in augmented matrix
Get the final inversed matrix