OSDN Git Service

CUDA
[eos/hostdependX86LINUX64.git] / util / X86LINUX64 / cuda-6.5 / include / thrust / uninitialized_copy.h
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
18 /*! \file uninitialized_copy.h
19  *  \brief Copy construction into a range of uninitialized elements from a source range
20  */
21
22 #pragma once
23
24 #include <thrust/detail/config.h>
25 #include <thrust/detail/execution_policy.h>
26
27 namespace thrust
28 {
29
30
31 /*! \addtogroup copying
32  *  \{
33  */
34
35
36 /*! In \c thrust, the function \c thrust::device_new allocates memory for
37  *  an object and then creates an object at that location by calling a constructor.
38  *  Occasionally, however, it is useful to separate those two operations.
39  *  If each iterator in the range <tt>[result, result + (last - first))</tt> points
40  *  to uninitialized memory, then \p uninitialized_copy creates a copy of
41  *  <tt>[first, last)</tt> in that range. That is, for each iterator \c i in
42  *  the input, \p uninitialized_copy creates a copy of \c *i in the location pointed
43  *  to by the corresponding iterator in the output range by \p ForwardIterator's
44  *  \c value_type's copy constructor with *i as its argument.
45  *
46  *  The algorithm's execution is parallelized as determined by \p exec.
47  *
48  *  \param exec The execution policy to use for parallelization.
49  *  \param first The first element of the input range to copy from.
50  *  \param last The last element of the input range to copy from.
51  *  \param result The first element of the output range to copy to.
52  *  \return An iterator pointing to the last element of the output range.
53  *
54  *  \tparam DerivedPolicy The name of the derived execution policy.
55  *  \tparam InputIterator is a model of <a href="http://www.sgi.com/tech/stl/InputIterator.html">Input Iterator</a>.
56  *  \tparam ForwardIterator is a model of <a href="http://www.sgi.com/tech/stl/ForwardIterator.html">Forward Iterator</a>,
57  *          \p ForwardIterator is mutable, and \p ForwardIterator's \c value_type has a constructor that takes
58  *          a single argument whose type is \p InputIterator's \c value_type.
59  *
60  *  \pre \p first may equal \p result, but the range <tt>[first, last)</tt> and the range <tt>[result, result + (last - first))</tt> shall not overlap otherwise.
61  *
62  *  The following code snippet demonstrates how to use \p uninitialized_copy to initialize
63  *  a range of uninitialized memory using the \p thrust::device execution policy for
64  *  parallelization:
65  *
66  *  \code
67  *  #include <thrust/uninitialized_copy.h>
68  *  #include <thrust/device_malloc.h>
69  *  #include <thrust/device_vector.h>
70  *  #include <thrust/execution_policy.h>
71  *  
72  *  struct Int
73  *  {
74  *    __host__ __device__
75  *    Int(int x) : val(x) {}
76  *    int val;
77  *  };  
78  *  ...
79  *  const int N = 137;
80  *
81  *  Int val(46);
82  *  thrust::device_vector<Int> input(N, val);
83  *  thrust::device_ptr<Int> array = thrust::device_malloc<Int>(N);
84  *  thrust::uninitialized_copy(thrust::device, input.begin(), input.end(), array);
85  *
86  *  // Int x = array[i];
87  *  // x.val == 46 for all 0 <= i < N
88  *  \endcode
89  *
90  *  \see http://www.sgi.com/tech/stl/uninitialized_copy.html
91  *  \see \c copy
92  *  \see \c uninitialized_fill
93  *  \see \c device_new
94  *  \see \c device_malloc
95  */
96 template<typename DerivedPolicy, typename InputIterator, typename ForwardIterator>
97   ForwardIterator uninitialized_copy(const thrust::detail::execution_policy_base<DerivedPolicy> &exec,
98                                      InputIterator first,
99                                      InputIterator last,
100                                      ForwardIterator result);
101
102
103 /*! In \c thrust, the function \c thrust::device_new allocates memory for
104  *  an object and then creates an object at that location by calling a constructor.
105  *  Occasionally, however, it is useful to separate those two operations.
106  *  If each iterator in the range <tt>[result, result + (last - first))</tt> points
107  *  to uninitialized memory, then \p uninitialized_copy creates a copy of
108  *  <tt>[first, last)</tt> in that range. That is, for each iterator \c i in
109  *  the input, \p uninitialized_copy creates a copy of \c *i in the location pointed
110  *  to by the corresponding iterator in the output range by \p ForwardIterator's
111  *  \c value_type's copy constructor with *i as its argument.
112  *
113  *  \param first The first element of the input range to copy from.
114  *  \param last The last element of the input range to copy from.
115  *  \param result The first element of the output range to copy to.
116  *  \return An iterator pointing to the last element of the output range.
117  *
118  *  \tparam InputIterator is a model of <a href="http://www.sgi.com/tech/stl/InputIterator.html">Input Iterator</a>.
119  *  \tparam ForwardIterator is a model of <a href="http://www.sgi.com/tech/stl/ForwardIterator.html">Forward Iterator</a>,
120  *          \p ForwardIterator is mutable, and \p ForwardIterator's \c value_type has a constructor that takes
121  *          a single argument whose type is \p InputIterator's \c value_type.
122  *
123  *  \pre \p first may equal \p result, but the range <tt>[first, last)</tt> and the range <tt>[result, result + (last - first))</tt> shall not overlap otherwise.
124  *
125  *  The following code snippet demonstrates how to use \p uninitialized_copy to initialize
126  *  a range of uninitialized memory.
127  *
128  *  \code
129  *  #include <thrust/uninitialized_copy.h>
130  *  #include <thrust/device_malloc.h>
131  *  #include <thrust/device_vector.h>
132  *  
133  *  struct Int
134  *  {
135  *    __host__ __device__
136  *    Int(int x) : val(x) {}
137  *    int val;
138  *  };  
139  *  ...
140  *  const int N = 137;
141  *
142  *  Int val(46);
143  *  thrust::device_vector<Int> input(N, val);
144  *  thrust::device_ptr<Int> array = thrust::device_malloc<Int>(N);
145  *  thrust::uninitialized_copy(input.begin(), input.end(), array);
146  *
147  *  // Int x = array[i];
148  *  // x.val == 46 for all 0 <= i < N
149  *  \endcode
150  *
151  *  \see http://www.sgi.com/tech/stl/uninitialized_copy.html
152  *  \see \c copy
153  *  \see \c uninitialized_fill
154  *  \see \c device_new
155  *  \see \c device_malloc
156  */
157 template<typename InputIterator, typename ForwardIterator>
158   ForwardIterator uninitialized_copy(InputIterator first,
159                                      InputIterator last,
160                                      ForwardIterator result);
161
162
163 /*! In \c thrust, the function \c thrust::device_new allocates memory for
164  *  an object and then creates an object at that location by calling a constructor.
165  *  Occasionally, however, it is useful to separate those two operations.
166  *  If each iterator in the range <tt>[result, result + n)</tt> points
167  *  to uninitialized memory, then \p uninitialized_copy_n creates a copy of
168  *  <tt>[first, first + n)</tt> in that range. That is, for each iterator \c i in
169  *  the input, \p uninitialized_copy_n creates a copy of \c *i in the location pointed
170  *  to by the corresponding iterator in the output range by \p InputIterator's
171  *  \c value_type's copy constructor with *i as its argument.
172  *
173  *  The algorithm's execution is parallelized as determined by \p exec.
174  *
175  *  \param exec The execution policy to use for parallelization.
176  *  \param first The first element of the input range to copy from.
177  *  \param n The number of elements to copy.
178  *  \param result The first element of the output range to copy to.
179  *  \return An iterator pointing to the last element of the output range.
180  *
181  *  \tparam DerivedPolicy The name of the derived execution policy.
182  *  \tparam InputIterator is a model of <a href="http://www.sgi.com/tech/stl/InputIterator.html">Input Iterator</a>.
183  *  \tparam Size is an integral type.
184  *  \tparam ForwardIterator is a model of <a href="http://www.sgi.com/tech/stl/ForwardIterator.html">Forward Iterator</a>,
185  *          \p ForwardIterator is mutable, and \p ForwardIterator's \c value_type has a constructor that takes
186  *          a single argument whose type is \p InputIterator's \c value_type.
187  *
188  *  \pre \p first may equal \p result, but the range <tt>[first, first + n)</tt> and the range <tt>[result, result + n)</tt> shall not overlap otherwise.
189  *
190  *  The following code snippet demonstrates how to use \p uninitialized_copy to initialize
191  *  a range of uninitialized memory using the \p thrust::device execution policy for
192  *  parallelization:
193  *
194  *  \code
195  *  #include <thrust/uninitialized_copy.h>
196  *  #include <thrust/device_malloc.h>
197  *  #include <thrust/device_vector.h>
198  *  #include <thrust/execution_policy.h>
199  *  
200  *  struct Int
201  *  {
202  *    __host__ __device__
203  *    Int(int x) : val(x) {}
204  *    int val;
205  *  };  
206  *  ...
207  *  const int N = 137;
208  *
209  *  Int val(46);
210  *  thrust::device_vector<Int> input(N, val);
211  *  thrust::device_ptr<Int> array = thrust::device_malloc<Int>(N);
212  *  thrust::uninitialized_copy_n(thrust::device, input.begin(), N, array);
213  *
214  *  // Int x = array[i];
215  *  // x.val == 46 for all 0 <= i < N
216  *  \endcode
217  *
218  *  \see http://www.sgi.com/tech/stl/uninitialized_copy.html
219  *  \see \c uninitialized_copy
220  *  \see \c copy
221  *  \see \c uninitialized_fill
222  *  \see \c device_new
223  *  \see \c device_malloc
224  */
225 template<typename DerivedPolicy, typename InputIterator, typename Size, typename ForwardIterator>
226   ForwardIterator uninitialized_copy_n(const thrust::detail::execution_policy_base<DerivedPolicy> &exec,
227                                        InputIterator first,
228                                        Size n,
229                                        ForwardIterator result);
230
231
232 /*! In \c thrust, the function \c thrust::device_new allocates memory for
233  *  an object and then creates an object at that location by calling a constructor.
234  *  Occasionally, however, it is useful to separate those two operations.
235  *  If each iterator in the range <tt>[result, result + n)</tt> points
236  *  to uninitialized memory, then \p uninitialized_copy_n creates a copy of
237  *  <tt>[first, first + n)</tt> in that range. That is, for each iterator \c i in
238  *  the input, \p uninitialized_copy_n creates a copy of \c *i in the location pointed
239  *  to by the corresponding iterator in the output range by \p InputIterator's
240  *  \c value_type's copy constructor with *i as its argument.
241  *
242  *  \param first The first element of the input range to copy from.
243  *  \param n The number of elements to copy.
244  *  \param result The first element of the output range to copy to.
245  *  \return An iterator pointing to the last element of the output range.
246  *
247  *  \tparam InputIterator is a model of <a href="http://www.sgi.com/tech/stl/InputIterator.html">Input Iterator</a>.
248  *  \tparam Size is an integral type.
249  *  \tparam ForwardIterator is a model of <a href="http://www.sgi.com/tech/stl/ForwardIterator.html">Forward Iterator</a>,
250  *          \p ForwardIterator is mutable, and \p ForwardIterator's \c value_type has a constructor that takes
251  *          a single argument whose type is \p InputIterator's \c value_type.
252  *
253  *  \pre \p first may equal \p result, but the range <tt>[first, first + n)</tt> and the range <tt>[result, result + n)</tt> shall not overlap otherwise.
254  *
255  *  The following code snippet demonstrates how to use \p uninitialized_copy to initialize
256  *  a range of uninitialized memory.
257  *
258  *  \code
259  *  #include <thrust/uninitialized_copy.h>
260  *  #include <thrust/device_malloc.h>
261  *  #include <thrust/device_vector.h>
262  *  
263  *  struct Int
264  *  {
265  *    __host__ __device__
266  *    Int(int x) : val(x) {}
267  *    int val;
268  *  };  
269  *  ...
270  *  const int N = 137;
271  *
272  *  Int val(46);
273  *  thrust::device_vector<Int> input(N, val);
274  *  thrust::device_ptr<Int> array = thrust::device_malloc<Int>(N);
275  *  thrust::uninitialized_copy_n(input.begin(), N, array);
276  *
277  *  // Int x = array[i];
278  *  // x.val == 46 for all 0 <= i < N
279  *  \endcode
280  *
281  *  \see http://www.sgi.com/tech/stl/uninitialized_copy.html
282  *  \see \c uninitialized_copy
283  *  \see \c copy
284  *  \see \c uninitialized_fill
285  *  \see \c device_new
286  *  \see \c device_malloc
287  */
288 template<typename InputIterator, typename Size, typename ForwardIterator>
289   ForwardIterator uninitialized_copy_n(InputIterator first,
290                                        Size n,
291                                        ForwardIterator result);
292
293
294 /*! \} // copying
295  */
296
297
298 } // end thrust
299
300 #include <thrust/detail/uninitialized_copy.inl>
301