| 7 | //template |
| 8 | template <typename T> |
| 9 | __global__ void batchedQRKernel(T* d_Q, T* d_A, size_s rows, size_s cols, size_s batchSize) { |
| 10 | size_s batchIdx = blockIdx.x * blockDim.x + threadIdx.x; |
| 11 | if (batchIdx < batchSize){ |
| 12 | // performe a 3-col QR decomposition by hand |
| 13 | // get the pointer to the current batch |
| 14 | T* A_c = d_A + batchIdx * rows * cols; |
| 15 | T* Q_c = d_Q + batchIdx * rows * cols; |
| 16 | // get the pointer to the first column of the current batch |
| 17 | // for(int i = 0; i < cols; ++i){ |
| 18 | // for(int j = 0; j < rows; ++j){ |
| 19 | // Q_c[i*rows + j] = A_c[i*rows + j]; |
| 20 | // } |
| 21 | // for(int j = 0; j < i; ++j){ |
| 22 | // T uudot = 0; |
| 23 | // T uadot = 0; |
| 24 | // for(int k = 0; k < rows; ++k){ |
| 25 | // uadot += Q_c[j*rows + k] * A_c[i*rows + k]; |
| 26 | // } |
| 27 | // for(int k = 0; k < rows; ++k){ |
| 28 | // Q_c[i*rows + k] -= uadot * Q_c[j*rows + k]; |
| 29 | |
| 30 | // } |
| 31 | |
| 32 | // } |
| 33 | // T qqdot = 0; |
| 34 | // for(int k = 0; k < rows; ++k){ |
| 35 | // qqdot += Q_c[i*rows + k] * Q_c[i*rows + k]; |
| 36 | // } |
| 37 | // qqdot = sqrt(qqdot); |
| 38 | // for(int k = 0; k < rows; ++k){ |
| 39 | // Q_c[i*rows + k] /= qqdot; |
| 40 | // } |
| 41 | // } |
| 42 | for(int i = 0; i < cols; ++i){ |
| 43 | for(int j = 0; j < rows; ++j){ |
| 44 | Q_c[i*rows + j] = A_c[i*rows + j]; |
| 45 | } |
| 46 | } |
| 47 | for(int i = 0; i < cols; ++i){ |
| 48 | T qqdot = 0; |
| 49 | for(int k = 0; k < rows; ++k){ |
| 50 | qqdot += Q_c[i*rows + k] * Q_c[i*rows + k]; |
| 51 | } |
| 52 | qqdot = sqrt(qqdot); |
| 53 | //printf("qqdot: %1.20e %d\n", qqdot, i); |
| 54 | for(int k = 0; k < rows; ++k){ |
| 55 | Q_c[i*rows + k] /= qqdot; |
| 56 | } |
| 57 | for(int j = i+1; j < cols; ++j){ |
| 58 | T uudot = 0; |
| 59 | for(int k = 0; k < rows; ++k){ |
| 60 | uudot += Q_c[i*rows + k] * Q_c[j*rows + k]; |
| 61 | } |
| 62 | //printf("uudot: %1.20e %d %d\n", uudot, i, j); |
| 63 | for(int k = 0; k < rows; ++k){ |
| 64 | Q_c[j*rows + k] -= uudot * Q_c[i*rows + k]; |
| 65 | } |
| 66 | } |
nothing calls this directly
no outgoing calls
no test coverage detected