Parallel for loop in CUDA 7.0
With the release of CUDA 7.0 a subset of CP++11 features are available inside of CUDA kernels. These features are
Without these features a for loop inside a kernel looked very confusing, because the user had to deal with the grid size and the block size to access an element of the data array on the device.
__global__ void sum(int* array , int n, int* count){
for (int i = blockDim.x * blockIdx.x + threadIdx.x;
i < n;
i += gridDim.x * blockDim.x)
{
atomicAdd(&(count[0]), array[i]);
}
}__global__ void sum(int* array,int n , int* count){
for (auto i : grid_stride_range(0,n))
atomicAdd(&(count[0]), array[i]);