-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
optim A x D x A.T and A x Dinv x A.T on GPU
- Loading branch information
Showing
10 changed files
with
360 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#include <stdio.h> | ||
|
||
|
||
__global__ void A_D_in_B_kernel(int n, double *A, double *D, double *B) { | ||
|
||
|
||
int i, j; | ||
int in, ji; | ||
|
||
double tmp; | ||
|
||
i = blockIdx.x * blockDim.x + threadIdx.x; | ||
j = blockIdx.y * blockDim.y + threadIdx.y; | ||
|
||
while(i < n) { | ||
|
||
in = i * n; | ||
|
||
tmp = D[i]; | ||
|
||
while(j < n) { | ||
|
||
ji = in + j; | ||
|
||
B[ji] = A[ji] * tmp; | ||
|
||
j += blockDim.y * gridDim.y; | ||
} // j | ||
|
||
i += blockDim.x * gridDim.x; | ||
} // i | ||
|
||
} | ||
|
||
|
||
|
||
|
||
|
||
extern "C" void A_D_in_B(int n, double *A, double *D, double *B) { | ||
|
||
|
||
int sBlocks = 32; | ||
int nBlocks = (n + sBlocks - 1) / sBlocks; | ||
|
||
dim3 dimGrid(nBlocks, nBlocks, 1); | ||
dim3 dimBlock(sBlocks, sBlocks, 1); | ||
|
||
printf("lunching A_D_in_B_kernel with %dx%d blocks and %dx%d threads/block\n", | ||
nBlocks, nBlocks, sBlocks, sBlocks); | ||
|
||
|
||
A_D_in_B_kernel<<<dimGrid, dimBlock>>>(n, A, D, B); | ||
|
||
} | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#include <stdio.h> | ||
|
||
|
||
__global__ void A_Dinv_in_B_kernel(int n, double *A, double *D, double *B) { | ||
|
||
|
||
int i, j; | ||
int in, ji; | ||
|
||
double tmp; | ||
|
||
i = blockIdx.x * blockDim.x + threadIdx.x; | ||
j = blockIdx.y * blockDim.y + threadIdx.y; | ||
|
||
while(i < n) { | ||
|
||
in = i * n; | ||
|
||
tmp = 1.0 / D[i]; | ||
|
||
while(j < n) { | ||
|
||
ji = in + j; | ||
|
||
B[ji] = A[ji] * tmp; | ||
|
||
j += blockDim.y * gridDim.y; | ||
} // j | ||
|
||
i += blockDim.x * gridDim.x; | ||
} // i | ||
|
||
} | ||
|
||
|
||
|
||
|
||
|
||
extern "C" void A_Dinv_in_B(int n, double *A, double *D, double *B) { | ||
|
||
|
||
int sBlocks = 32; | ||
int nBlocks = (n + sBlocks - 1) / sBlocks; | ||
|
||
dim3 dimGrid(nBlocks, nBlocks, 1); | ||
dim3 dimBlock(sBlocks, sBlocks, 1); | ||
|
||
printf("lunching A_Dinv_in_B_kernel with %dx%d blocks and %dx%d threads/block\n", | ||
nBlocks, nBlocks, sBlocks, sBlocks); | ||
|
||
|
||
A_Dinv_in_B_kernel<<<dimGrid, dimBlock>>>(n, A, D, B); | ||
|
||
} | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#include <stdio.h> | ||
|
||
|
||
__global__ void A_minus_twoB_in_B_kernel(int n, double *A, double *B) { | ||
|
||
|
||
int i, j; | ||
int in, ji; | ||
|
||
i = blockIdx.x * blockDim.x + threadIdx.x; | ||
j = blockIdx.y * blockDim.y + threadIdx.y; | ||
|
||
while(i < n) { | ||
|
||
in = i * n; | ||
|
||
while(j < n) { | ||
|
||
ji = in + j; | ||
|
||
B[ji] = A[ji] - 2.0 * B[ji]; | ||
|
||
j += blockDim.y * gridDim.y; | ||
} // j | ||
|
||
i += blockDim.x * gridDim.x; | ||
} // i | ||
|
||
} | ||
|
||
|
||
|
||
|
||
extern "C" void A_minus_twoB_in_B(int n, double *A, double *B) { | ||
|
||
|
||
int sBlocks = 32; | ||
int nBlocks = (n + sBlocks - 1) / sBlocks; | ||
|
||
dim3 dimGrid(nBlocks, nBlocks, 1); | ||
dim3 dimBlock(sBlocks, sBlocks, 1); | ||
|
||
printf("lunching A_minus_twoB_in_B_kernel with %dx%d blocks and %dx%d threads/block\n", | ||
nBlocks, nBlocks, sBlocks, sBlocks); | ||
|
||
|
||
A_minus_twoB_in_B_kernel<<<dimGrid, dimBlock>>>(n, A, B); | ||
|
||
} | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#include <stdio.h> | ||
|
||
|
||
__global__ void A_plus_B_in_A_kernel(int n, double *A, double *B) { | ||
|
||
|
||
int i, j; | ||
int in, ji; | ||
|
||
i = blockIdx.x * blockDim.x + threadIdx.x; | ||
j = blockIdx.y * blockDim.y + threadIdx.y; | ||
|
||
while(i < n) { | ||
|
||
in = i * n; | ||
|
||
while(j < n) { | ||
|
||
ji = in + j; | ||
|
||
A[ji] = A[ji] + B[ji]; | ||
|
||
j += blockDim.y * gridDim.y; | ||
} // j | ||
|
||
i += blockDim.x * gridDim.x; | ||
} // i | ||
|
||
} | ||
|
||
|
||
|
||
|
||
extern "C" void A_plus_B_in_A(int n, double *A, double *B) { | ||
|
||
|
||
int sBlocks = 32; | ||
int nBlocks = (n + sBlocks - 1) / sBlocks; | ||
|
||
dim3 dimGrid(nBlocks, nBlocks, 1); | ||
dim3 dimBlock(sBlocks, sBlocks, 1); | ||
|
||
printf("lunching A_plus_B_in_A_kernel with %dx%d blocks and %dx%d threads/block\n", | ||
nBlocks, nBlocks, sBlocks, sBlocks); | ||
|
||
|
||
A_plus_B_in_A_kernel<<<dimGrid, dimBlock>>>(n, A, B); | ||
|
||
} | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.