Skip to content
This repository has been archived by the owner on Mar 21, 2024. It is now read-only.

Commit

Permalink
Infer the directionality of trivial_copy_n dynamically
Browse files Browse the repository at this point in the history
Because the user may have explicitly passed an execution policy such as thrust::cuda::par.on(stream), trivial_copy_n could be cross-space. Dynamically infer the directionality of the copy using cudaMemcpyDefault.

Fixes #651
  • Loading branch information
jaredhoberock committed Mar 25, 2015
1 parent e2ce20f commit df18386
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion thrust/system/cuda/detail/trivial_copy.inl
Expand Up @@ -86,7 +86,12 @@ void trivial_copy_n(execution_policy<DerivedPolicy> &exec,
void *dst = thrust::raw_pointer_cast(&*result);
const void *src = thrust::raw_pointer_cast(&*first);

trivial_copy_detail::checked_cudaMemcpyAsync(dst, src, n * sizeof(T), cudaMemcpyDeviceToDevice, stream(thrust::detail::derived_cast(exec)));
// since the user may have given thrust::cuda::par to thrust::copy explicitly,
// this copy may be a cross-space copy that has bypassed system dispatch
// we need to have cudaMemcpyAsync figure out the directionality of the copy dynamically
// using cudaMemcpyDefault

trivial_copy_detail::checked_cudaMemcpyAsync(dst, src, n * sizeof(T), cudaMemcpyDefault, stream(thrust::detail::derived_cast(exec)));
#else
thrust::transform(exec, first, first + n, result, thrust::identity<T>());
#endif
Expand Down

0 comments on commit df18386

Please sign in to comment.