#include #include #include template __global__ void copy_kernel(ExecutionPolicy exec, Iterator1 first, Iterator1 last, Iterator2 result) { thrust::copy(exec, first, last, result); } template void TestCopyDevice(ExecutionPolicy exec, size_t n) { thrust::host_vector h_src = unittest::random_integers(n); thrust::host_vector h_dst(n); thrust::device_vector d_src = h_src; thrust::device_vector d_dst(n); thrust::copy(h_src.begin(), h_src.end(), h_dst.begin()); copy_kernel<<<1,1>>>(exec, d_src.begin(), d_src.end(), d_dst.begin()); { cudaError_t const err = cudaDeviceSynchronize(); ASSERT_EQUAL(cudaSuccess, err); } ASSERT_EQUAL(h_dst, d_dst); } template void TestCopyDeviceSeq(size_t n) { TestCopyDevice(thrust::seq, n); } DECLARE_VARIABLE_UNITTEST(TestCopyDeviceSeq); template void TestCopyDeviceDevice(size_t n) { TestCopyDevice(thrust::device, n); } DECLARE_VARIABLE_UNITTEST(TestCopyDeviceDevice); template __global__ void copy_n_kernel(ExecutionPolicy exec, Iterator1 first, Size n, Iterator2 result) { thrust::copy_n(exec, first, n, result); } template void TestCopyNDevice(ExecutionPolicy exec, size_t n) { thrust::host_vector h_src = unittest::random_integers(n); thrust::host_vector h_dst(n); thrust::device_vector d_src = h_src; thrust::device_vector d_dst(n); thrust::copy_n(h_src.begin(), h_src.size(), h_dst.begin()); copy_n_kernel<<<1,1>>>(exec, d_src.begin(), d_src.size(), d_dst.begin()); { cudaError_t const err = cudaDeviceSynchronize(); ASSERT_EQUAL(cudaSuccess, err); } ASSERT_EQUAL(h_dst, d_dst); } template void TestCopyNDeviceSeq(size_t n) { TestCopyNDevice(thrust::seq, n); } DECLARE_VARIABLE_UNITTEST(TestCopyNDeviceSeq); template void TestCopyNDeviceDevice(size_t n) { TestCopyNDevice(thrust::device, n); } DECLARE_VARIABLE_UNITTEST(TestCopyNDeviceDevice);