Skip to content

Instantly share code, notes, and snippets.

@migerh
Created October 10, 2011 17:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save migerh/1275802 to your computer and use it in GitHub Desktop.
Save migerh/1275802 to your computer and use it in GitHub Desktop.
cuda matrix addition example
// 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