Skip to content

Instantly share code, notes, and snippets.

@kaityo256
Last active June 21, 2018 20:14
Show Gist options
  • Save kaityo256/0241257bda1d97da1c95 to your computer and use it in GitHub Desktop.
Save kaityo256/0241257bda1d97da1c95 to your computer and use it in GitHub Desktop.
CUDA sample for curand_kernel
#include <stdio.h>
#include <cuda.h>
#include <curand_kernel.h>
__global__ void
func(void){
int id = blockIdx.x * blockDim.x + threadIdx.x;
curandState s;
curand_init(0,id,0,&s);
for(int i=0;i<4;i++){
printf("%d %f\n",id,curand_uniform_double(&s));
}
}
int
main(void){
cudaSetDeviceFlags(cudaDeviceMapHost);
int const n_thread = 2;
int const n_block = 2;
func<<<n_block,n_thread>>>();
printf("Version = %d\n",CUDA_VERSION);
cudaThreadSynchronize();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment