Skip to content

Topic/datatype (#3441) #3504

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions ompi/datatype/ompi_datatype_get_elements.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Copyright (c) 2004-2007 The Trustees of Indiana University and Indiana
* University Research and Technology
* Corporation. All rights reserved.
* Copyright (c) 2004-2013 The University of Tennessee and The University
* Copyright (c) 2004-2017 The University of Tennessee and The University
* of Tennessee Research Foundation. All rights
* reserved.
* Copyright (c) 2004-2008 High Performance Computing Center Stuttgart,
Expand All @@ -25,6 +25,7 @@

#include "ompi/runtime/params.h"
#include "ompi/datatype/ompi_datatype.h"
#include "opal/datatype/opal_datatype_internal.h"

int ompi_datatype_get_elements (ompi_datatype_t *datatype, size_t ucount, size_t *count)
{
Expand All @@ -48,9 +49,10 @@ int ompi_datatype_get_elements (ompi_datatype_t *datatype, size_t ucount, size_t
there are no leftover bytes */
if (!ompi_datatype_is_predefined(datatype)) {
if (0 != internal_count) {
opal_datatype_compute_ptypes(&datatype->super);
/* count the basic elements in the datatype */
for (i = 4, total = 0 ; i < OPAL_DATATYPE_MAX_PREDEFINED ; ++i) {
total += datatype->super.btypes[i];
for (i = OPAL_DATATYPE_FIRST_TYPE, total = 0 ; i < OPAL_DATATYPE_MAX_PREDEFINED ; ++i) {
total += datatype->super.ptypes[i];
}
internal_count = total * internal_count;
}
Expand Down
4 changes: 2 additions & 2 deletions ompi/datatype/ompi_datatype_internal.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
/*
* Copyright (c) 2009-2013 The University of Tennessee and The University
* Copyright (c) 2009-2017 The University of Tennessee and The University
* of Tennessee Research Foundation. All rights
* reserved.
* Copyright (c) 2009 Oak Ridge National Labs. All rights reserved.
Expand Down Expand Up @@ -465,7 +465,7 @@ extern const ompi_datatype_t* ompi_datatype_basicDatatypes[OMPI_DATATYPE_MPI_MAX
.name = OPAL_DATATYPE_INIT_NAME(TYPE ## SIZE), \
.desc = OPAL_DATATYPE_INIT_DESC_PREDEFINED(TYPE ## SIZE), \
.opt_desc = OPAL_DATATYPE_INIT_DESC_PREDEFINED(TYPE ## SIZE), \
.btypes = OPAL_DATATYPE_INIT_BTYPES_ARRAY(TYPE ## SIZE) \
.ptypes = OPAL_DATATYPE_INIT_PTYPES_ARRAY(TYPE ## SIZE) \
}

#define OMPI_DATATYPE_INIT_PREDEFINED_BASIC_TYPE_FORTRAN( TYPE, NAME, SIZE, ALIGN, FLAGS ) \
Expand Down
7 changes: 4 additions & 3 deletions ompi/datatype/ompi_datatype_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -384,8 +384,9 @@ opal_pointer_array_t ompi_datatype_f_to_c_table = {{0}};
(PDST)->super.opt_desc = (PSRC)->super.opt_desc; \
(PDST)->packed_description = (PSRC)->packed_description; \
(PSRC)->packed_description = NULL; \
memcpy( (PDST)->super.btypes, (PSRC)->super.btypes, \
OPAL_DATATYPE_MAX_PREDEFINED * sizeof(uint32_t) ); \
/* transfer the ptypes */ \
(PDST)->super.ptypes = (PSRC)->super.ptypes; \
(PSRC)->super.ptypes = NULL; \
} while(0)

#define DECLARE_MPI2_COMPOSED_STRUCT_DDT( PDATA, MPIDDT, MPIDDTNAME, type1, type2, MPIType1, MPIType2, FLAGS) \
Expand Down Expand Up @@ -737,7 +738,7 @@ void ompi_datatype_dump( const ompi_datatype_t* pData )
(long)pData->super.size, (int)pData->super.align, pData->super.id, (int)pData->super.desc.length, (int)pData->super.desc.used,
(long)pData->super.true_lb, (long)pData->super.true_ub, (long)(pData->super.true_ub - pData->super.true_lb),
(long)pData->super.lb, (long)pData->super.ub, (long)(pData->super.ub - pData->super.lb),
(int)pData->super.nbElems, (int)pData->super.btypes[OPAL_DATATYPE_LOOP], (int)pData->super.flags );
(int)pData->super.nbElems, (int)pData->super.loops, (int)pData->super.flags );
/* dump the flags */
if( ompi_datatype_is_predefined(pData) ) {
index += snprintf( buffer + index, length - index, "predefined " );
Expand Down
3 changes: 2 additions & 1 deletion ompi/include/ompi/memchecker.h
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,8 @@ static inline int memchecker_datatype(MPI_Datatype type)
opal_memchecker_base_isdefined (&type->super.opt_desc.length, sizeof(opal_datatype_count_t));
opal_memchecker_base_isdefined (&type->super.opt_desc.used, sizeof(opal_datatype_count_t));
opal_memchecker_base_isdefined (&type->super.opt_desc.desc, sizeof(dt_elem_desc_t *));
opal_memchecker_base_isdefined (&type->super.btypes, OPAL_DATATYPE_MAX_PREDEFINED * sizeof(uint32_t));
if( NULL != type->super.ptypes )
opal_memchecker_base_isdefined (&type->super.ptypes, OPAL_DATATYPE_MAX_PREDEFINED * sizeof(size_t));

opal_memchecker_base_isdefined (&type->id, sizeof(int32_t));
opal_memchecker_base_isdefined (&type->d_f_to_c_index, sizeof(int32_t));
Expand Down
91 changes: 51 additions & 40 deletions opal/datatype/opal_convertor.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Copyright (c) 2004-2006 The Trustees of Indiana University and Indiana
* University Research and Technology
* Corporation. All rights reserved.
* Copyright (c) 2004-2016 The University of Tennessee and The University
* Copyright (c) 2004-2017 The University of Tennessee and The University
* of Tennessee Research Foundation. All rights
* reserved.
* Copyright (c) 2004-2006 High Performance Computing Center Stuttgart,
Expand Down Expand Up @@ -43,9 +43,6 @@
CONVERTOR->cbmemcpy( (DST), (SRC), (BLENGTH), (CONVERTOR) )
#endif

extern int opal_convertor_create_stack_with_pos_general( opal_convertor_t* convertor,
int starting_point, const int* sizes );

static void opal_convertor_construct( opal_convertor_t* convertor )
{
convertor->pStack = convertor->static_stack;
Expand Down Expand Up @@ -226,7 +223,7 @@ int32_t opal_convertor_pack( opal_convertor_t* pConv,
if( OPAL_LIKELY(pConv->flags & CONVERTOR_NO_OP) ) {
/**
* We are doing conversion on a contiguous datatype on a homogeneous
* environment. The convertor contain minimal informations, we only
* environment. The convertor contain minimal information, we only
* use the bConverted to manage the conversion.
*/
uint32_t i;
Expand Down Expand Up @@ -447,31 +444,49 @@ int32_t opal_convertor_set_position_nocheck( opal_convertor_t* convertor,
return rc;
}

static size_t
opal_datatype_compute_remote_size( const opal_datatype_t* pData,
const size_t* sizes )
{
uint32_t typeMask = pData->bdt_used;
size_t length = 0;

if( OPAL_UNLIKELY(NULL == pData->ptypes) ) {
/* Allocate and fill the array of types used in the datatype description */
opal_datatype_compute_ptypes( (opal_datatype_t*)pData );
}

for( int i = OPAL_DATATYPE_FIRST_TYPE; typeMask && (i < OPAL_DATATYPE_MAX_PREDEFINED); i++ ) {
if( typeMask & ((uint32_t)1 << i) ) {
length += (pData->ptypes[i] * sizes[i]);
typeMask ^= ((uint32_t)1 << i);
}
}
return length;
}

/**
* Compute the remote size. If necessary remove the homogeneous flag
* and redirect the convertor description toward the non-optimized
* datatype representation.
*/
#define OPAL_CONVERTOR_COMPUTE_REMOTE_SIZE(convertor, datatype, bdt_mask) \
{ \
if( OPAL_UNLIKELY(0 != (bdt_mask)) ) { \
opal_convertor_master_t* master; \
int i; \
uint32_t mask = datatype->bdt_used; \
convertor->flags &= (~CONVERTOR_HOMOGENEOUS); \
master = convertor->master; \
convertor->remote_size = 0; \
for( i = OPAL_DATATYPE_FIRST_TYPE; mask && (i < OPAL_DATATYPE_MAX_PREDEFINED); i++ ) { \
if( mask & ((uint32_t)1 << i) ) { \
convertor->remote_size += (datatype->btypes[i] * \
master->remote_sizes[i]); \
mask ^= ((uint32_t)1 << i); \
} \
} \
convertor->remote_size *= convertor->count; \
convertor->use_desc = &(datatype->desc); \
} \
size_t opal_convertor_compute_remote_size( opal_convertor_t* pConvertor )
{
opal_datatype_t* datatype = (opal_datatype_t*)pConvertor->pDesc;

pConvertor->remote_size = pConvertor->local_size;
if( OPAL_UNLIKELY(datatype->bdt_used & pConvertor->master->hetero_mask) ) {
pConvertor->flags &= (~CONVERTOR_HOMOGENEOUS);
pConvertor->use_desc = &(datatype->desc);
if( 0 == (pConvertor->flags & CONVERTOR_HAS_REMOTE_SIZE) ) {
/* This is for a single datatype, we must update it with the count */
pConvertor->remote_size = opal_datatype_compute_remote_size(datatype,
pConvertor->master->remote_sizes);
pConvertor->remote_size *= pConvertor->count;
}
}
pConvertor->flags |= CONVERTOR_HAS_REMOTE_SIZE;
return pConvertor->remote_size;
}

/**
Expand All @@ -483,29 +498,26 @@ int32_t opal_convertor_set_position_nocheck( opal_convertor_t* convertor,
*/
#define OPAL_CONVERTOR_PREPARE( convertor, datatype, count, pUserBuf ) \
{ \
uint32_t bdt_mask; \
\
convertor->local_size = count * datatype->size; \
convertor->pBaseBuf = (unsigned char*)pUserBuf; \
convertor->count = count; \
convertor->pDesc = (opal_datatype_t*)datatype; \
convertor->bConverted = 0; \
convertor->use_desc = &(datatype->opt_desc); \
/* If the data is empty we just mark the convertor as \
* completed. With this flag set the pack and unpack functions \
* will not do anything. \
*/ \
if( OPAL_UNLIKELY((0 == count) || (0 == datatype->size)) ) { \
convertor->flags |= OPAL_DATATYPE_FLAG_NO_GAPS | CONVERTOR_COMPLETED; \
convertor->flags |= (OPAL_DATATYPE_FLAG_NO_GAPS | CONVERTOR_COMPLETED | CONVERTOR_HAS_REMOTE_SIZE); \
convertor->local_size = convertor->remote_size = 0; \
return OPAL_SUCCESS; \
} \
/* Compute the local in advance */ \
convertor->local_size = count * datatype->size; \
convertor->pBaseBuf = (unsigned char*)pUserBuf; \
convertor->count = count; \
\
/* Grab the datatype part of the flags */ \
convertor->flags &= CONVERTOR_TYPE_MASK; \
convertor->flags |= (CONVERTOR_DATATYPE_MASK & datatype->flags); \
convertor->flags |= (CONVERTOR_NO_OP | CONVERTOR_HOMOGENEOUS); \
convertor->pDesc = (opal_datatype_t*)datatype; \
convertor->bConverted = 0; \
convertor->use_desc = &(datatype->opt_desc); \
\
convertor->remote_size = convertor->local_size; \
if( OPAL_LIKELY(convertor->remoteArch == opal_local_arch) ) { \
Expand All @@ -516,9 +528,8 @@ int32_t opal_convertor_set_position_nocheck( opal_convertor_t* convertor,
} \
} \
\
bdt_mask = datatype->bdt_used & convertor->master->hetero_mask; \
OPAL_CONVERTOR_COMPUTE_REMOTE_SIZE( convertor, datatype, \
bdt_mask ); \
assert( (convertor)->pDesc == (datatype) ); \
opal_convertor_compute_remote_size( convertor ); \
assert( NULL != convertor->use_desc->desc ); \
/* For predefined datatypes (contiguous) do nothing more */ \
/* if checksum is enabled then always continue */ \
Expand All @@ -530,7 +541,7 @@ int32_t opal_convertor_set_position_nocheck( opal_convertor_t* convertor,
} \
convertor->flags &= ~CONVERTOR_NO_OP; \
{ \
uint32_t required_stack_length = datatype->btypes[OPAL_DATATYPE_LOOP] + 1; \
uint32_t required_stack_length = datatype->loops + 1; \
\
if( required_stack_length > convertor->stack_size ) { \
assert(convertor->pStack == convertor->static_stack); \
Expand Down Expand Up @@ -714,8 +725,8 @@ void opal_datatype_dump_stack( const dt_stack_t* pStack, int stack_pos,
opal_output( 0, "%d: pos %d count %d disp %ld ", stack_pos, pStack[stack_pos].index,
(int)pStack[stack_pos].count, (long)pStack[stack_pos].disp );
if( pStack->index != -1 )
opal_output( 0, "\t[desc count %d disp %ld extent %ld]\n",
pDesc[pStack[stack_pos].index].elem.count,
opal_output( 0, "\t[desc count %lu disp %ld extent %ld]\n",
(unsigned long)pDesc[pStack[stack_pos].index].elem.count,
(long)pDesc[pStack[stack_pos].index].elem.disp,
(long)pDesc[pStack[stack_pos].index].elem.extent );
else
Expand Down
29 changes: 23 additions & 6 deletions opal/datatype/opal_convertor.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Copyright (c) 2004-2006 The Trustees of Indiana University and Indiana
* University Research and Technology
* Corporation. All rights reserved.
* Copyright (c) 2004-2014 The University of Tennessee and The University
* Copyright (c) 2004-2017 The University of Tennessee and The University
* of Tennessee Research Foundation. All rights
* reserved.
* Copyright (c) 2004-2006 High Performance Computing Center Stuttgart,
Expand Down Expand Up @@ -52,6 +52,7 @@ BEGIN_C_DECLS
#define CONVERTOR_STATE_ALLOC 0x04000000
#define CONVERTOR_COMPLETED 0x08000000
#define CONVERTOR_CUDA_UNIFIED 0x10000000
#define CONVERTOR_HAS_REMOTE_SIZE 0x20000000

union dt_elem_desc;
typedef struct opal_convertor_t opal_convertor_t;
Expand Down Expand Up @@ -184,9 +185,16 @@ static inline int32_t opal_convertor_need_buffers( const opal_convertor_t* pConv
return 1;
}

/**
* Update the size of the remote datatype representation. The size will
* depend on the configuration of the master convertor. In homogeneous
* environments, the local and remote sizes are identical.
*/
size_t
opal_convertor_compute_remote_size( opal_convertor_t* pConv );

/*
*
/**
* Return the local size of the convertor (count times the size of the datatype).
*/
static inline void opal_convertor_get_packed_size( const opal_convertor_t* pConv,
size_t* pSize )
Expand All @@ -195,16 +203,24 @@ static inline void opal_convertor_get_packed_size( const opal_convertor_t* pConv
}


/*
*
/**
* Return the remote size of the convertor (count times the remote size of the
* datatype). On homogeneous environments the local and remote sizes are
* identical.
*/
static inline void opal_convertor_get_unpacked_size( const opal_convertor_t* pConv,
size_t* pSize )
{
if( pConv->flags & CONVERTOR_HOMOGENEOUS ) {
*pSize = pConv->local_size;
return;
}
if( 0 == (CONVERTOR_HAS_REMOTE_SIZE & pConv->flags) ) {
opal_convertor_compute_remote_size( (opal_convertor_t*)pConv);
}
*pSize = pConv->remote_size;
}


/**
* Return the current absolute position of the next pack/unpack. This function is
* mostly useful for contiguous datatypes, when we need to get the pointer to the
Expand Down Expand Up @@ -277,6 +293,7 @@ opal_convertor_raw( opal_convertor_t* convertor, /* [IN/OUT] */
uint32_t* iov_count, /* [IN/OUT] */
size_t* length ); /* [OUT] */


/*
* Upper level does not need to call the _nocheck function directly.
*/
Expand Down
Loading