/* * Copyright 2008-2012 NVIDIA Corporation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include #include #include #include #include #include #include #include #include #include namespace thrust { namespace system { namespace cuda { namespace detail { namespace detail { template OutputIterator copy_device_to_device(execution_policy &exec, InputIterator begin, InputIterator end, OutputIterator result, thrust::detail::false_type) { // general case (mixed types) typedef typename thrust::iterator_traits::value_type InputType; #if THRUST_DEVICE_COMPILER == THRUST_DEVICE_COMPILER_NVCC return thrust::transform(exec, begin, end, result, thrust::identity()); #else // we're not compiling with nvcc: copy [begin, end) to temp host memory typename thrust::iterator_traits::difference_type n = thrust::distance(begin, end); thrust::host_system_tag temp_exec; thrust::detail::temporary_array temp1(temp_exec, begin, end); // transform temp1 to OutputType in host memory typedef typename thrust::iterator_traits::value_type OutputType; thrust::detail::temporary_array temp2(temp_exec, temp1.begin(), temp1.end()); // copy temp2 to device result = thrust::system::cuda::detail::copy_cross_system(temp2.begin(), temp2.end(), result); return result; #endif // THRUST_DEVICE_COMPILER_NVCC } template OutputIterator copy_device_to_device(execution_policy &exec, InputIterator begin, InputIterator end, OutputIterator result, thrust::detail::true_type) { // specialization for device to device when the value_types match, operator= is not overloaded, // and the iterators are pointers // how many elements to copy? typename thrust::iterator_traits::difference_type n = end - begin; thrust::system::cuda::detail::trivial_copy_n(exec, begin, n, result); return result + n; } } // end namespace detail ///////////////// // Entry Point // ///////////////// template OutputIterator copy_device_to_device(execution_policy &exec, InputIterator begin, InputIterator end, OutputIterator result) { typedef typename thrust::iterator_traits::value_type InputType; typedef typename thrust::iterator_traits::value_type OutputType; const bool use_trivial_copy = thrust::detail::is_same::value && thrust::detail::is_trivial_iterator::value && thrust::detail::is_trivial_iterator::value; // XXX WAR unused variable warning (void) use_trivial_copy; return detail::copy_device_to_device(exec, begin, end, result, thrust::detail::integral_constant()); } } // end namespace detail } // end namespace cuda } // end namespace system } // end namespace thrust