Skip to content

Commit

Permalink
Update matAdd.cu
Browse files Browse the repository at this point in the history
  • Loading branch information
linjames0 authored Sep 20, 2023
1 parent d7074e5 commit 9c533de
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions matAdd.cu
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
__global__ void matAdd(float *d_A, float *d_B, float *d_C, int N, int M) {
int row = blockIdx.y * blockDim.y + threadIdx.y;
int col = blockIdx.x * blockDim.x + threadIdx.x;


// add matrix elements
if(row < N && col < M) {
d_C[row * M + col] = d_A[row * M + col] + d_B[row * M + col];
}
Expand Down Expand Up @@ -39,7 +40,6 @@ int main() {
cudaMemcpy(d_B, B, N * M * sizeof(float), cudaMemcpyHostToDevice);
cudaMemcpy(d_C, C, N * M * sizeof(float), cudaMemcpyHostToDevice);

// kernel launch: vector addition
dim3 blockDim(16, 16);
dim3 gridDim((M + blockDim.x - 1)/blockDim.x, (N + blockDim.y - 1)/blockDim.y);
addVectors<<<gridDim, blockDim>>>(d_A, d_B, d_C, N, M);
Expand Down

0 comments on commit 9c533de

Please sign in to comment.