1 #include <thrust/device_ptr.h> 2 #include <thrust/fill.h> 3 #include <cuda.h> 4 main(void)5int main(void) 6 { 7 size_t N = 10; 8 9 // obtain raw pointer to device memory 10 int * raw_ptr; 11 cudaMalloc((void **) &raw_ptr, N * sizeof(int)); 12 13 // wrap raw pointer with a device_ptr 14 thrust::device_ptr<int> dev_ptr = thrust::device_pointer_cast(raw_ptr); 15 16 // use device_ptr in Thrust algorithms 17 thrust::fill(dev_ptr, dev_ptr + N, (int) 0); 18 19 // access device memory transparently through device_ptr 20 dev_ptr[0] = 1; 21 22 // free memory 23 cudaFree(raw_ptr); 24 25 return 0; 26 } 27