1 / 12

GPGPU labor IX .

GPGPU labor IX. Line áris egyenletrendszerek megoldása. Kezdeti teendők. Tantárgy honlapja, Lineáris egyenletrendszerek A labor kiindulási alapjának letöltése (lab9_base.zip), kitömörítés a GPGPU Labs könyvtárba. Gauss-Jordan elimináció. // TODO // // ID := get_local_id(0) //

kibo-lucas
Download Presentation

GPGPU labor IX .

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. GPGPU labor IX. Lineáris egyenletrendszerek megoldása

  2. Kezdeti teendők • Tantárgy honlapja, Lineáris egyenletrendszerek • A labor kiindulási alapjának letöltése (lab9_base.zip), kitömörítés a GPGPU\Labs könyvtárba

  3. Gauss-Jordan elimináció // TODO // // ID := get_local_id(0) // // LOOP ma := 0 .. m DO: // pivot := A[ma + ma * n] // coeff := A[ma + ID * n] / pivot // BARRIER // IF ID != ma DO: // LOOP na := 0 .. n DO: // A[na + id * n] := A[na + id * n] - coeff * A[na + n * ma]; // ENDIF // BARRIER // END LOOP // // coeff := A[ID + ID * n] // LOOP na := 0 .. n DO: // A[na + id * n] = A[na + id * n] / coeff __kernel void gaussian(const int n, const int m, __global float* A){ }

  4. Minta egyenletrendszer int n = 4; int m = 3; float A[] = {2, 1, -1, 8, -3, -1, 2, -11, -2, 1, 2, -3};

  5. Mátrix invertálás int n = 6; int m = 3; float A[] = { 2, -1, 0, 1, 0, 0, -1, 2, -1, 0, 1, 0, 0, -1, 2, 0, 0, 1};

  6. Mátrix vektor szorzásCPU implementáció voidscalarMV(int n, int m, float* y, constfloat* A, constfloat* x, constfloat* b){ for(int i=0; i<n; ++i){ floatyi = b[i]; for(int j=0; j<m; ++j){ yi += A[i * m + j] * x[j]; } y[i] = yi; } }

  7. Mátrix vektor szorzásGPU implementáció I // TODO // // i := get_global_id(0) // // IF ID < n DO: // yi := b[i] // LOOP j := 0 .. m DO: // yi += A[j + i * m] * x[j] // END LOOP // y[i] := yi // END IF __kernel void simpleMV(const int n, const int m, __global float* y, __global float* A, __global float* x, __global float* b){ }

  8. Mátrix vektor szorzásGPU implementáció II // TODO // // i = get_group_id(0) // j = get_local_id(0) // // Q[j] := A[i * M + j] * x[j] // BARRIER // // Sum scan on Q (reduction) // // IF j = 0 THEN: // y[i] = Q[0] + b[i] // __kernel void reduceMV(const int n, __global float* y, __global float* A, __global float* x, __global float* b, const int M, __local float* Q){ }

  9. Mátrix vektor szorzásGPU implementáció III // TODO // // t := get_local_id(0) / Z // z := get_local_id(0) % Z // // FOR i := t ; i < n ; i := i + T : // Q[t * Z + z] = 0 // FOR j := z ; j < m ; j += Z : // Q[t * Z + z] += A[j + i * m] * x[j] // END FOR // END FOR // // Sum scan on Q (reduction) // // IF z = 0 THEN: // y[i] = Q[t * Z + 0] + b[i] // __kernel void largeMV(constint n, constint m, __global float* y, __global float* A, __global float* x, __global float* b, constint T, constint Z, __local float* Q){ }

  10. Mátrixvektorszorzás • Terjesszükvalamelymegoldásttöbbmunkacsoportra!

  11. Jacobi iteráció void jacobi(){ int n = 8; float* x[2] = {NULL, NULL}; x[0] = newfloat[n]; x[1] = newfloat[n]; for(int i = 0; i < n; ++i){ x[0][i] = 0.0f; x[1][i] = 0.0f; } float* A = newfloat[n * n]; for(int i = 0; i < n; ++i){ for(int j = 0; j < n; ++j){ float v = 0.0f; if( i == j){ v = 0.5f; } A[i + j * n] = v; } } float* b = newfloat[n]; for(int i = 0; i < n; ++i){ b[i] = 1.0f; } int inputBuffer = 0; const int iterations = 20; for(int i = 0; i < iterations; ++i){ largeMV(n, n, x[(inputBuffer + 1) % 2], A, x[inputBuffer], b); inputBuffer = (inputBuffer + 1) % 2; printResult(n, x[inputBuffer], "Jakobi"); } delete x[0]; delete x[1]; delete A; delete b; }

  12. Jacobi iteráció • Próbáljukkimásegyenletrendszerre is! • Próbáljukki, hogymi történik, ha nemmegoldhatóazegyenletrendszer!

More Related