~cs355001/bin/add.CUDA |
Logout and then log back in to update your shell environment variables.
mkdir ~/cs355/CUDA cp ~cs355001/Handouts/CUDA/* ~/cs355/CUDA |
To help you do this project, I have provided:
|
|
|
/usr/local/cuda/bin/nvcc -o cuda-inverse cuda-inverse.cu |
cuda-inverse N or cuda-inverse N manual // Manual entry of NxN matrix |
|
Inverting a 100x100 matrix: cs355@lab1X (3273)> inverse 100 Elasped time = 16794 micro secs Max err = 0.000208 Inverse is correct ! cs355@lab1X (3274)> cuda-inverse 100 Elasped time = 6477 micro secs N > 5; skip printing... Max err = 0.000133 Inverse is correct ! |
Inverting a 1000x1000 matrix: cs355@lab1X (3275)> inverse 1000 Elasped time = 7262190 micro secs Max err = 0.055180 Inverse is correct ! cs355@lab1X (3276)> cuda-inverse 1000 Elasped time = 4011005 micro secs N > 5; skip printing... Max err = 0.018559 Inverse is correct ! |
Given matrix A A-1 is the inverse of matrix A if and only if: A*A-1 = I where I = the identity matrix |
Example:
+- -+ | 7 2 1 | A = | 0 3 -1 | | -3 4 -2 | +- -+ |
|
void inverse( float *A, float *C, int N) { /* ========================================================== R = a variable that goes through each row of the matrix ========================================================== */ for (int R = 0; R < N; R++) { float factor = A[R*N + R]; // Use A[R][R] as multiply factor for (int j = 0; j < N; j++) // Normalize row R with factor { A[R*N+j] = A[R*N+j]/factor; C[R*N+j] = C[R*N+j]/factor; } /* ========================================================= Make a column of 0 values in column R using the row "R" ========================================================= */ for (int i = 0; i < N; i++) { if (i == R) { // Do nothing to row "R" } else { float f = A[i*N+R]; // Multiply factor /* ------------------------------------- Add -f*row(R) to row(i) ------------------------------------- */ for (int j = 0; j < N; j++) { A[i*N+j] = A[i*N+j] - f*A[R*N+j]; C[i*N+j] = C[i*N+j] - f*C[R*N+j]; } } } } } |
Compile: gcc -o inverse inverse.c Run: inverse N or: inverse N manual // Manual entry of a NxN matrix |
cd ~/cs355/CUDA /home/cs355001/turnin cuda-inverse.cu cuda |
/home/cs355001/req-ext cuda |