Skip to content

Commit 247b795

Browse files
authored
Merge pull request #11606 from yosefe/topic/pml-ucx-fix-log-calc
pml_ucx: use integer log2 calculation for datatype size
2 parents 39584df + bb258e5 commit 247b795

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

ompi/mca/pml/ucx/pml_ucx_datatype.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,19 @@ static inline int mca_pml_ucx_datatype_is_contig(ompi_datatype_t *datatype)
167167
(lb == 0);
168168
}
169169

170+
static unsigned mca_pml_ucx_ilog2_u64(uint64_t n)
171+
{
172+
#if OPAL_C_HAVE_BUILTIN_CLZ
173+
return (sizeof(n) * 8) - 1 - __builtin_clzll(n);
174+
#else
175+
unsigned i;
176+
for (i = 0; n > 1; ++i) {
177+
n >>= 1;
178+
}
179+
return i;
180+
#endif
181+
}
182+
170183
#ifdef HAVE_UCP_REQUEST_PARAM_T
171184
__opal_attribute_always_inline__ static inline
172185
pml_ucx_datatype_t *mca_pml_ucx_init_nbx_datatype(ompi_datatype_t *datatype,
@@ -196,7 +209,7 @@ pml_ucx_datatype_t *mca_pml_ucx_init_nbx_datatype(ompi_datatype_t *datatype,
196209
is_contig_pow2 = mca_pml_ucx_datatype_is_contig(datatype) &&
197210
(size && !(size & (size - 1))); /* is_pow2(size) */
198211
if (is_contig_pow2) {
199-
pml_datatype->size_shift = (int)(log(size) / log(2.0)); /* log2(size) */
212+
pml_datatype->size_shift = mca_pml_ucx_ilog2_u64(size);
200213
} else {
201214
pml_datatype->size_shift = 0;
202215
PML_UCX_DATATYPE_SET_VALUE(pml_datatype, op_attr_mask |= UCP_OP_ATTR_FIELD_DATATYPE);

0 commit comments

Comments
 (0)