From 80884d46eb9a823fc4f3810d3e9b7733815fb1df Mon Sep 17 00:00:00 2001 From: Wenduo Wang Date: Mon, 19 Aug 2024 23:24:30 +0000 Subject: [PATCH 1/3] coll/han: ptrdiff_t max size bugfix Fix buggy integer comparison of (ptrdiff_t) displ < SIZE_MAX Signed-off-by: Wenduo Wang --- ompi/mca/coll/han/coll_han_gatherv.c | 2 +- ompi/mca/coll/han/coll_han_scatterv.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ompi/mca/coll/han/coll_han_gatherv.c b/ompi/mca/coll/han/coll_han_gatherv.c index 248d15fdc29..f4fb8f8d474 100644 --- a/ompi/mca/coll/han/coll_han_gatherv.c +++ b/ompi/mca/coll/han/coll_han_gatherv.c @@ -170,7 +170,7 @@ int mca_coll_han_gatherv_intra(const void *sbuf, size_t scount, struct ompi_data } for (up_peer = 0; up_peer < up_size; ++up_peer) { - up_displs[up_peer] = INT_MAX; + up_displs[up_peer] = PTRDIFF_MAX; } /* Calculate recv counts for the inter-node gatherv - no need to gather diff --git a/ompi/mca/coll/han/coll_han_scatterv.c b/ompi/mca/coll/han/coll_han_scatterv.c index c18583dc498..47b7d553b93 100644 --- a/ompi/mca/coll/han/coll_han_scatterv.c +++ b/ompi/mca/coll/han/coll_han_scatterv.c @@ -174,7 +174,7 @@ int mca_coll_han_scatterv_intra(const void *sbuf, ompi_count_array_t scounts, om } for (up_peer = 0; up_peer < up_size; ++up_peer) { - up_displs[up_peer] = SIZE_MAX; + up_displs[up_peer] = PTRDIFF_MAX; } /* Calculate send counts for the inter-node scatterv */ From 37a6ffb3795116b808930dbaa3c73f457e9c465f Mon Sep 17 00:00:00 2001 From: Wenduo Wang Date: Mon, 19 Aug 2024 23:27:24 +0000 Subject: [PATCH 2/3] coll/han: remove unused variables Minor code cleanup Signed-off-by: Wenduo Wang --- ompi/mca/coll/han/coll_han_gatherv.c | 5 +---- ompi/mca/coll/han/coll_han_scatterv.c | 5 +---- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/ompi/mca/coll/han/coll_han_gatherv.c b/ompi/mca/coll/han/coll_han_gatherv.c index f4fb8f8d474..fd600b9d1cd 100644 --- a/ompi/mca/coll/han/coll_han_gatherv.c +++ b/ompi/mca/coll/han/coll_han_gatherv.c @@ -129,7 +129,7 @@ int mca_coll_han_gatherv_intra(const void *sbuf, size_t scount, struct ompi_data int need_bounce_buf = 0; size_t total_up_rcounts = 0; ptrdiff_t *up_displs = NULL; - size_t *up_rcounts = NULL, *up_peer_lb = NULL, *up_peer_ub = NULL; + size_t *up_rcounts = NULL, *up_peer_ub = NULL; ompi_count_array_t up_rcounts_desc; ompi_disp_array_t up_displs_desc; char *bounce_buf = NULL; @@ -273,9 +273,6 @@ int mca_coll_han_gatherv_intra(const void *sbuf, size_t scount, struct ompi_data if (up_rcounts) { free(up_rcounts); } - if (up_peer_lb) { - free(up_peer_lb); - } if (up_peer_ub) { free(up_peer_ub); } diff --git a/ompi/mca/coll/han/coll_han_scatterv.c b/ompi/mca/coll/han/coll_han_scatterv.c index 47b7d553b93..18c67baff91 100644 --- a/ompi/mca/coll/han/coll_han_scatterv.c +++ b/ompi/mca/coll/han/coll_han_scatterv.c @@ -143,7 +143,7 @@ int mca_coll_han_scatterv_intra(const void *sbuf, ompi_count_array_t scounts, om int need_bounce_buf = 0; size_t total_up_scounts = 0; ptrdiff_t *up_displs = NULL; - size_t *up_scounts = NULL, *up_peer_lb = NULL, *up_peer_ub = NULL; + size_t *up_scounts = NULL, *up_peer_ub = NULL; ompi_count_array_t up_scounts_desc; ompi_disp_array_t up_displs_desc; char *reorder_sbuf = (char *) sbuf, *bounce_buf = NULL; @@ -290,9 +290,6 @@ int mca_coll_han_scatterv_intra(const void *sbuf, ompi_count_array_t scounts, om if (up_scounts) { free(up_scounts); } - if (up_peer_lb) { - free(up_peer_lb); - } if (up_peer_ub) { free(up_peer_ub); } From f877e512335c44e7e17e248917bb8fabbaabb8fc Mon Sep 17 00:00:00 2001 From: Wenduo Wang Date: Mon, 19 Aug 2024 23:28:28 +0000 Subject: [PATCH 3/3] coll/han: cleanup unused utils With the large-count interface we no longer need these utils. Signed-off-by: Wenduo Wang --- ompi/mca/coll/han/Makefile.am | 3 +- ompi/mca/coll/han/coll_han.h | 7 --- ompi/mca/coll/han/coll_han_utils.c | 72 ------------------------------ 3 files changed, 1 insertion(+), 81 deletions(-) delete mode 100644 ompi/mca/coll/han/coll_han_utils.c diff --git a/ompi/mca/coll/han/Makefile.am b/ompi/mca/coll/han/Makefile.am index 6d0e1a7d6f0..978ef1805cb 100644 --- a/ompi/mca/coll/han/Makefile.am +++ b/ompi/mca/coll/han/Makefile.am @@ -35,8 +35,7 @@ coll_han_algorithms.c \ coll_han_dynamic.c \ coll_han_dynamic_file.c \ coll_han_topo.c \ -coll_han_subcomms.c \ -coll_han_utils.c +coll_han_subcomms.c # Make the output library in this directory, and name it either # mca__.la (for DSO builds) or libmca__.la diff --git a/ompi/mca/coll/han/coll_han.h b/ompi/mca/coll/han/coll_han.h index f4a57d119b7..e8f9db87c0e 100644 --- a/ompi/mca/coll/han/coll_han.h +++ b/ompi/mca/coll/han/coll_han.h @@ -561,13 +561,6 @@ ompi_coll_han_reorder_gather(const void *sbuf, struct ompi_communicator_t *comm, int * topo); -size_t -coll_han_utils_gcd(const uint64_t *numerators, const size_t size); - -int -coll_han_utils_create_contiguous_datatype(size_t count, const ompi_datatype_t *oldType, - ompi_datatype_t **newType); - static inline struct mca_smsc_endpoint_t *mca_coll_han_get_smsc_endpoint (struct ompi_proc_t *proc) { extern opal_mutex_t mca_coll_han_lock; if (NULL == proc->proc_endpoints[OMPI_PROC_ENDPOINT_TAG_SMSC]) { diff --git a/ompi/mca/coll/han/coll_han_utils.c b/ompi/mca/coll/han/coll_han_utils.c deleted file mode 100644 index a9f39eeada9..00000000000 --- a/ompi/mca/coll/han/coll_han_utils.c +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (c) Amazon.com, Inc. or its affiliates. - * All rights reserved. - * $COPYRIGHT$ - * - * Additional copyrights may follow - * - * $HEADER$ - */ - -/** - * @file - * - * Shared utility functions - */ - -#include "ompi/mca/coll/base/coll_base_functions.h" -#include "coll_han.h" - -/** - * Calculate the Greatest Common Denominator of a list of non-negative integers - * - * @param[in] numerators A list of numerators that should be divisible by - * the denominator - * @param[in] size Number of numerators - * @returns The GCD, where 1 <= GCD - */ -size_t coll_han_utils_gcd(const uint64_t *numerators, const size_t size) -{ - size_t denominator = (size_t) numerators[0], numerator, tmp; - - for (size_t i = 1; i < size; ++i) { - numerator = (size_t) numerators[i]; - - if (0 == denominator) { - denominator = numerator; - continue; - } - - if (0 == numerator) { - continue; - } - - while (0 < numerator % denominator && 0 < denominator % numerator) { - tmp = MIN(numerator, denominator); - denominator = MAX(numerator, denominator) - tmp; - numerator = tmp; - } - } - - if (0 == denominator) { - denominator = 1; - } - - return denominator; -} - -int coll_han_utils_create_contiguous_datatype(size_t count, const ompi_datatype_t *oldType, - ompi_datatype_t **newType) -{ - ompi_datatype_t *pdt; - - if ((0 == count) || (0 == oldType->super.size)) { - return ompi_datatype_duplicate(&ompi_mpi_datatype_null.dt, newType); - } - - pdt = ompi_datatype_create(oldType->super.desc.used + 2); - opal_datatype_add(&(pdt->super), &(oldType->super), count, 0, - (oldType->super.ub - oldType->super.lb)); - *newType = pdt; - return OMPI_SUCCESS; -}