1
1

macros to compute checksum while moving data

This commit was SVN r9278.
Этот коммит содержится в:
Tim Woodall 2006-03-14 19:33:27 +00:00
родитель 92c5e26758
Коммит 0b366e912c
7 изменённых файлов: 64 добавлений и 54 удалений

Просмотреть файл

@ -86,6 +86,9 @@ inline int32_t ompi_convertor_pack( ompi_convertor_t* pConv,
size_t* max_data, int32_t* freeAfter )
{
pConv->checksum = 1;
pConv->csum_ui1 = 0;
pConv->csum_ui2 = 0;
/* protect against over packing data */
if( pConv->flags & CONVERTOR_COMPLETED ) {
iov[0].iov_len = 0;
@ -107,6 +110,9 @@ inline int32_t ompi_convertor_unpack( ompi_convertor_t* pConv,
size_t* max_data, int32_t* freeAfter )
{
pConv->checksum = 1;
pConv->csum_ui1 = 0;
pConv->csum_ui2 = 0;
/* protect against over unpacking data */
if( pConv->flags & CONVERTOR_COMPLETED ) {
iov[0].iov_len = 0;

Просмотреть файл

@ -94,6 +94,8 @@ struct ompi_convertor_t {
uint32_t stack_pos; /**< the actual position on the stack */
size_t bConverted; /**< # of bytes already converted */
uint32_t checksum; /**< checksum computed by pack/unpack operation */
uint32_t csum_ui1; /**< partial checksum computed by pack/unpack operation */
uint32_t csum_ui2; /**< partial checksum computed by pack/unpack operation */
char pending[16]; /**< bytes pending from the last conversion */
uint32_t pending_length; /**< # bytes pending ... */
dt_stack_t static_stack[DT_STATIC_STACK_SIZE]; /**< local stack for small datatypes */

Просмотреть файл

@ -251,6 +251,7 @@ do { \
memcpy( (DST), (SRC), (BLENGTH) ); \
} while (0)
#if OMPI_ENABLE_DEBUG
OMPI_DECLSPEC int ompi_ddt_safeguard_pointer_debug_breakpoint( const void* actual_ptr, int length,
const void* initial_ptr,
@ -291,7 +292,33 @@ static inline int GET_FIRST_NON_LOOP( const dt_elem_desc_t* _pElem )
/* Please set it to one if you want data checksum. The current implementation
* use ADLER32 algorithm.
*/
#define OMPI_REQUIRE_DATA_VALIDATION 0
#include "opal/util/crc.h"
#define MEMCPY_CSUM( DST, SRC, BLENGTH, CONVERTOR ) \
do { \
/*opal_output( 0, "memcpy dest = %p src = %p length = %d\n", (void*)(DST), (void*)(SRC), (int)(BLENGTH) ); */\
(CONVERTOR)->checksum += opal_bcopy_uicsum_partial( (SRC), (DST), (BLENGTH), (BLENGTH), &(CONVERTOR)->csum_ui1, &(CONVERTOR)->csum_ui2 ); \
} while (0)
#define COMPUTE_CSUM( SRC, BLENGTH, CONVERTOR ) \
do { \
/*opal_output( 0, "memcpy dest = %p src = %p length = %d\n", (void*)(DST), (void*)(SRC), (int)(BLENGTH) ); */\
(CONVERTOR)->checksum += opal_uicsum_partial( (SRC), (BLENGTH), &(CONVERTOR)->csum_ui1, &(CONVERTOR)->csum_ui2 ); \
} while (0)
#else
#define MEMCPY_CSUM( DST, SRC, BLENGTH, CONVERTOR ) \
do { \
/*opal_output( 0, "memcpy dest = %p src = %p length = %d\n", (void*)(DST), (void*)(SRC), (int)(BLENGTH) ); */\
memcpy( (DST), (SRC), (BLENGTH) ); \
} while (0)
#define COMPUTE_CSUM( SRC, BLENGTH, CONVERTOR )
#endif
/* ADLER_NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
#define ADLER_NMAX 5551

Просмотреть файл

@ -234,7 +234,7 @@ int ompi_convertor_pack_homogeneous_with_memcpy( ompi_convertor_t* pConv,
for( i = 0; i < last_count; i++ ) {
OMPI_DDT_SAFEGUARD_POINTER( pConv->pBaseBuf + lastDisp, end_loop->size,
pConv->pBaseBuf, pData, pConv->count );
MEMCPY( pDestBuf, pConv->pBaseBuf + lastDisp, end_loop->size );
MEMCPY_CSUM( pDestBuf, pConv->pBaseBuf + lastDisp, end_loop->size, pConv );
pDestBuf += end_loop->size; /* size of the contiguous data */
lastDisp += pElems[pos_desc].loop.extent;
}
@ -268,7 +268,7 @@ int ompi_convertor_pack_homogeneous_with_memcpy( ompi_convertor_t* pConv,
}
OMPI_DDT_SAFEGUARD_POINTER( pConv->pBaseBuf + lastDisp, last_count,
pConv->pBaseBuf, pData, pConv->count );
MEMCPY( pDestBuf, pConv->pBaseBuf + lastDisp, last_count );
MEMCPY_CSUM( pDestBuf, pConv->pBaseBuf + lastDisp, last_count, pConv );
bConverted += last_blength;
space -= last_blength;
pDestBuf += last_blength;
@ -281,7 +281,7 @@ int ompi_convertor_pack_homogeneous_with_memcpy( ompi_convertor_t* pConv,
if( last_count != 0 ) { /* save the internal state */
OMPI_DDT_SAFEGUARD_POINTER( pConv->pBaseBuf + lastDisp, last_count,
pConv->pBaseBuf, pData, pConv->count );
MEMCPY( pDestBuf, pConv->pBaseBuf + lastDisp, last_count );
MEMCPY_CSUM( pDestBuf, pConv->pBaseBuf + lastDisp, last_count, pConv );
bConverted += last_count;
lastDisp += last_count;
}
@ -363,6 +363,7 @@ int ompi_convertor_pack_no_conversion( ompi_convertor_t* pConv,
saveLength = 0;
iov_pos++;
space_on_iovec = 0;
COMPUTE_CSUM( iov[iov_pos].iov_base, iov[iov_pos].iov_len, pConv );
/* let's go out of here */
} else {
uint32_t copy_length = saveLength;
@ -373,7 +374,7 @@ int ompi_convertor_pack_no_conversion( ompi_convertor_t* pConv,
pConv->pBaseBuf, pData, pConv->count );
DO_DEBUG( opal_output( 0, "1. memcpy( %p, %p, %ld ) bConverted %ld space %ld pConv->bConverted %ld\n", destination, source,
copy_length, bConverted, space_on_iovec, pConv->bConverted ); );
MEMCPY( destination, source, copy_length );
MEMCPY_CSUM( destination, source, copy_length, pConv );
source += copy_length;
destination += copy_length;
bConverted += copy_length;
@ -433,7 +434,7 @@ int ompi_convertor_pack_no_conversion( ompi_convertor_t* pConv,
pConv->pBaseBuf, pData, pConv->count );
DO_DEBUG (opal_output( 0, "2. memcpy( %p, %p, %ld )\n", destination, pConv->pBaseBuf + lastDisp,
end_loop->size ); );
MEMCPY( destination, pConv->pBaseBuf + lastDisp, end_loop->size );
MEMCPY_CSUM( destination, pConv->pBaseBuf + lastDisp, end_loop->size, pConv );
lastDisp += pElems[pos_desc].loop.extent;
destination += end_loop->size;
}
@ -516,7 +517,7 @@ int ompi_convertor_pack_no_conversion( ompi_convertor_t* pConv,
pConv->pBaseBuf, pData, pConv->count );
DO_DEBUG( opal_output( 0, "3. memcpy( %p, %p, %ld ) bConverted %ld space %ld pConv->bConverted %ld\n", destination, source,
saveLength, bConverted, space_on_iovec, pConv->bConverted ); );
MEMCPY( destination, source, saveLength );
MEMCPY_CSUM( destination, source, saveLength, pConv );
destination += saveLength;
/* update the pack counters values */
bConverted += saveLength;
@ -531,7 +532,7 @@ int ompi_convertor_pack_no_conversion( ompi_convertor_t* pConv,
pConv->pBaseBuf, pData, pConv->count );
DO_DEBUG( opal_output( 0, "4. memcpy( %p, %p, %ld ) bConverted %ld space %ld pConv->bConverted %ld\n", destination, source,
space_on_iovec, bConverted, space_on_iovec, pConv->bConverted ); );
MEMCPY( destination, source, space_on_iovec );
MEMCPY_CSUM( destination, source, space_on_iovec, pConv );
/* let's prepare for the next round. As I keep trace of the amount that I still
* have to pack, the next time when I came here, I'll try to append something.
* If I already fill-up the amount of data required by the upper level, I will
@ -609,21 +610,16 @@ ompi_convertor_pack_no_conv_contig( ompi_convertor_t* pConv,
+ pStack[0].disp + pStack[1].disp);
if( iov[iov_count].iov_base == NULL ) {
iov[iov_count].iov_base = source_base;
COMPUTE_CSUM( iov[iov_count].iov_base, iov[iov_count].iov_len, pConv );
} else {
/* contiguous data just memcpy the smallest data in the user buffer */
OMPI_DDT_SAFEGUARD_POINTER( source_base, iov[iov_count].iov_len,
pConv->pBaseBuf, pConv->pDesc, pConv->count );
MEMCPY( iov[iov_count].iov_base, source_base, iov[iov_count].iov_len);
MEMCPY_CSUM( iov[iov_count].iov_base, source_base, iov[iov_count].iov_len, pConv );
}
length -= iov[iov_count].iov_len;
pConv->bConverted += iov[iov_count].iov_len;
pStack[0].disp += iov[iov_count].iov_len;
/* We compute the checksum if we have to. But we will store the temporary
* values in the a and b variables, and only at the end take in account the
* value of the convertor checksum.
*/
COMPUTE_SPECIFIC_CHECKSUM( iov[iov_count].iov_base, iov[iov_count].iov_len,
pConv->checksum );
}
/* update the return value */
@ -679,6 +675,7 @@ ompi_convertor_pack_no_conv_contig_with_gaps( ompi_convertor_t* pConv,
total_bytes_converted += pStack[1].count;
pStack[1].disp = 0; /* reset it for the next round */
pStack[1].count = pData->size;
COMPUTE_CSUM( iov[index].iov_base, iov[index].iov_len, pConv );
}
*out_size = iov_count + index;
pConv->bConverted += total_bytes_converted;
@ -697,11 +694,13 @@ ompi_convertor_pack_no_conv_contig_with_gaps( ompi_convertor_t* pConv,
iov[index].iov_len = max_allowed;
max_allowed = 0;
printf( "%s:%d Possible problem here\n", __FILE__, __LINE__ );
COMPUTE_CSUM( iov[index].iov_base, iov[index].iov_len, pConv );
break;
} else {
iov[index].iov_base = user_memory;
iov[index].iov_len = pData->size;
user_memory += extent;
COMPUTE_CSUM( iov[index].iov_base, iov[index].iov_len, pConv );
}
max_allowed -= iov[index].iov_len;
total_bytes_converted += iov[index].iov_len;
@ -733,7 +732,7 @@ ompi_convertor_pack_no_conv_contig_with_gaps( ompi_convertor_t* pConv,
if( done != 0 ) { /* still some data to copy from the last time */
done = pData->size - done;
OMPI_DDT_SAFEGUARD_POINTER( user_memory, done, pConv->pBaseBuf, pData, pConv->count );
MEMCPY( packed_buffer, user_memory, done );
MEMCPY_CSUM( packed_buffer, user_memory, done, pConv );
packed_buffer += done;
max_allowed -= done;
i++; /* just to compute the correct source pointer */
@ -744,7 +743,7 @@ ompi_convertor_pack_no_conv_contig_with_gaps( ompi_convertor_t* pConv,
if( counter > pConv->count ) counter = pConv->count;
for( i = 0; i < counter; i++ ) {
OMPI_DDT_SAFEGUARD_POINTER( user_memory, pData->size, pConv->pBaseBuf, pData, pConv->count );
MEMCPY( packed_buffer, user_memory, pData->size );
MEMCPY_CSUM( packed_buffer, user_memory, pData->size, pConv );
packed_buffer+= pData->size;
user_memory += extent;
}
@ -757,12 +756,6 @@ ompi_convertor_pack_no_conv_contig_with_gaps( ompi_convertor_t* pConv,
* it's supposed to be useless from now.
*/
user_memory = pConv->pBaseBuf + pStack[0].disp;
/* We compute the checksum if we have to. But we will store the temporary
* values in the a and b variables, and only at the end take in account the
* value of the convertor checksum.
*/
COMPUTE_SPECIFIC_CHECKSUM( iov[iov_count].iov_base, iov[iov_count].iov_len,
pConv->checksum );
}
*max_data = total_bytes_converted;
pConv->bConverted += total_bytes_converted;

Просмотреть файл

@ -236,7 +236,7 @@ static int ompi_convertor_unpack_homogeneous( ompi_convertor_t* pConv,
OMPI_DDT_SAFEGUARD_POINTER( pConv->pBaseBuf + lastDisp, end_loop->size,
pConv->pBaseBuf, pData, pConv->count );
/*opal_output( 0, "3. memcpy %p, %p, %d", pConv->pBaseBuf + lastDisp, pSrcBuf, end_loop->size );*/
MEMCPY( pConv->pBaseBuf + lastDisp, pSrcBuf, end_loop->size );
MEMCPY_CSUM( pConv->pBaseBuf + lastDisp, pSrcBuf, end_loop->size, pConv );
pSrcBuf += end_loop->size;
lastDisp += pElems[pos_desc].loop.extent;
}
@ -273,7 +273,7 @@ static int ompi_convertor_unpack_homogeneous( ompi_convertor_t* pConv,
OMPI_DDT_SAFEGUARD_POINTER( pConv->pBaseBuf + lastDisp, last_blength,
pConv->pBaseBuf, pData, pConv->count );
/*opal_output( 0, "1. memcpy %p, %p, %d -> %d", pConv->pBaseBuf + lastDisp, pSrcBuf, last_blength, bConverted );*/
MEMCPY( pConv->pBaseBuf + lastDisp, pSrcBuf, last_blength );
MEMCPY_CSUM( pConv->pBaseBuf + lastDisp, pSrcBuf, last_blength, pConv );
bConverted += last_blength;
space -= last_blength;
pSrcBuf += last_blength;
@ -285,7 +285,7 @@ static int ompi_convertor_unpack_homogeneous( ompi_convertor_t* pConv,
OMPI_DDT_SAFEGUARD_POINTER( pConv->pBaseBuf + lastDisp, last_blength,
pConv->pBaseBuf, pData, pConv->count );
/*opal_output( 0, "2. memcpy %p, %p, %d", pConv->pBaseBuf + lastDisp, pSrcBuf, last_blength );*/
MEMCPY( pConv->pBaseBuf + lastDisp, pSrcBuf, last_blength );
MEMCPY_CSUM( pConv->pBaseBuf + lastDisp, pSrcBuf, last_blength, pConv );
lastDisp += pElems[pos_desc].elem.extent;
pSrcBuf += basic_type->size;
}
@ -301,7 +301,7 @@ static int ompi_convertor_unpack_homogeneous( ompi_convertor_t* pConv,
/* update corresponding the the datatype length */
OMPI_DDT_SAFEGUARD_POINTER( pConv->pBaseBuf + lastDisp, last_blength,
pConv->pBaseBuf, pData, pConv->count );
MEMCPY( pConv->pBaseBuf + lastDisp, pSrcBuf, last_blength );
MEMCPY_CSUM( pConv->pBaseBuf + lastDisp, pSrcBuf, last_blength, pConv );
/*opal_output( 0, "1. memcpy %p, %p, %d -> %d", pConv->pBaseBuf + lastDisp, pSrcBuf, last_blength, bConverted );*/
bConverted += last_blength;
lastDisp += last_blength;
@ -351,7 +351,7 @@ static int ompi_convertor_unpack_homogeneous_contig( ompi_convertor_t* pConv,
pConv->pBaseBuf, pData, pConv->count );
/*opal_output( 0, "1. unpack contig dest %p src %p length %d\n",
user_memory, packed_buffer, remaining );*/
MEMCPY( user_memory, packed_buffer, remaining);
MEMCPY_CSUM( user_memory, packed_buffer, remaining, pConv );
} else {
user_memory += stack->disp;
@ -363,7 +363,7 @@ static int ompi_convertor_unpack_homogeneous_contig( ompi_convertor_t* pConv,
pData, pConv->count );
/*opal_output( 0, "1. unpack dest %p src %p length %d\n",
user_memory, packed_buffer, length );*/
MEMCPY( user_memory, packed_buffer, length );
MEMCPY_CSUM( user_memory, packed_buffer, length, pConv );
packed_buffer += length;
user_memory += (extent - (pData->size - length));
remaining -= length;
@ -373,7 +373,7 @@ static int ompi_convertor_unpack_homogeneous_contig( ompi_convertor_t* pConv,
pData, pConv->count );
/*opal_output( 0, "2. unpack dest %p src %p length %d\n",
user_memory, packed_buffer, pData->size );*/
MEMCPY( user_memory, packed_buffer, pData->size );
MEMCPY_CSUM( user_memory, packed_buffer, pData->size, pConv );
packed_buffer += pData->size;
user_memory += extent;
remaining -= pData->size;
@ -384,18 +384,12 @@ static int ompi_convertor_unpack_homogeneous_contig( ompi_convertor_t* pConv,
pData, pConv->count );
/*opal_output( 0, "3. unpack dest %p src %p length %d\n",
user_memory, packed_buffer, remaining );*/
MEMCPY( user_memory, packed_buffer, remaining );
MEMCPY_CSUM( user_memory, packed_buffer, remaining, pConv );
user_memory += remaining;
}
stack->disp = user_memory - pData->true_lb - pConv->pBaseBuf; /* save the position */
}
pConv->bConverted += bConverted;
/* We compute the checksum if we have to. But we will store the temporary
* values in the a and b variables, and only at the end take in account the
* value of the convertor checksum.
*/
COMPUTE_SPECIFIC_CHECKSUM( iov[iov_count].iov_base, iov[iov_count].iov_len,
pConv->checksum );
}
*out_size = iov_count;
*max_data = (pConv->bConverted - initial_bytes_converted);

Просмотреть файл

@ -78,7 +78,7 @@ static inline void pack_predefined_data( ompi_convertor_t* CONVERTOR,
(CONVERTOR)->pDesc, (CONVERTOR)->count );
DO_DEBUG( opal_output( 0, "pack 1. memcpy( %p, %p, %ld ) => space %d\n",
*(DESTINATION), _source, _copy_blength, *(SPACE) ); );
MEMCPY( *(DESTINATION), _source, _copy_blength );
MEMCPY_CSUM( *(DESTINATION), _source, _copy_blength, (CONVERTOR) );
_source += _copy_blength;
*(DESTINATION) += _copy_blength;
} else {
@ -88,7 +88,7 @@ static inline void pack_predefined_data( ompi_convertor_t* CONVERTOR,
(CONVERTOR)->pDesc, (CONVERTOR)->count );
DO_DEBUG( opal_output( 0, "pack 2. memcpy( %p, %p, %ld ) => space %d\n",
*(DESTINATION), _source, _copy_blength, *(SPACE) - (_i * _copy_blength) ); );
MEMCPY( *(DESTINATION), _source, _copy_blength );
MEMCPY_CSUM( *(DESTINATION), _source, _copy_blength, (CONVERTOR) );
*(DESTINATION) += _copy_blength;
_source += _elem->extent;
}
@ -119,7 +119,7 @@ static inline void pack_contiguous_loop( ompi_convertor_t* CONVERTOR,
(CONVERTOR)->pDesc, (CONVERTOR)->count );
DO_DEBUG( opal_output( 0, "pack 3. memcpy( %p, %p, %ld ) => space %ld\n",
*(DESTINATION), _source, _end_loop->size, *(SPACE) - _i * _end_loop->size ); );
MEMCPY( *(DESTINATION), _source, _end_loop->size );
MEMCPY_CSUM( *(DESTINATION), _source, _end_loop->size, (CONVERTOR) );
*(DESTINATION) += _end_loop->size;
_source += _loop->extent;
}
@ -265,12 +265,6 @@ int ompi_convertor_generic_simple_pack( ompi_convertor_t* pConvertor,
iov[iov_count].iov_len -= iov_len_local; /* update the amount of valid data */
total_packed += iov[iov_count].iov_len;
pConvertor->bConverted += iov[iov_count].iov_len; /* update the already converted bytes */
/* We compute the checksum if we have to. But we will store the temporary
* values in the a and b variables, and only at the end take in account the
* value of the convertor checksum.
*/
COMPUTE_SPECIFIC_CHECKSUM( iov[iov_count].iov_base, iov[iov_count].iov_len,
pConvertor->checksum );
}
*max_data = total_packed;
*out_size = iov_count;

Просмотреть файл

@ -70,7 +70,7 @@ static inline void unpack_predefined_data( ompi_convertor_t* CONVERTOR, /* the c
(CONVERTOR)->pDesc, (CONVERTOR)->count );
DO_DEBUG( opal_output( 0, "unpack 1. memcpy( %p, %p, %ld ) => space %d\n",
_destination, *(SOURCE), _copy_blength, *(SPACE) ); );
MEMCPY( _destination, *(SOURCE), _copy_blength );
MEMCPY_CSUM( _destination, *(SOURCE), _copy_blength, (CONVERTOR) );
*(SOURCE) += _copy_blength;
_destination += _copy_blength;
} else {
@ -80,7 +80,7 @@ static inline void unpack_predefined_data( ompi_convertor_t* CONVERTOR, /* the c
(CONVERTOR)->pDesc, (CONVERTOR)->count );
DO_DEBUG( opal_output( 0, "unpack 2. memcpy( %p, %p, %ld ) => space %d\n",
_destination, *(SOURCE), _copy_blength, *(SPACE) - (_i * _copy_blength) ); );
MEMCPY( _destination, *(SOURCE), _copy_blength );
MEMCPY_CSUM( _destination, *(SOURCE), _copy_blength, (CONVERTOR) );
*(SOURCE) += _copy_blength;
_destination += _elem->extent;
}
@ -111,7 +111,7 @@ static inline void unpack_contiguous_loop( ompi_convertor_t* CONVERTOR,
(CONVERTOR)->pDesc, (CONVERTOR)->count );
DO_DEBUG( opal_output( 0, "unpack 3. memcpy( %p, %p, %ld ) => space %ld\n",
_destination, *(SOURCE), _end_loop->size, *(SPACE) - _i * _end_loop->size ); );
MEMCPY( _destination, *(SOURCE), _end_loop->size );
MEMCPY_CSUM( _destination, *(SOURCE), _end_loop->size, (CONVERTOR) );
*(SOURCE) += _end_loop->size;
_destination += _loop->extent;
}
@ -280,12 +280,6 @@ int ompi_convertor_generic_simple_unpack( ompi_convertor_t* pConvertor,
iov[iov_count].iov_len -= iov_len_local; /* update the amount of valid data */
total_unpacked += iov[iov_count].iov_len;
pConvertor->bConverted += iov[iov_count].iov_len; /* update the already converted bytes */
/* We compute the checksum if we have to. But we will store the temporary
* values in the a and b variables, and only at the end take in account the
* value of the convertor checksum.
*/
COMPUTE_SPECIFIC_CHECKSUM( iov[iov_count].iov_base, iov[iov_count].iov_len,
pConvertor->checksum );
}
*max_data = total_unpacked;
*out_size = iov_count;