| #include <thrust/device_ptr.h> |
| #include <thrust/device_malloc.h> |
| #include <thrust/device_free.h> |
|
|
| #include <thrust/sequence.h> |
| #include <thrust/reduce.h> |
|
|
| #include <cassert> |
| #include <iostream> |
|
|
| int main(void) |
| { |
| |
| thrust::device_ptr<int> d_ptr = thrust::device_malloc<int>(10); |
|
|
| |
| thrust::device_ptr<int> first = d_ptr; |
| thrust::device_ptr<int> last = d_ptr + 10; |
| std::cout << "device array contains " << (last - first) << " values\n"; |
| |
| |
| thrust::sequence(first, last); |
| std::cout << "sum of values is " << thrust::reduce(first, last) << "\n"; |
| |
| |
| d_ptr[0] = 10; |
| d_ptr[1] = 11; |
| d_ptr[2] = d_ptr[0] + d_ptr[1]; |
|
|
| |
| int * raw_ptr = thrust::raw_pointer_cast(d_ptr); |
|
|
| |
|
|
| |
| thrust::device_ptr<int> wrapped_ptr = thrust::device_pointer_cast(raw_ptr); |
|
|
| |
| assert(wrapped_ptr == d_ptr); |
| (void)wrapped_ptr; |
|
|
| |
| thrust::device_free(d_ptr); |
|
|
| return 0; |
| } |
|
|
|
|