OSDN Git Service

CUDA
[eos/hostdependX86LINUX64.git] / util / X86LINUX64 / cuda-6.5 / include / thrust / system / omp / detail / copy.inl
1 /*
2  *  Copyright 2008-2013 NVIDIA Corporation
3  *
4  *  Licensed under the Apache License, Version 2.0 (the "License");
5  *  you may not use this file except in compliance with the License.
6  *  You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *  Unless required by applicable law or agreed to in writing, software
11  *  distributed under the License is distributed on an "AS IS" BASIS,
12  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *  See the License for the specific language governing permissions and
14  *  limitations under the License.
15  */
16
17 #pragma once
18
19 #include <thrust/detail/config.h>
20 #include <thrust/system/omp/detail/copy.h>
21 #include <thrust/system/detail/generic/copy.h>
22 #include <thrust/detail/type_traits/minimum_type.h>
23 #include <thrust/system/cpp/detail/copy.h>
24 #include <thrust/iterator/detail/retag.h>
25
26 namespace thrust
27 {
28 namespace system
29 {
30 namespace omp
31 {
32 namespace detail
33 {
34 namespace dispatch
35 {
36
37 template<typename DerivedPolicy,
38          typename InputIterator,
39          typename OutputIterator>
40   OutputIterator copy(execution_policy<DerivedPolicy> &exec,
41                       InputIterator first,
42                       InputIterator last,
43                       OutputIterator result,
44                       thrust::incrementable_traversal_tag)
45 {
46   return thrust::system::cpp::detail::copy(exec, first, last, result);
47 } // end copy()
48
49
50 template<typename DerivedPolicy,
51          typename InputIterator,
52          typename OutputIterator>
53   OutputIterator copy(execution_policy<DerivedPolicy> &exec,
54                       InputIterator first,
55                       InputIterator last,
56                       OutputIterator result,
57                       thrust::random_access_traversal_tag)
58 {
59   // XXX WAR problems reconciling unrelated types such as omp & tbb
60   // reinterpret iterators as the policy we were passed
61   // this ensures that generic::copy's implementation, which eventually results in
62   // zip_iterator works correctly
63   thrust::detail::tagged_iterator<OutputIterator,DerivedPolicy> retagged_result(result);
64
65   return thrust::system::detail::generic::copy(exec, thrust::reinterpret_tag<DerivedPolicy>(first), thrust::reinterpret_tag<DerivedPolicy>(last), retagged_result).base();
66 } // end copy()
67
68
69 template<typename DerivedPolicy,
70          typename InputIterator,
71          typename Size,
72          typename OutputIterator>
73   OutputIterator copy_n(execution_policy<DerivedPolicy> &exec,
74                         InputIterator first,
75                         Size n,
76                         OutputIterator result,
77                         thrust::incrementable_traversal_tag)
78 {
79   return thrust::system::cpp::detail::copy_n(exec, first, n, result);
80 } // end copy_n()
81
82
83 template<typename DerivedPolicy,
84          typename InputIterator,
85          typename Size,
86          typename OutputIterator>
87   OutputIterator copy_n(execution_policy<DerivedPolicy> &exec,
88                         InputIterator first,
89                         Size n,
90                         OutputIterator result,
91                         thrust::random_access_traversal_tag)
92 {
93   // XXX WAR problems reconciling unrelated types such as omp & tbb
94   // reinterpret iterators as the policy we were passed
95   // this ensures that generic::copy's implementation, which eventually results in
96   // zip_iterator works correctly
97   thrust::detail::tagged_iterator<OutputIterator,DerivedPolicy> retagged_result(result);
98
99   return thrust::system::detail::generic::copy_n(exec, thrust::reinterpret_tag<DerivedPolicy>(first), n, retagged_result).base();
100 } // end copy_n()
101
102 } // end dispatch
103
104
105 template<typename DerivedPolicy,
106          typename InputIterator,
107          typename OutputIterator>
108 OutputIterator copy(execution_policy<DerivedPolicy> &exec,
109                     InputIterator first,
110                     InputIterator last,
111                     OutputIterator result)
112 {
113   typedef typename thrust::iterator_traversal<InputIterator>::type  traversal1;
114   typedef typename thrust::iterator_traversal<OutputIterator>::type traversal2;
115   
116   typedef typename thrust::detail::minimum_type<traversal1,traversal2>::type traversal;
117
118   // dispatch on minimum traversal
119   return thrust::system::omp::detail::dispatch::copy(exec, first,last,result,traversal());
120 } // end copy()
121
122
123
124 template<typename DerivedPolicy,
125          typename InputIterator,
126          typename Size,
127          typename OutputIterator>
128 OutputIterator copy_n(execution_policy<DerivedPolicy> &exec,
129                       InputIterator first,
130                       Size n,
131                       OutputIterator result)
132 {
133   typedef typename thrust::iterator_traversal<InputIterator>::type  traversal1;
134   typedef typename thrust::iterator_traversal<OutputIterator>::type traversal2;
135   
136   typedef typename thrust::detail::minimum_type<traversal1,traversal2>::type traversal;
137
138   // dispatch on minimum traversal
139   return thrust::system::omp::detail::dispatch::copy_n(exec,first,n,result,traversal());
140 } // end copy_n()
141
142
143 } // end namespace detail
144 } // end namespace omp
145 } // end namespace system
146 } // end namespace thrust
147