-
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.
- Loading branch information
Showing
10 changed files
with
339 additions
and
58 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#ifndef MY_LINALG | ||
|
||
#define MY_LINALG | ||
|
||
extern void A_D_At(int n, double *A, double *D, double *R); | ||
extern void A_Dinv_At(int n, double *A, double *D, double *R); | ||
|
||
extern void A_D_inplace(int n, double *A, double *D); | ||
extern void A_Dinv_inplace(int n, double *A, double *D); | ||
|
||
extern void elementwise_dsqrt(int nS, double *A, double *A_Sq); | ||
extern void elementwise_dsqrt_inplace(int nS, double *A); | ||
|
||
extern void diag_dn_dsyevd(int n, int *info, double *W, double *A); | ||
|
||
#endif |
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
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_inplace_kernel(int n, double *A, double *D) { | ||
|
||
|
||
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; | ||
|
||
A[ji] = A[ji] * tmp; | ||
|
||
j += blockDim.y * gridDim.y; | ||
} // j | ||
|
||
i += blockDim.x * gridDim.x; | ||
} // i | ||
|
||
} | ||
|
||
|
||
|
||
|
||
|
||
extern "C" void A_D_inplace(int n, double *A, double *D) { | ||
|
||
|
||
int sBlocks = 32; | ||
int nBlocks = (n + sBlocks - 1) / sBlocks; | ||
|
||
dim3 dimGrid(nBlocks, nBlocks, 1); | ||
dim3 dimBlock(sBlocks, sBlocks, 1); | ||
|
||
printf("lunching A_D_inplace_kernel with %dx%d blocks and %dx%d threads/block\n", | ||
nBlocks, nBlocks, sBlocks, sBlocks); | ||
|
||
|
||
A_D_inplace_kernel<<<dimGrid, dimBlock>>>(n, A, D); | ||
|
||
} | ||
|
||
|
||
|
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_Dinv_inplace_kernel(int n, double *A, double *D) { | ||
|
||
|
||
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 / (1e-12 + D[i]); | ||
|
||
while(j < n) { | ||
|
||
ji = in + j; | ||
|
||
A[ji] = A[ji] * tmp; | ||
|
||
j += blockDim.y * gridDim.y; | ||
} // j | ||
|
||
i += blockDim.x * gridDim.x; | ||
} // i | ||
|
||
} | ||
|
||
|
||
|
||
|
||
|
||
extern "C" void A_Dinv_inplace(int n, double *A, double *D) { | ||
|
||
|
||
int sBlocks = 32; | ||
int nBlocks = (n + sBlocks - 1) / sBlocks; | ||
|
||
dim3 dimGrid(nBlocks, nBlocks, 1); | ||
dim3 dimBlock(sBlocks, sBlocks, 1); | ||
|
||
printf("lunching A_Dinv_inplace_kernel with %dx%d blocks and %dx%d threads/block\n", | ||
nBlocks, nBlocks, sBlocks, sBlocks); | ||
|
||
|
||
A_Dinv_inplace_kernel<<<dimGrid, dimBlock>>>(n, A, D); | ||
|
||
} | ||
|
||
|
||
|
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,51 @@ | ||
#include <stdio.h> | ||
#include <math.h> | ||
|
||
|
||
__global__ void elementwise_dsqrt_kernel(int nS, double *A, double *A_Sq) { | ||
|
||
|
||
int i; | ||
|
||
i = blockIdx.x * blockDim.x + threadIdx.x; | ||
|
||
while(i < nS) { | ||
|
||
if(A[i] > 0.0) { | ||
|
||
A_Sq[i] = sqrt(A[i]); | ||
|
||
} else { | ||
|
||
A_Sq[i] = sqrt(-A[i]); | ||
|
||
} | ||
|
||
i += blockDim.x * gridDim.x; | ||
} // i | ||
|
||
} | ||
|
||
|
||
|
||
|
||
|
||
extern "C" void elementwise_dsqrt(int nS, double *A, double *A_Sq) { | ||
|
||
int sBlocks = 32; | ||
int nBlocks = (nS + sBlocks - 1) / sBlocks; | ||
|
||
dim3 dimGrid(nBlocks, 1, 1); | ||
dim3 dimBlock(sBlocks, 1, 1); | ||
|
||
printf("lunching elementwise_dsqrt_kernel with %d blocks and %d threads/block\n", | ||
nBlocks, sBlocks); | ||
|
||
|
||
elementwise_dsqrt_kernel<<<dimGrid, dimBlock>>>(nS, A, A_Sq); | ||
|
||
} | ||
|
||
|
||
|
||
|
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.