Created
October 10, 2011 17:04
-
-
Save migerh/1275802 to your computer and use it in GitHub Desktop.
cuda matrix addition example
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
// Kernel definition | |
__global__ void MatAdd(float A[N][N], float B[N][N], float C[N][N]) { | |
int i = threadIdx.x; | |
int j = threadIdx.y; | |
C[i][j] = A[i][j] + B[i][j]; | |
} | |
int main() { | |
// Kernel invocation with one block of N * N * 1 threads | |
int numBlocks = 1; | |
dim3 threadsPerBlock(N, N); | |
MatAdd<<<numBlocks, threadsPerBlock>>>(A, B, C); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment