Skip to content

Instantly share code, notes, and snippets.

@blackball
Created March 11, 2014 14:49
Show Gist options
  • Select an option

  • Save blackball/9487335 to your computer and use it in GitHub Desktop.

Select an option

Save blackball/9487335 to your computer and use it in GitHub Desktop.
#define CUDA_KERNEL_GUARD(i, n) for(int i = blockIdx.x * blockDim.x + threadIdx.x; i < n; i += blockDim.x * gridDim.x)
__global__
void saxpy(int n, float a, float *x, float *y) {
CUDA_KERNEL_GUARD(i, n) {
y[i] = a * x[i] + y[i];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment