| #include <thrust/detail/raw_reference_cast.h> |
| #include <thrust/device_vector.h> |
| #include <thrust/sequence.h> |
| #include <thrust/fill.h> |
| #include <iostream> |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
|
|
| __host__ __device__ |
| void assign_reference_to_reference(int& x, int& y) |
| { |
| y = x; |
| } |
|
|
| __host__ __device__ |
| void assign_value_to_reference(int x, int& y) |
| { |
| y = x; |
| } |
|
|
| template <typename InputIterator, |
| typename OutputIterator> |
| struct copy_iterators |
| { |
| InputIterator input; |
| OutputIterator output; |
|
|
| copy_iterators(InputIterator input, OutputIterator output) |
| : input(input), output(output) |
| {} |
|
|
| __host__ __device__ |
| void operator()(int i) |
| { |
| InputIterator in = input + i; |
| OutputIterator out = output + i; |
|
|
| |
| |
| |
| |
| assign_reference_to_reference(thrust::raw_reference_cast(*in), thrust::raw_reference_cast(*out)); |
|
|
| |
| assign_value_to_reference(*in, thrust::raw_reference_cast(*out)); |
| } |
| }; |
|
|
| template <typename Vector> |
| void print(const std::string& name, const Vector& v) |
| { |
| typedef typename Vector::value_type T; |
|
|
| std::cout << name << ": "; |
| thrust::copy(v.begin(), v.end(), std::ostream_iterator<T>(std::cout, " ")); |
| std::cout << "\n"; |
| } |
|
|
| int main(void) |
| { |
| typedef thrust::device_vector<int> Vector; |
| typedef Vector::iterator Iterator; |
| typedef thrust::device_system_tag System; |
|
|
| size_t N = 5; |
|
|
| |
| Vector A(N); |
| Vector B(N); |
|
|
| |
| thrust::sequence(A.begin(), A.end()); |
| thrust::fill(B.begin(), B.end(), 0); |
|
|
| std::cout << "Before A->B Copy" << std::endl; |
| print("A", A); |
| print("B", B); |
|
|
| |
| thrust::for_each(thrust::counting_iterator<int,System>(0), |
| thrust::counting_iterator<int,System>(N), |
| copy_iterators<Iterator,Iterator>(A.begin(), B.begin())); |
| |
| std::cout << "After A->B Copy" << std::endl; |
| print("A", A); |
| print("B", B); |
| |
| return 0; |
| } |
|
|
|
|