Skip to content

Commit 1e311b2

Browse files
author
Valentin Petrov
committed
coll/hcoll: dtype fallback optimization
If hcoll fails to create mpi derived type let's set zero_dte on this dtype. This will save cycles on subsequent collective calls with the same derived type since we will not try to create hcoll type again. Signed-off-by: Valentin Petrov <[email protected]>
1 parent 06ef344 commit 1e311b2

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

ompi/mca/coll/hcoll/coll_hcoll.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ typedef struct {
5656
} mca_coll_hcoll_dtype_t;
5757
OBJ_CLASS_DECLARATION(mca_coll_hcoll_dtype_t);
5858

59+
extern mca_coll_hcoll_dtype_t zero_dte_mapping;
5960
struct mca_coll_hcoll_component_t {
6061
/** Base coll component */
6162
mca_coll_base_component_2_0_0_t super;

ompi/mca/coll/hcoll/coll_hcoll_dtypes.h

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include "ompi/mca/op/op.h"
1111
#include "hcoll/api/hcoll_dte.h"
1212
extern int hcoll_type_attr_keyval;
13-
13+
extern mca_coll_hcoll_dtype_t zero_dte_mapping;
1414
/*to keep this at hand: Ids of the basic opal_datatypes:
1515
#define OPAL_DATATYPE_INT1 4
1616
#define OPAL_DATATYPE_INT2 5
@@ -97,15 +97,21 @@ enum {
9797

9898
#if HCOLL_API >= HCOLL_VERSION(3,6)
9999
static inline
100-
int hcoll_map_derived_type(ompi_datatype_t *dtype, dte_data_representation_t *new_dte)
100+
void hcoll_map_derived_type(ompi_datatype_t *dtype, dte_data_representation_t *new_dte)
101101
{
102102
int rc;
103103
if (NULL == dtype->args) {
104104
/* predefined type, shouldn't call this */
105-
return OMPI_SUCCESS;
105+
return;
106106
}
107107
rc = hcoll_create_mpi_type((void*)dtype, new_dte);
108-
return rc == HCOLL_SUCCESS ? OMPI_SUCCESS : OMPI_ERROR;
108+
if (rc != HCOLL_SUCCESS) {
109+
/* If hcoll fails to create mpi derived type let's set zero_dte on this dtype.
110+
This will save cycles on subsequent collective calls with the same derived
111+
type since we will not try to create hcoll type again. */
112+
ompi_attr_set_c(TYPE_ATTR, (void*)dtype, &(dtype->d_keyhash),
113+
hcoll_type_attr_keyval, &zero_dte_mapping, false);
114+
}
109115
}
110116

111117
static dte_data_representation_t find_derived_mapping(ompi_datatype_t *dtype){
@@ -238,6 +244,9 @@ static int hcoll_type_attr_del_fn(MPI_Datatype type, int keyval, void *attr_val,
238244
(mca_coll_hcoll_dtype_t*) attr_val;
239245

240246
assert(dtype);
247+
if (&zero_dte_mapping == dtype) {
248+
return OMPI_SUCCESS;
249+
}
241250
if (HCOLL_SUCCESS != (ret = hcoll_dt_destroy(dtype->type))) {
242251
HCOL_ERROR("failed to delete type attr: hcoll_dte_destroy returned %d",ret);
243252
return OMPI_ERROR;

ompi/mca/coll/hcoll/coll_hcoll_module.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
int hcoll_comm_attr_keyval;
1919
int hcoll_type_attr_keyval;
20-
20+
mca_coll_hcoll_dtype_t zero_dte_mapping;
2121
/*
2222
* Initial query function that is invoked during MPI_INIT, allowing
2323
* this module to indicate what level of thread support it provides.
@@ -333,6 +333,7 @@ mca_coll_hcoll_comm_query(struct ompi_communicator_t *comm, int *priority)
333333
}
334334

335335
if (mca_coll_hcoll_component.derived_types_support_enabled) {
336+
zero_dte_mapping.type = DTE_ZERO;
336337
copy_fn.attr_datatype_copy_fn = (MPI_Type_internal_copy_attr_function *) MPI_TYPE_NULL_COPY_FN;
337338
del_fn.attr_datatype_delete_fn = hcoll_type_attr_del_fn;
338339
err = ompi_attr_create_keyval(TYPE_ATTR, copy_fn, del_fn, &hcoll_type_attr_keyval, NULL ,0, NULL);

0 commit comments

Comments
 (0)