1 | #ifndef META_COPY_HPP |
2 | #define META_COPY_HPP |
3 | |
4 | #include "copy_general.hpp" |
5 | #include "util/cuda_util.hpp" |
6 | #include "util/multi_array_openfpm/multi_array_ref_openfpm.hpp" |
7 | |
8 | /*! \brief This class copy general objects |
9 | * |
10 | * * primitives |
11 | * * array of primitives |
12 | * * complex objects |
13 | * * aggregates |
14 | * |
15 | * ### Usage of meta copy and compare for primitives |
16 | * \snippet meta_cc_unit_tests.hpp Usage of meta copy and compare for primitives |
17 | * ### Usage of meta copy and compare for array of primitives |
18 | * \snippet meta_cc_unit_tests.hpp Usage of meta copy and compare for array of primitives |
19 | * ### Usage of meta copy and compare for openfpm aggregates |
20 | * \snippet meta_cc_unit_tests.hpp Usage of meta copy and compare for openfpm aggregates |
21 | * ### Usage of meta copy and compare for complex object |
22 | * \snippet meta_cc_unit_tests.hpp Usage of meta copy and compare for complex object |
23 | * ### Usage of meta copy and compare for complex aggregates object |
24 | * \snippet meta_cc_unit_tests.hpp Usage of meta copy and compare for complex aggregates object |
25 | * ### Usage of meta copy and compare for Point_test |
26 | * \snippet meta_cc_unit_tests.hpp Usage of meta copy and compare for Point_test |
27 | * |
28 | */ |
29 | template<typename T> |
30 | struct meta_copy |
31 | { |
32 | /*! \brief copy and object from src to dst |
33 | * |
34 | * \param src source object to copy |
35 | * \param dst destination object |
36 | * |
37 | */ |
38 | __device__ __host__ static inline void meta_copy_(const T & src, T & dst) |
39 | { |
40 | copy_general<T>(src,dst); |
41 | } |
42 | |
43 | /*! \brief copy and object from src to dst |
44 | * |
45 | * \param src source object to copy |
46 | * \param dst destination object |
47 | * |
48 | */ |
49 | __device__ __host__ static inline void meta_copy_(const T & src, T && dst) |
50 | { |
51 | copy_general<T>(src,dst); |
52 | } |
53 | }; |
54 | |
55 | /*! \brief copy for a source object to a destination |
56 | * |
57 | * \tparam Tsrc source object |
58 | * \tparam Tdst destination object |
59 | * |
60 | */ |
61 | template<typename Tsrc,typename Tdst> |
62 | struct meta_copy_d |
63 | { |
64 | /*! \brief copy and object from src to dst |
65 | * |
66 | * \param src source object to copy |
67 | * \param dst destination object |
68 | * |
69 | */ |
70 | __device__ __host__ static inline void meta_copy_d_(const Tsrc & src, Tdst & dst) |
71 | { |
72 | copy_general<Tsrc>(src,dst); |
73 | } |
74 | |
75 | /*! \brief copy and object from src to dst |
76 | * |
77 | * \param src source object to copy |
78 | * \param dst destination object |
79 | * |
80 | */ |
81 | __device__ __host__ static inline void meta_copy_d_(const Tsrc & src, Tdst && dst) |
82 | { |
83 | copy_general<Tsrc>(src,dst); |
84 | } |
85 | }; |
86 | |
87 | //! Partial specialization for N=1 1D-Array |
88 | template<typename T,size_t N1> |
89 | struct meta_copy<T[N1]> |
90 | { |
91 | /*! \brief copy and object from src to dst |
92 | * |
93 | * \param src source object to copy |
94 | * \param dst destination object |
95 | * |
96 | */ |
97 | __device__ __host__ static inline void meta_copy_(const T src[N1], T dst[N1]) |
98 | { |
99 | for (size_t i1 = 0 ; i1 < N1 ; i1++) |
100 | { |
101 | copy_general<T>(src[i1],dst[i1]); |
102 | } |
103 | } |
104 | |
105 | /*! \brief copy and object from src to dst |
106 | * |
107 | * \param src source object to copy |
108 | * \param dst destination object |
109 | * |
110 | */ |
111 | template<typename v_mpl> |
112 | __device__ __host__ static inline void meta_copy_(const openfpm::detail::multi_array::sub_array_openfpm<T,1,v_mpl> src, |
113 | openfpm::detail::multi_array::sub_array_openfpm<T,1,v_mpl> dst) |
114 | { |
115 | for (size_t i1 = 0 ; i1 < N1 ; i1++) |
116 | { |
117 | copy_general<T>(src[i1],dst[i1]); |
118 | } |
119 | } |
120 | |
121 | /*! \brief copy and object from src to dst |
122 | * |
123 | * \param src source object to copy |
124 | * \param dst destination object |
125 | * |
126 | */ |
127 | template<typename v_mpl> |
128 | __device__ __host__ static inline void meta_copy_(const openfpm::detail::multi_array::sub_array_openfpm<T,1,v_mpl> src, |
129 | T * dst) |
130 | { |
131 | for (size_t i1 = 0 ; i1 < N1 ; i1++) |
132 | { |
133 | copy_general<T>(src[i1],dst[i1]); |
134 | } |
135 | } |
136 | }; |
137 | |
138 | //! Partial specialization for N=1 1D-Array |
139 | template<typename Tsrc, typename Tdst, size_t N1> |
140 | struct meta_copy_d<Tsrc[N1],Tdst> |
141 | { |
142 | /*! \brief copy and object from src to dst |
143 | * |
144 | * \param src source object to copy |
145 | * \param dst destination object |
146 | * |
147 | */ |
148 | __device__ __host__ static inline void meta_copy_d_(const Tsrc src[N1], Tdst && dst) |
149 | { |
150 | for (size_t i1 = 0 ; i1 < N1 ; i1++) |
151 | { |
152 | copy_general<Tsrc>(src[i1],static_cast<Tsrc&>(dst[i1])); |
153 | } |
154 | } |
155 | |
156 | /*! \brief copy and object from src to dst |
157 | * |
158 | * \param src source object to copy |
159 | * \param dst destination object |
160 | * |
161 | */ |
162 | __device__ __host__ static inline void meta_copy_d_(const Tsrc src[N1], Tdst & dst) |
163 | { |
164 | for (size_t i1 = 0 ; i1 < N1 ; i1++) |
165 | { |
166 | copy_general<Tsrc>(src[i1],static_cast<Tsrc&>(dst[i1])); |
167 | } |
168 | } |
169 | }; |
170 | |
171 | //! Partial specialization for N=1 1D-Array |
172 | template<typename Tsrc, typename Tdst, size_t N1> |
173 | struct meta_copy_d<Tsrc,Tdst[N1]> |
174 | { |
175 | /*! \brief copy and object from src to dst |
176 | * |
177 | * \param src source object to copy |
178 | * \param dst destination object |
179 | * |
180 | */ |
181 | __device__ __host__ static inline void meta_copy_d_(const Tsrc & src, Tdst dst[N1]) |
182 | { |
183 | for (size_t i1 = 0 ; i1 < N1 ; i1++) |
184 | { |
185 | copy_general<Tdst>(static_cast<const Tdst&>(src[i1]),dst[i1]); |
186 | } |
187 | } |
188 | }; |
189 | |
190 | //! Partial specialization for N=1 1D-Array |
191 | template<typename Tsrc, typename Tdst, size_t N1> |
192 | struct meta_copy_d<Tsrc[N1],Tdst[N1]> |
193 | { |
194 | /*! \brief copy and object from src to dst |
195 | * |
196 | * \param src source object to copy |
197 | * \param dst destination object |
198 | * |
199 | */ |
200 | __device__ __host__ static inline void meta_copy_d_(const Tsrc src[N1], Tdst dst[N1]) |
201 | { |
202 | for (size_t i1 = 0 ; i1 < N1 ; i1++) |
203 | { |
204 | copy_general<Tsrc>(src[i1],dst[i1]); |
205 | } |
206 | } |
207 | }; |
208 | |
209 | //! Partial specialization for N=2 2D-Array |
210 | template<typename T,size_t N1,size_t N2> |
211 | struct meta_copy<T[N1][N2]> |
212 | { |
213 | /*! \brief copy and object from src to dst |
214 | * |
215 | * \param src source object to copy |
216 | * \param dst destination object |
217 | * |
218 | */ |
219 | __device__ __host__ static inline void meta_copy_(const T src[N1][N2], T dst[N1][N2]) |
220 | { |
221 | for (size_t i1 = 0 ; i1 < N1 ; i1++) |
222 | { |
223 | for (size_t i2 = 0 ; i2 < N2 ; i2++) |
224 | { |
225 | copy_general<T>(src[i1][i2],dst[i1][i2]); |
226 | } |
227 | } |
228 | } |
229 | |
230 | /*! \brief copy and object from src to dst |
231 | * |
232 | * \param src source object to copy |
233 | * \param dst destination object |
234 | * |
235 | */ |
236 | template<typename v_mpl> |
237 | __device__ __host__ static inline void meta_copy_(const openfpm::detail::multi_array::sub_array_openfpm<T,2,v_mpl> src, |
238 | openfpm::detail::multi_array::sub_array_openfpm<T,2,v_mpl> dst) |
239 | { |
240 | for (size_t i1 = 0 ; i1 < N1 ; i1++) |
241 | { |
242 | for (size_t i2 = 0 ; i2 < N2 ; i2++) |
243 | { |
244 | copy_general<T>(src[i1][i2],dst[i1][i2]); |
245 | } |
246 | } |
247 | } |
248 | |
249 | /*! \brief copy and object from src to dst |
250 | * |
251 | * \param src source object to copy |
252 | * \param dst destination object |
253 | * |
254 | */ |
255 | template<typename v_mpl> |
256 | __device__ __host__ static inline void meta_copy_(const openfpm::detail::multi_array::sub_array_openfpm<T,2,v_mpl> src, |
257 | T dst[N1][N2]) |
258 | { |
259 | for (size_t i1 = 0 ; i1 < N1 ; i1++) |
260 | { |
261 | for (size_t i2 = 0 ; i2 < N2 ; i2++) |
262 | { |
263 | copy_general<T>(src[i1][i2],dst[i1][i2]); |
264 | } |
265 | } |
266 | } |
267 | }; |
268 | |
269 | //! Partial specialization for N=2 2D-Array |
270 | template<typename Tsrc, typename Tdst,size_t N1,size_t N2> |
271 | struct meta_copy_d<Tsrc[N1][N2],Tdst> |
272 | { |
273 | __device__ __host__ static inline void meta_copy_d_(const Tsrc src[N1][N2], Tdst && dst) |
274 | { |
275 | /*! \brief copy and object from src to dst |
276 | * |
277 | * \param src source object to copy |
278 | * \param dst destination object |
279 | * |
280 | */ |
281 | for (size_t i1 = 0 ; i1 < N1 ; i1++) |
282 | { |
283 | for (size_t i2 = 0 ; i2 < N2 ; i2++) |
284 | { |
285 | copy_general<Tsrc>(src[i1][i2],static_cast<Tsrc&>(dst[i1][i2])); |
286 | } |
287 | } |
288 | } |
289 | |
290 | __device__ __host__ static inline void meta_copy_d_(const Tsrc src[N1][N2], Tdst & dst) |
291 | { |
292 | /*! \brief copy and object from src to dst |
293 | * |
294 | * \param src source object to copy |
295 | * \param dst destination object |
296 | * |
297 | */ |
298 | for (size_t i1 = 0 ; i1 < N1 ; i1++) |
299 | { |
300 | for (size_t i2 = 0 ; i2 < N2 ; i2++) |
301 | { |
302 | copy_general<Tsrc>(src[i1][i2],static_cast<Tsrc&>(dst[i1][i2])); |
303 | } |
304 | } |
305 | } |
306 | }; |
307 | |
308 | //! Partial specialization for N=2 2D-Array |
309 | template<typename Tsrc, typename Tdst, size_t N1, size_t N2> |
310 | struct meta_copy_d<Tsrc,Tdst[N1][N2]> |
311 | { |
312 | /*! \brief copy and object from src to dst |
313 | * |
314 | * \param src source object to copy |
315 | * \param dst destination object |
316 | * |
317 | */ |
318 | __device__ __host__ static inline void meta_copy_d_(const Tsrc & src, Tdst dst[N1][N2]) |
319 | { |
320 | for (size_t i1 = 0 ; i1 < N1 ; i1++) |
321 | { |
322 | for (size_t i2 = 0 ; i2 < N2 ; i2++) |
323 | { |
324 | copy_general<Tdst>(static_cast<const Tdst&>(src[i1][i2]),dst[i1][i2]); |
325 | } |
326 | } |
327 | } |
328 | }; |
329 | |
330 | |
331 | |
332 | //! Partial specialization for N=1 1D-Array |
333 | template<typename Tsrc, typename Tdst, size_t N1, size_t N2> |
334 | struct meta_copy_d<Tsrc[N1][N2],Tdst[N1][N2]> |
335 | { |
336 | /*! \brief copy and object from src to dst |
337 | * |
338 | * \param src source object to copy |
339 | * \param dst destination object |
340 | * |
341 | */ |
342 | __device__ __host__ static inline void meta_copy_d_(const Tsrc src[N1][N2], Tdst dst[N1][N2]) |
343 | { |
344 | for (size_t i1 = 0 ; i1 < N1 ; i1++) |
345 | { |
346 | for (size_t i2 = 0 ; i2 < N2 ; i2++) |
347 | { |
348 | copy_general<Tsrc>(src[i1][i2],dst[i1][i2]); |
349 | } |
350 | } |
351 | } |
352 | }; |
353 | |
354 | //! Partial specialization for N=3 |
355 | template<typename T,size_t N1,size_t N2,size_t N3> |
356 | struct meta_copy<T[N1][N2][N3]> |
357 | { |
358 | /*! \brief copy and object from src to dst |
359 | * |
360 | * \param src source object to copy |
361 | * \param dst destination object |
362 | * |
363 | */ |
364 | static inline void meta_copy_(const T src[N1][N2][N3], T dst[N1][N2][N3]) |
365 | { |
366 | for (size_t i1 = 0 ; i1 < N1 ; i1++) |
367 | { |
368 | for (size_t i2 = 0 ; i2 < N2 ; i2++) |
369 | { |
370 | for (size_t i3 = 0 ; i3 < N3 ; i3++) |
371 | { |
372 | copy_general<T>(src[i1][i2][i3],dst[i1][i2][i3]); |
373 | } |
374 | } |
375 | } |
376 | } |
377 | }; |
378 | |
379 | //! Partial specialization for N=4 |
380 | template<typename T,size_t N1,size_t N2,size_t N3,size_t N4> |
381 | struct meta_copy<T[N1][N2][N3][N4]> |
382 | { |
383 | /*! \brief copy and object from src to dst |
384 | * |
385 | * \param src source object to copy |
386 | * \param dst destination object |
387 | * |
388 | */ |
389 | static inline void meta_copy_(const T src[N1][N2][N3][N4], T dst[N1][N2][N3][N4]) |
390 | { |
391 | for (size_t i1 = 0 ; i1 < N1 ; i1++) |
392 | { |
393 | for (size_t i2 = 0 ; i2 < N2 ; i2++) |
394 | { |
395 | for (size_t i3 = 0 ; i3 < N3 ; i3++) |
396 | { |
397 | for (size_t i4 = 0 ; i4 < N4 ; i4++) |
398 | { |
399 | copy_general<T>(src[i1][i2][i3][i4],dst[i1][i2][i3][i4]); |
400 | } |
401 | } |
402 | } |
403 | } |
404 | } |
405 | }; |
406 | |
407 | //! Partial specialization for N=5 |
408 | template<typename T,size_t N1,size_t N2,size_t N3,size_t N4,size_t N5> |
409 | struct meta_copy<T[N1][N2][N3][N4][N5]> |
410 | { |
411 | /*! \brief copy and object from src to dst |
412 | * |
413 | * \param src source object to copy |
414 | * \param dst destination object |
415 | * |
416 | */ |
417 | static inline void meta_copy_(const T src[N1][N2][N3][N4][N5], T dst[N1][N2][N3][N4][N5]) |
418 | { |
419 | for (size_t i1 = 0 ; i1 < N1 ; i1++) |
420 | { |
421 | for (size_t i2 = 0 ; i2 < N2 ; i2++) |
422 | { |
423 | for (size_t i3 = 0 ; i3 < N3 ; i3++) |
424 | { |
425 | for (size_t i4 = 0 ; i4 < N4 ; i4++) |
426 | { |
427 | for (size_t i5 = 0 ; i5 < N5 ; i5++) |
428 | { |
429 | copy_general<T>(src[i1][i2][i3][i4][i5],dst[i1][i2][i3][i4][i5]); |
430 | } |
431 | } |
432 | } |
433 | } |
434 | } |
435 | } |
436 | }; |
437 | |
438 | //! Partial specialization for N=6 |
439 | template<typename T,size_t N1,size_t N2,size_t N3,size_t N4,size_t N5, size_t N6> |
440 | struct meta_copy<T[N1][N2][N3][N4][N5][N6]> |
441 | { |
442 | /*! \brief copy and object from src to dst |
443 | * |
444 | * \param src source object to copy |
445 | * \param dst destination object |
446 | * |
447 | */ |
448 | static inline void meta_copy_(const T src[N1][N2][N3][N4][N5][N6], T dst[N1][N2][N3][N4][N5][N6]) |
449 | { |
450 | for (size_t i1 = 0 ; i1 < N1 ; i1++) |
451 | { |
452 | for (size_t i2 = 0 ; i2 < N2 ; i2++) |
453 | { |
454 | for (size_t i3 = 0 ; i3 < N3 ; i3++) |
455 | { |
456 | for (size_t i4 = 0 ; i4 < N4 ; i4++) |
457 | { |
458 | for (size_t i5 = 0 ; i5 < N5 ; i5++) |
459 | { |
460 | for (size_t i6 = 0 ; i6 < N6 ; i6++) |
461 | { |
462 | copy_general<T>(src[i1][i2][i3][i4][i5][i6],dst[i1][i2][i3][i4][i5][i6]); |
463 | } |
464 | } |
465 | } |
466 | } |
467 | } |
468 | } |
469 | } |
470 | }; |
471 | |
472 | //! Partial specialization for N=7 |
473 | template<typename T,size_t N1,size_t N2,size_t N3,size_t N4,size_t N5, size_t N6, size_t N7> |
474 | struct meta_copy<T[N1][N2][N3][N4][N5][N6][N7]> |
475 | { |
476 | /*! \brief copy and object from src to dst |
477 | * |
478 | * \param src source object to copy |
479 | * \param dst destination object |
480 | * |
481 | */ |
482 | static inline void meta_copy_(const T src[N1][N2][N3][N4][N5][N6][N7], T dst[N1][N2][N3][N4][N5][N6][N7]) |
483 | { |
484 | for (size_t i1 = 0 ; i1 < N1 ; i1++) |
485 | { |
486 | for (size_t i2 = 0 ; i2 < N2 ; i2++) |
487 | { |
488 | for (size_t i3 = 0 ; i3 < N3 ; i3++) |
489 | { |
490 | for (size_t i4 = 0 ; i4 < N4 ; i4++) |
491 | { |
492 | for (size_t i5 = 0 ; i5 < N5 ; i5++) |
493 | { |
494 | for (size_t i6 = 0 ; i6 < N6 ; i6++) |
495 | { |
496 | for (size_t i7 = 0 ; i7 < N7 ; i7++) |
497 | { |
498 | copy_general<T>(src[i1][i2][i3][i4][i5][i6][i7],dst[i1][i2][i3][i4][i5][i6][i7]); |
499 | } |
500 | } |
501 | } |
502 | } |
503 | } |
504 | } |
505 | } |
506 | } |
507 | }; |
508 | |
509 | //! Partial specialization for N=8 |
510 | template<typename T,size_t N1,size_t N2,size_t N3,size_t N4,size_t N5, size_t N6, size_t N7, size_t N8> |
511 | struct meta_copy<T[N1][N2][N3][N4][N5][N6][N7][N8]> |
512 | { |
513 | /*! \brief copy and object from src to dst |
514 | * |
515 | * \param src source object to copy |
516 | * \param dst destination object |
517 | * |
518 | */ |
519 | static inline void meta_copy_(const T src[N1][N2][N3][N4][N5][N6][N7][N8], T dst[N1][N2][N3][N4][N5][N6][N7][N8]) |
520 | { |
521 | for (size_t i1 = 0 ; i1 < N1 ; i1++) |
522 | { |
523 | for (size_t i2 = 0 ; i2 < N2 ; i2++) |
524 | { |
525 | for (size_t i3 = 0 ; i3 < N3 ; i3++) |
526 | { |
527 | for (size_t i4 = 0 ; i4 < N4 ; i4++) |
528 | { |
529 | for (size_t i5 = 0 ; i5 < N5 ; i5++) |
530 | { |
531 | for (size_t i6 = 0 ; i6 < N6 ; i6++) |
532 | { |
533 | for (size_t i7 = 0 ; i7 < N7 ; i7++) |
534 | { |
535 | for (size_t i8 = 0 ; i8 < N8 ; i8++) |
536 | { |
537 | copy_general<T>(src[i1][i2][i3][i4][i5][i6][i7][i8],dst[i1][i2][i3][i4][i5][i6][i7][i8]); |
538 | } |
539 | } |
540 | } |
541 | } |
542 | } |
543 | } |
544 | } |
545 | } |
546 | } |
547 | }; |
548 | |
549 | //! Partial specialization for N=9 |
550 | template<typename T,size_t N1,size_t N2,size_t N3,size_t N4,size_t N5, size_t N6, size_t N7, size_t N8, size_t N9> |
551 | struct meta_copy<T[N1][N2][N3][N4][N5][N6][N7][N8][N9]> |
552 | { |
553 | /*! \brief copy and object from src to dst |
554 | * |
555 | * \param src source object to copy |
556 | * \param dst destination object |
557 | * |
558 | */ |
559 | static inline void meta_copy_(const T src[N1][N2][N3][N4][N5][N6][N7][N8][N9], T dst[N1][N2][N3][N4][N5][N6][N7][N8][N9]) |
560 | { |
561 | for (size_t i1 = 0 ; i1 < N1 ; i1++) |
562 | { |
563 | for (size_t i2 = 0 ; i2 < N2 ; i2++) |
564 | { |
565 | for (size_t i3 = 0 ; i3 < N3 ; i3++) |
566 | { |
567 | for (size_t i4 = 0 ; i4 < N4 ; i4++) |
568 | { |
569 | for (size_t i5 = 0 ; i5 < N5 ; i5++) |
570 | { |
571 | for (size_t i6 = 0 ; i6 < N6 ; i6++) |
572 | { |
573 | for (size_t i7 = 0 ; i7 < N7 ; i7++) |
574 | { |
575 | for (size_t i8 = 0 ; i8 < N8 ; i8++) |
576 | { |
577 | for (size_t i9 = 0 ; i9 < N9 ; i9++) |
578 | { |
579 | copy_general<T>(src[i1][i2][i3][i4][i5][i6][i7][i8][i9],dst[i1][i2][i3][i4][i5][i6][i7][i8][i9]); |
580 | } |
581 | } |
582 | } |
583 | } |
584 | } |
585 | } |
586 | } |
587 | } |
588 | } |
589 | } |
590 | }; |
591 | |
592 | //! Partial specialization for N=10 |
593 | template<typename T,size_t N1,size_t N2,size_t N3,size_t N4,size_t N5, size_t N6, size_t N7, size_t N8, size_t N9, size_t N10> |
594 | struct meta_copy<T[N1][N2][N3][N4][N5][N6][N7][N8][N9][N10]> |
595 | { |
596 | /*! \brief copy and object from src to dst |
597 | * |
598 | * \param src source object to copy |
599 | * \param dst destination object |
600 | * |
601 | */ |
602 | static inline void meta_copy_(const T src[N1][N2][N3][N4][N5][N6][N7][N8][N9][N10], T dst[N1][N2][N3][N4][N5][N6][N7][N8][N9][N10]) |
603 | { |
604 | for (size_t i1 = 0 ; i1 < N1 ; i1++) |
605 | { |
606 | for (size_t i2 = 0 ; i2 < N2 ; i2++) |
607 | { |
608 | for (size_t i3 = 0 ; i3 < N3 ; i3++) |
609 | { |
610 | for (size_t i4 = 0 ; i4 < N4 ; i4++) |
611 | { |
612 | for (size_t i5 = 0 ; i5 < N5 ; i5++) |
613 | { |
614 | for (size_t i6 = 0 ; i6 < N6 ; i6++) |
615 | { |
616 | for (size_t i7 = 0 ; i7 < N7 ; i7++) |
617 | { |
618 | for (size_t i8 = 0 ; i8 < N8 ; i8++) |
619 | { |
620 | for (size_t i9 = 0 ; i9 < N9 ; i9++) |
621 | { |
622 | for (size_t i10 = 0 ; i10 < N10 ; i10++) |
623 | { |
624 | copy_general<T>(src[i1][i2][i3][i4][i5][i6][i7][i8][i9][i10],dst[i1][i2][i3][i4][i5][i6][i7][i8][i9][i10]); |
625 | } |
626 | } |
627 | } |
628 | } |
629 | } |
630 | } |
631 | } |
632 | } |
633 | } |
634 | } |
635 | } |
636 | }; |
637 | |
638 | ////////////////////////// VERSION WITH OPERATION //////////////////////// |
639 | |
640 | |
641 | /*! \brief This class copy general objects applying an operation |
642 | * |
643 | * * primitives |
644 | * * array of primitives |
645 | * * complex objects |
646 | * * aggregates |
647 | * |
648 | * ### Usage of meta copy and compare for primitives |
649 | * \snippet meta_cc_unit_tests.hpp Usage of meta copy and compare for primitives |
650 | * ### Usage of meta copy and compare for array of primitives |
651 | * \snippet meta_cc_unit_tests.hpp Usage of meta copy and compare for array of primitives |
652 | * ### Usage of meta copy and compare for openfpm aggregates |
653 | * \snippet meta_cc_unit_tests.hpp Usage of meta copy and compare for openfpm aggregates |
654 | * ### Usage of meta copy and compare for complex object |
655 | * \snippet meta_cc_unit_tests.hpp Usage of meta copy and compare for complex object |
656 | * ### Usage of meta copy and compare for complex aggregates object |
657 | * \snippet meta_cc_unit_tests.hpp Usage of meta copy and compare for complex aggregates object |
658 | * ### Usage of meta copy and compare for Point_test |
659 | * \snippet meta_cc_unit_tests.hpp Usage of meta copy and compare for Point_test |
660 | * |
661 | */ |
662 | template<template<typename,typename> class op, typename T> |
663 | struct meta_copy_op |
664 | { |
665 | /*! \brief Meta-copy applying an operation |
666 | * |
667 | * \param src source object |
668 | * \param dst destination object |
669 | * |
670 | */ |
671 | static inline void meta_copy_op_(const T & src, T & dst) |
672 | { |
673 | copy_general_op<op,T>(src,dst); |
674 | } |
675 | |
676 | /*! \brief Meta-copy applying an operation |
677 | * |
678 | * \param src source object |
679 | * \param dst destination object |
680 | * |
681 | */ |
682 | static inline void meta_copy_op_(const T & src, T && dst) |
683 | { |
684 | copy_general_op<op,T>(src,dst); |
685 | } |
686 | }; |
687 | |
688 | //! Partial specialization for N=1 1D-Array |
689 | template<template<typename,typename> class op, typename T, typename vmpl> |
690 | struct meta_copy_op<op,openfpm::detail::multi_array::sub_array_openfpm<T,1,vmpl>> |
691 | { |
692 | /*! \brief Meta-copy applying an operation |
693 | * |
694 | * \param src source object |
695 | * \param dst destination object |
696 | * |
697 | */ |
698 | static inline void meta_copy_op_(const openfpm::detail::multi_array::sub_array_openfpm<T,1,vmpl> src, openfpm::detail::multi_array::sub_array_openfpm<T,1,vmpl> dst) |
699 | { |
700 | for (size_t i1 = 0 ; i1 < boost::mpl::at<vmpl,boost::mpl::int_<0>>::type::value ; i1++) |
701 | { |
702 | copy_general_op<op,T>(src[i1],dst[i1]); |
703 | } |
704 | } |
705 | }; |
706 | |
707 | //! Partial specialization for N=1 1D-Array |
708 | template<template<typename,typename> class op, typename T,size_t N1> |
709 | struct meta_copy_op<op,T[N1]> |
710 | { |
711 | /*! \brief Meta-copy applying an operation |
712 | * |
713 | * \param src source object |
714 | * \param dst destination object |
715 | * |
716 | */ |
717 | static inline void meta_copy_op_(const T src[N1], T dst[N1]) |
718 | { |
719 | for (size_t i1 = 0 ; i1 < N1 ; i1++) |
720 | { |
721 | copy_general_op<op,T>(src[i1],dst[i1]); |
722 | } |
723 | } |
724 | }; |
725 | |
726 | //! Partial specialization for N=2 2D-Array |
727 | template<template<typename,typename> class op, typename T, typename vmpl> |
728 | struct meta_copy_op<op,openfpm::detail::multi_array::sub_array_openfpm<T,2,vmpl>> |
729 | { |
730 | /*! \brief Meta-copy applying an operation |
731 | * |
732 | * \param src source object |
733 | * \param dst destination object |
734 | * |
735 | */ |
736 | static inline void meta_copy_op_(const openfpm::detail::multi_array::sub_array_openfpm<T,2,vmpl> src, openfpm::detail::multi_array::sub_array_openfpm<T,2,vmpl> dst) |
737 | { |
738 | for (size_t i1 = 0 ; i1 < boost::mpl::at<vmpl,boost::mpl::int_<0>>::type::value ; i1++) |
739 | { |
740 | for (size_t i2 = 0 ; i2 < boost::mpl::at<vmpl,boost::mpl::int_<1>>::type::value ; i2++) |
741 | { |
742 | copy_general_op<op,T>(src[i1][i2],dst[i1][i2]); |
743 | } |
744 | } |
745 | } |
746 | }; |
747 | |
748 | //! Partial specialization for N=2 2D-Array |
749 | template<template<typename,typename> class op, typename T,size_t N1,size_t N2> |
750 | struct meta_copy_op<op,T[N1][N2]> |
751 | { |
752 | /*! \brief Meta-copy applying an operation |
753 | * |
754 | * \param src source object |
755 | * \param dst destination object |
756 | * |
757 | */ |
758 | static inline void meta_copy_op_(const T src[N1][N2], T dst[N1][N2]) |
759 | { |
760 | for (size_t i1 = 0 ; i1 < N1 ; i1++) |
761 | { |
762 | for (size_t i2 = 0 ; i2 < N2 ; i2++) |
763 | { |
764 | copy_general_op<op,T>(src[i1][i2],dst[i1][i2]); |
765 | } |
766 | } |
767 | } |
768 | }; |
769 | |
770 | |
771 | //! Partial specialization for N=3 |
772 | template<template<typename,typename> class op, typename T,size_t N1,size_t N2,size_t N3> |
773 | struct meta_copy_op<op,T[N1][N2][N3]> |
774 | { |
775 | /*! \brief Meta-copy applying an operation |
776 | * |
777 | * \param src source object |
778 | * \param dst destination object |
779 | * |
780 | */ |
781 | static inline void meta_copy_op_(const T src[N1][N2][N3], T dst[N1][N2][N3]) |
782 | { |
783 | for (size_t i1 = 0 ; i1 < N1 ; i1++) |
784 | { |
785 | for (size_t i2 = 0 ; i2 < N2 ; i2++) |
786 | { |
787 | for (size_t i3 = 0 ; i3 < N3 ; i3++) |
788 | { |
789 | copy_general_op<op,T>(src[i1][i2][i3],dst[i1][i2][i3]); |
790 | } |
791 | } |
792 | } |
793 | } |
794 | }; |
795 | |
796 | |
797 | template<template<typename,typename> class op, typename Tsrc, typename Tdst> |
798 | struct meta_copy_op_d |
799 | { |
800 | /*! \brief Meta-copy applying an operation |
801 | * |
802 | * \param src source object |
803 | * \param dst destination object |
804 | * |
805 | */ |
806 | __device__ __host__ static inline void meta_copy_op_d_(const Tsrc & src, Tdst & dst) |
807 | { |
808 | copy_general_op<op,Tsrc>(src,dst); |
809 | } |
810 | |
811 | /*! \brief Meta-copy applying an operation |
812 | * |
813 | * \param src source object |
814 | * \param dst destination object |
815 | * |
816 | */ |
817 | __device__ __host__ static inline void meta_copy_op_d_(const Tsrc & src, Tdst && dst) |
818 | { |
819 | copy_general_op<op,Tsrc>(src,dst); |
820 | } |
821 | }; |
822 | |
823 | //! Partial specialization for N=1 1D-Array |
824 | template<template<typename,typename> class op,typename Tsrc, typename Tdst, size_t N1> |
825 | struct meta_copy_op_d<op,Tsrc[N1],Tdst> |
826 | { |
827 | /*! \brief copy and object from src to dst |
828 | * |
829 | * \param src source object to copy |
830 | * \param dst destination object |
831 | * |
832 | */ |
833 | __device__ __host__ static inline void meta_copy_op_d_(const Tsrc src[N1], Tdst && dst) |
834 | { |
835 | for (size_t i1 = 0 ; i1 < N1 ; i1++) |
836 | { |
837 | copy_general_op<op,Tsrc>(src[i1],static_cast<Tsrc&>(dst[i1])); |
838 | } |
839 | } |
840 | }; |
841 | |
842 | //! Partial specialization for N=1 1D-Array |
843 | template<template<typename,typename> class op, typename Tsrc, typename Tdst, size_t N1> |
844 | struct meta_copy_op_d<op,Tsrc,Tdst[N1]> |
845 | { |
846 | /*! \brief copy and object from src to dst |
847 | * |
848 | * \param src source object to copy |
849 | * \param dst destination object |
850 | * |
851 | */ |
852 | __device__ __host__ static inline void meta_copy_op_d_(const Tsrc & src, Tdst dst[N1]) |
853 | { |
854 | for (size_t i1 = 0 ; i1 < N1 ; i1++) |
855 | { |
856 | copy_general_op<op,Tdst>(static_cast<const Tdst&>(src[i1]),dst[i1]); |
857 | } |
858 | } |
859 | }; |
860 | |
861 | //! Partial specialization for N=2 2D-Array |
862 | template<template<typename,typename> class op, typename Tsrc, typename Tdst, typename vmpl> |
863 | struct meta_copy_op_d<op,openfpm::detail::multi_array::sub_array_openfpm<Tsrc,1,vmpl>,openfpm::detail::multi_array::sub_array_openfpm<Tdst,1,vmpl>> |
864 | { |
865 | /*! \brief copy and object from src to dst |
866 | * |
867 | * \param src source object to copy |
868 | * \param dst destination object |
869 | * |
870 | */ |
871 | __device__ __host__ static inline void meta_copy_op_d_(const openfpm::detail::multi_array::sub_array_openfpm<Tsrc,1,vmpl> src, openfpm::detail::multi_array::sub_array_openfpm<Tdst,1,vmpl> dst) |
872 | { |
873 | for (size_t i1 = 0 ; i1 < boost::mpl::at<vmpl,boost::mpl::int_<0>>::type::value ; i1++) |
874 | { |
875 | copy_general_op<op,Tdst>(src[i1],dst[i1]); |
876 | } |
877 | } |
878 | }; |
879 | |
880 | //! Partial specialization for N=1 1D-Array |
881 | template<template<typename,typename> class op, typename Tsrc, typename Tdst, size_t N1> |
882 | struct meta_copy_op_d<op,Tsrc[N1],Tdst[N1]> |
883 | { |
884 | /*! \brief copy and object from src to dst |
885 | * |
886 | * \param src source object to copy |
887 | * \param dst destination object |
888 | * |
889 | */ |
890 | __device__ __host__ static inline void meta_copy_op_d_(const Tsrc src[N1], Tdst dst[N1]) |
891 | { |
892 | for (size_t i1 = 0 ; i1 < N1 ; i1++) |
893 | { |
894 | copy_general_op<op,Tdst>(src[i1],dst[i1]); |
895 | } |
896 | } |
897 | }; |
898 | |
899 | //! Partial specialization for N=2 2D-Array |
900 | template<template<typename,typename> class op, typename Tsrc, typename Tdst, size_t N1, size_t N2> |
901 | struct meta_copy_op_d<op,Tsrc[N1][N2],Tdst[N1][N2]> |
902 | { |
903 | /*! \brief copy and object from src to dst |
904 | * |
905 | * \param src source object to copy |
906 | * \param dst destination object |
907 | * |
908 | */ |
909 | __device__ __host__ static inline void meta_copy_op_d_(const Tsrc src[N1][N2], Tdst dst[N1][N2]) |
910 | { |
911 | for (size_t i1 = 0 ; i1 < N1 ; i1++) |
912 | { |
913 | for (size_t i2 = 0 ; i2 < N2 ; i2++) |
914 | { |
915 | copy_general_op<op,Tdst>(src[i1][i2],dst[i1][i2]); |
916 | } |
917 | } |
918 | } |
919 | }; |
920 | |
921 | //! Partial specialization for N=2 2D-Array |
922 | template<template<typename,typename> class op, typename Tsrc, typename Tdst, typename vmpl> |
923 | struct meta_copy_op_d<op,openfpm::detail::multi_array::sub_array_openfpm<Tsrc,2,vmpl>,openfpm::detail::multi_array::sub_array_openfpm<Tdst,2,vmpl>> |
924 | { |
925 | /*! \brief copy and object from src to dst |
926 | * |
927 | * \param src source object to copy |
928 | * \param dst destination object |
929 | * |
930 | */ |
931 | __device__ __host__ static inline void meta_copy_op_d_(const openfpm::detail::multi_array::sub_array_openfpm<Tsrc,2,vmpl> src, openfpm::detail::multi_array::sub_array_openfpm<Tdst,2,vmpl> dst) |
932 | { |
933 | for (size_t i1 = 0 ; i1 < boost::mpl::at<vmpl,boost::mpl::int_<0>>::type::value ; i1++) |
934 | { |
935 | for (size_t i2 = 0 ; i2 < boost::mpl::at<vmpl,boost::mpl::int_<1>>::type::value ; i2++) |
936 | { |
937 | copy_general_op<op,Tdst>(src[i1][i2],dst[i1][i2]); |
938 | } |
939 | } |
940 | } |
941 | }; |
942 | |
943 | #endif |
944 | |