Skip to content
Snippets Groups Projects
Commit d22e26e6 authored by dansa828's avatar dansa828
Browse files

Lab4 updates

parent fa04cadc
No related branches found
No related tags found
No related merge requests found
......@@ -6,17 +6,21 @@
#include <stdio.h>
#include <cmath>
const int N = 32;
const int blocksize = 64;
const int gridsize = 4;
const int N = 1024;
const int blocksize = 32; //threads
const int gridsize = 32; //blocks
__global__
void add(float* result, float *c, float *d)
void add(float* result, float *c, float *d, int N)
{
int idx = blockIdx.x * blockDim.x + threadIdx.x;
int idy = blockIdx.y * blockDim.y + threadIdx.y;
int index = idy * blockDim.x + idx;
result[index] = c[index] + d[index];
int index = idx + idy * N;
if (idx < N && idy < N) {
result[index] = c[index] + d[index];
}
}
int main()
......@@ -51,7 +55,7 @@ int main()
cudaEventCreate(&startEvent);
cudaEventCreate(&finEvent);
cudaEventRecord(startEvent, 0);
add<<<dimGrid, dimBlock>>>(result_cuda, c, d);
add<<<dimGrid, dimBlock>>>(result_cuda, c, d, N);
cudaThreadSynchronize();
cudaEventRecord(finEvent, 0);
cudaEventSynchronize(finEvent);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment