In this section, the example of adding two large arrays is taken to demonstrate the use of a Jetson TX1 development board in executing CUDA programs. The performance of the program is also measured using CUDA events.
The kernel function for adding two large arrays with 50,000 elements is as follows:
#include<iostream>
#include <cuda.h>
#include <cuda_runtime.h>
//Defining number of elements in Array
#define N 50000
//Defining Kernel function for vector addition
__global__ void gpuAdd(int *d_a, int *d_b, int *d_c) {
//Getting Thread index of current kernel
int tid = threadIdx.x + blockIdx.x * blockDim.x;
while (tid < N)
{
d_c[tid] = d_a[tid] + d_b[tid];
tid += blockDim.x * gridDim.x;
}
}
The kernel function takes two device pointers, which point to input arrays as input, and one device pointer, which points to output arrays in the...