This source file includes following definitions.
- unpack_predefined_data
- unpack_contiguous_loop
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 #ifndef OPAL_DATATYPE_UNPACK_H_HAS_BEEN_INCLUDED
18 #define OPAL_DATATYPE_UNPACK_H_HAS_BEEN_INCLUDED
19
20 #include "opal_config.h"
21
22 #if !defined(CHECKSUM) && OPAL_CUDA_SUPPORT
23
24 #undef MEMCPY_CSUM
25 #define MEMCPY_CSUM( DST, SRC, BLENGTH, CONVERTOR ) \
26 CONVERTOR->cbmemcpy( (DST), (SRC), (BLENGTH), (CONVERTOR) )
27 #endif
28
29 static inline void
30 unpack_predefined_data( opal_convertor_t* CONVERTOR,
31 const dt_elem_desc_t* ELEM,
32 size_t* COUNT,
33 unsigned char** SOURCE,
34 unsigned char** DESTINATION,
35 size_t* SPACE )
36 {
37 size_t _copy_count = *(COUNT);
38 size_t _copy_blength;
39 const ddt_elem_desc_t* _elem = &((ELEM)->elem);
40 unsigned char* _destination = (*DESTINATION) + _elem->disp;
41
42 _copy_blength = opal_datatype_basicDatatypes[_elem->common.type]->size;
43 if( (_copy_count * _copy_blength) > *(SPACE) ) {
44 _copy_count = (*(SPACE) / _copy_blength);
45 if( 0 == _copy_count ) return;
46 }
47
48 if( (ptrdiff_t)_copy_blength == _elem->extent ) {
49 _copy_blength *= _copy_count;
50
51 OPAL_DATATYPE_SAFEGUARD_POINTER( _destination, _copy_blength, (CONVERTOR)->pBaseBuf,
52 (CONVERTOR)->pDesc, (CONVERTOR)->count );
53 DO_DEBUG( opal_output( 0, "unpack 1. memcpy( %p, %p, %lu ) => space %lu\n",
54 (void*)_destination, (void*)*(SOURCE), (unsigned long)_copy_blength, (unsigned long)(*(SPACE)) ); );
55 MEMCPY_CSUM( _destination, *(SOURCE), _copy_blength, (CONVERTOR) );
56 *(SOURCE) += _copy_blength;
57 _destination += _copy_blength;
58 } else {
59 for(size_t _i = 0; _i < _copy_count; _i++ ) {
60 OPAL_DATATYPE_SAFEGUARD_POINTER( _destination, _copy_blength, (CONVERTOR)->pBaseBuf,
61 (CONVERTOR)->pDesc, (CONVERTOR)->count );
62 DO_DEBUG( opal_output( 0, "unpack 2. memcpy( %p, %p, %lu ) => space %lu\n",
63 (void*)_destination, (void*)*(SOURCE), (unsigned long)_copy_blength, (unsigned long)(*(SPACE) - (_i * _copy_blength)) ); );
64 MEMCPY_CSUM( _destination, *(SOURCE), _copy_blength, (CONVERTOR) );
65 *(SOURCE) += _copy_blength;
66 _destination += _elem->extent;
67 }
68 _copy_blength *= _copy_count;
69 }
70 (*DESTINATION) = _destination - _elem->disp;
71 *(SPACE) -= _copy_blength;
72 *(COUNT) -= _copy_count;
73 }
74
75 static inline void unpack_contiguous_loop( opal_convertor_t* CONVERTOR,
76 const dt_elem_desc_t* ELEM,
77 size_t* COUNT,
78 unsigned char** SOURCE,
79 unsigned char** DESTINATION,
80 size_t* SPACE )
81 {
82 const ddt_loop_desc_t *_loop = (ddt_loop_desc_t*)(ELEM);
83 const ddt_endloop_desc_t* _end_loop = (ddt_endloop_desc_t*)((ELEM) + _loop->items);
84 unsigned char* _destination = (*DESTINATION) + _end_loop->first_elem_disp;
85 size_t _copy_loops = *(COUNT);
86
87 if( (_copy_loops * _end_loop->size) > *(SPACE) )
88 _copy_loops = (*(SPACE) / _end_loop->size);
89 for(size_t _i = 0; _i < _copy_loops; _i++ ) {
90 OPAL_DATATYPE_SAFEGUARD_POINTER( _destination, _end_loop->size, (CONVERTOR)->pBaseBuf,
91 (CONVERTOR)->pDesc, (CONVERTOR)->count );
92 DO_DEBUG( opal_output( 0, "unpack 3. memcpy( %p, %p, %lu ) => space %lu\n",
93 (void*)_destination, (void*)*(SOURCE), (unsigned long)_end_loop->size, (unsigned long)(*(SPACE) - _i * _end_loop->size) ); );
94 MEMCPY_CSUM( _destination, *(SOURCE), _end_loop->size, (CONVERTOR) );
95 *(SOURCE) += _end_loop->size;
96 _destination += _loop->extent;
97 }
98 *(DESTINATION) = _destination - _end_loop->first_elem_disp;
99 *(SPACE) -= _copy_loops * _end_loop->size;
100 *(COUNT) -= _copy_loops;
101 }
102
103 #define UNPACK_PREDEFINED_DATATYPE( CONVERTOR, ELEM, COUNT, SOURCE, DESTINATION, SPACE ) \
104 unpack_predefined_data( (CONVERTOR), (ELEM), &(COUNT), &(SOURCE), &(DESTINATION), &(SPACE) )
105
106 #define UNPACK_CONTIGUOUS_LOOP( CONVERTOR, ELEM, COUNT, SOURCE, DESTINATION, SPACE ) \
107 unpack_contiguous_loop( (CONVERTOR), (ELEM), &(COUNT), &(SOURCE), &(DESTINATION), &(SPACE) )
108
109 #endif