Skip to content

Commit

Permalink
Expose opal_datatype_compute_remote_size.
Browse files Browse the repository at this point in the history
This function can be used to compute the packed size of a datatype on a
target architecture.

Signed-off-by: George Bosilca <[email protected]>
  • Loading branch information
bosilca committed Aug 31, 2021
1 parent 0041ce8 commit 74049fc
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 26 deletions.
29 changes: 3 additions & 26 deletions opal/datatype/opal_convertor.c
Original file line number Diff line number Diff line change
Expand Up @@ -455,29 +455,6 @@ int32_t opal_convertor_set_position_nocheck(opal_convertor_t *convertor, size_t
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_datatype_is_predefined(pData)) {
return sizes[pData->desc.desc->elem.common.type];
}

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
Expand All @@ -496,9 +473,9 @@ size_t opal_convertor_compute_remote_size(opal_convertor_t *pConvertor)
}
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 =
opal_datatype_compute_remote_size(datatype,
pConvertor->master->remote_sizes);
pConvertor->remote_size *= pConvertor->count;
}
}
Expand Down
9 changes: 9 additions & 0 deletions opal/datatype/opal_datatype.h
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,15 @@ OPAL_DECLSPEC int32_t opal_datatype_copy_content_same_ddt(const opal_datatype_t

OPAL_DECLSPEC int opal_datatype_compute_ptypes(opal_datatype_t *datatype);

/*
* Compute the size of the datatype using a specific set of predefined type sizes.
* This function allows to compute the size of a packed buffer without creating
* a fully fledged specialized convertor for the remote peer.
*/
OPAL_DECLSPEC size_t
opal_datatype_compute_remote_size(const opal_datatype_t *pData,
const size_t *sizes);

/* Compute the span in memory of count datatypes. This function help with temporary
* memory allocations for receiving already typed data (such as those used for reduce
* operations). This span is the distance between the minimum and the maximum byte
Expand Down
24 changes: 24 additions & 0 deletions opal/datatype/opal_datatype_get_count.c
Original file line number Diff line number Diff line change
Expand Up @@ -223,3 +223,27 @@ int opal_datatype_compute_ptypes(opal_datatype_t *datatype)
}
}
}

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_datatype_is_predefined(pData)) {
return sizes[pData->desc.desc->elem.common.type];
}

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;
}

0 comments on commit 74049fc

Please sign in to comment.