root/ompi/mca/coll/hcoll/coll_hcoll_dtypes.h

/* [<][>][^][v][top][bottom][index][help] */

INCLUDED FROM


DEFINITIONS

This source file includes following definitions.
  1. hcoll_map_derived_type
  2. find_derived_mapping
  3. ompi_predefined_derived_2_hcoll
  4. ompi_dtype_2_hcoll_dtype
  5. ompi_op_2_hcolrte_op
  6. hcoll_type_attr_del_fn
  7. hcoll_type_attr_del_fn

   1 #ifndef COLL_HCOLL_DTYPES_H
   2 #define COLL_HCOLL_DTYPES_H
   3 
   4 /*Here comes the translation between ompi_datatype_t and dte_data_representation
   5   This is not complete and takes into account the basic datatypes only
   6   It is used to extract allreduce bcol functions where the arrhythmetics has to be done*/
   7 
   8 #include "ompi/datatype/ompi_datatype.h"
   9 #include "ompi/datatype/ompi_datatype_internal.h"
  10 #include "ompi/mca/op/op.h"
  11 #include "hcoll/api/hcoll_dte.h"
  12 extern int hcoll_type_attr_keyval;
  13 extern mca_coll_hcoll_dtype_t zero_dte_mapping;
  14 /*to keep this at hand: Ids of the basic opal_datatypes:
  15 #define OPAL_DATATYPE_INT1           4
  16 #define OPAL_DATATYPE_INT2           5
  17 #define OPAL_DATATYPE_INT4           6
  18 #define OPAL_DATATYPE_INT8           7
  19 #define OPAL_DATATYPE_INT16          8
  20 #define OPAL_DATATYPE_UINT1          9
  21 #define OPAL_DATATYPE_UINT2          10
  22 #define OPAL_DATATYPE_UINT4          11
  23 #define OPAL_DATATYPE_UINT8          12
  24 #define OPAL_DATATYPE_UINT16         13
  25 #define OPAL_DATATYPE_FLOAT2         14
  26 #define OPAL_DATATYPE_FLOAT4         15
  27 #define OPAL_DATATYPE_FLOAT8         16
  28 #define OPAL_DATATYPE_FLOAT12        17
  29 #define OPAL_DATATYPE_FLOAT16        18
  30 #define OPAL_DATATYPE_SHORT_FLOAT_COMPLEX 19
  31 #define OPAL_DATATYPE_FLOAT_COMPLEX  20
  32 #define OPAL_DATATYPE_DOUBLE_COMPLEX 21
  33 
  34 total 15 types
  35 */
  36 
  37 static dte_data_representation_t* ompi_datatype_2_dte_data_rep[OMPI_DATATYPE_MAX_PREDEFINED] = {
  38     &DTE_ZERO,                  /*OPAL_DATATYPE_LOOP           0 */
  39     &DTE_ZERO,                  /*OPAL_DATATYPE_END_LOOP       1 */
  40 #if defined(DTE_LB)
  41     &DTE_LB,                    /*OPAL_DATATYPE_LB             2 */
  42 #else
  43     &DTE_ZERO,
  44 #endif
  45 #if defined(DTE_UB)
  46     &DTE_UB,                    /*OPAL_DATATYPE_UB             3 */
  47 #else
  48     &DTE_ZERO,
  49 #endif
  50     &DTE_BYTE,                  /*OPAL_DATATYPE_INT1           4 */
  51     &DTE_INT16,                 /*OPAL_DATATYPE_INT2           5 */
  52     &DTE_INT32,                 /*OPAL_DATATYPE_INT4           6 */
  53     &DTE_INT64,                 /*OPAL_DATATYPE_INT8           7 */
  54     &DTE_INT128,                /*OPAL_DATATYPE_INT16          8 */
  55     &DTE_UBYTE,                 /*OPAL_DATATYPE_UINT1          9 */
  56     &DTE_UINT16,                /*OPAL_DATATYPE_UINT2          10 */
  57     &DTE_UINT32,                /*OPAL_DATATYPE_UINT4          11 */
  58     &DTE_UINT64,                /*OPAL_DATATYPE_UINT8          12 */
  59     &DTE_UINT128,               /*OPAL_DATATYPE_UINT16         13 */
  60 #if defined(DTE_FLOAT16)
  61     &DTE_FLOAT16,               /*OPAL_DATATYPE_FLOAT2         14 */
  62 #else
  63     &DTE_ZERO,
  64 #endif
  65     &DTE_FLOAT32,               /*OPAL_DATATYPE_FLOAT4         15 */
  66     &DTE_FLOAT64,               /*OPAL_DATATYPE_FLOAT8         16 */
  67     &DTE_FLOAT96,               /*OPAL_DATATYPE_FLOAT12        17 */
  68     &DTE_FLOAT128,              /*OPAL_DATATYPE_FLOAT16        18 */
  69     &DTE_ZERO,                  /*OPAL_DATATYPE_SHORT_FLOAT_COMPLEX 19 */
  70 #if defined(DTE_FLOAT32_COMPLEX)
  71     &DTE_FLOAT32_COMPLEX,       /*OPAL_DATATYPE_FLOAT_COMPLEX  20 */
  72 #else
  73     &DTE_ZERO,
  74 #endif
  75 #if defined(DTE_FLOAT64_COMPLEX)
  76     &DTE_FLOAT64_COMPLEX,       /*OPAL_DATATYPE_DOUBLE_COMPLEX 21 */
  77 #else
  78     &DTE_ZERO,
  79 #endif
  80 #if defined(DTE_FLOAT128_COMPLEX)
  81     &DTE_FLOAT128_COMPLEX,      /*OPAL_DATATYPE_LONG_DOUBLE_COMPLEX 22 */
  82 #else
  83     &DTE_ZERO,
  84 #endif
  85 #if defined(DTE_BOOL)
  86     &DTE_BOOL,                  /*OPAL_DATATYPE_BOOL           23 */
  87 #else
  88     &DTE_ZERO,
  89 #endif
  90 #if defined(DTE_WCHAR)
  91     &DTE_WCHAR,                 /*OPAL_DATATYPE_WCHAR          24 */
  92 #else
  93     &DTE_ZERO,
  94 #endif
  95     &DTE_ZERO                   /*OPAL_DATATYPE_UNAVAILABLE    25 */
  96 };
  97 
  98 enum {
  99     TRY_FIND_DERIVED,
 100     NO_DERIVED
 101 };
 102 
 103 
 104 #if HCOLL_API >= HCOLL_VERSION(3,6)
 105 static inline
 106 void hcoll_map_derived_type(ompi_datatype_t *dtype, dte_data_representation_t *new_dte)
 107 {
 108     int rc;
 109     if (NULL == dtype->args) {
 110         /* predefined type, shouldn't call this */
 111         return;
 112     }
 113     rc = hcoll_create_mpi_type((void*)dtype, new_dte);
 114     if (rc != HCOLL_SUCCESS) {
 115         /* If hcoll fails to create mpi derived type let's set zero_dte on this dtype.
 116            This will save cycles on subsequent collective calls with the same derived
 117            type since we will not try to create hcoll type again. */
 118         ompi_attr_set_c(TYPE_ATTR, (void*)dtype, &(dtype->d_keyhash),
 119                         hcoll_type_attr_keyval, &zero_dte_mapping, false);
 120     }
 121 }
 122 
 123 static dte_data_representation_t find_derived_mapping(ompi_datatype_t *dtype){
 124     dte_data_representation_t dte = DTE_ZERO;
 125     mca_coll_hcoll_dtype_t *hcoll_dtype;
 126     if (mca_coll_hcoll_component.derived_types_support_enabled) {
 127         int map_found = 0;
 128         ompi_attr_get_c(dtype->d_keyhash, hcoll_type_attr_keyval,
 129                         (void**)&hcoll_dtype, &map_found);
 130         if (!map_found)
 131             hcoll_map_derived_type(dtype, &dte);
 132         else
 133             dte = hcoll_dtype->type;
 134     }
 135 
 136     return dte;
 137 }
 138 
 139 
 140 
 141 static inline  dte_data_representation_t
 142 ompi_predefined_derived_2_hcoll(int ompi_id) {
 143     switch(ompi_id) {
 144     case OMPI_DATATYPE_MPI_FLOAT_INT:
 145         return DTE_FLOAT_INT;
 146     case OMPI_DATATYPE_MPI_DOUBLE_INT:
 147         return DTE_DOUBLE_INT;
 148     case OMPI_DATATYPE_MPI_LONG_INT:
 149         return DTE_LONG_INT;
 150     case OMPI_DATATYPE_MPI_SHORT_INT:
 151         return DTE_SHORT_INT;
 152     case OMPI_DATATYPE_MPI_LONG_DOUBLE_INT:
 153         return DTE_LONG_DOUBLE_INT;
 154     case OMPI_DATATYPE_MPI_2INT:
 155         return DTE_2INT;
 156 #if HCOLL_API >= HCOLL_VERSION(3,7)
 157     case OMPI_DATATYPE_MPI_2INTEGER:
 158 #if OMPI_SIZEOF_FORTRAN_INTEGER == 4
 159         return DTE_2INT;
 160 #elif OMPI_SIZEOF_FORTRAN_INTEGER == 8
 161         return DTE_2INT64;
 162 #else
 163         return DTE_ZERO;
 164 #endif
 165     case OMPI_DATATYPE_MPI_2REAL:
 166 #if OMPI_SIZEOF_FORTRAN_REAL == 4
 167         return DTE_2FLOAT32;
 168 #elif OMPI_SIZEOF_FORTRAN_REAL == 8
 169         return DTE_2FLOAT64;
 170 #else
 171         return DTE_ZERO;
 172 #endif
 173     case OMPI_DATATYPE_MPI_2DBLPREC:
 174 #if OMPI_SIZEOF_FORTRAN_DOUBLE_PRECISION == 4
 175         return DTE_2FLOAT32;
 176 #elif OMPI_SIZEOF_FORTRAN_DOUBLE_PRECISION == 8
 177         return DTE_2FLOAT64;
 178 #else
 179         return DTE_ZERO;
 180 #endif
 181 #endif
 182     default:
 183         break;
 184     }
 185     return DTE_ZERO;
 186 }
 187 #endif
 188 
 189 static dte_data_representation_t
 190 ompi_dtype_2_hcoll_dtype( ompi_datatype_t *dtype,
 191                           const int mode)
 192 {
 193     int ompi_type_id = dtype->id;
 194     int opal_type_id = dtype->super.id;
 195     dte_data_representation_t dte_data_rep = DTE_ZERO;
 196 
 197     if (ompi_type_id < OMPI_DATATYPE_MPI_MAX_PREDEFINED &&
 198         dtype->super.flags & OMPI_DATATYPE_FLAG_PREDEFINED) {
 199         if (opal_type_id > 0 && opal_type_id < OPAL_DATATYPE_MAX_PREDEFINED) {
 200             dte_data_rep =  *ompi_datatype_2_dte_data_rep[opal_type_id];
 201         }
 202 #if HCOLL_API >= HCOLL_VERSION(3,6)
 203         else if (TRY_FIND_DERIVED == mode){
 204             dte_data_rep =  ompi_predefined_derived_2_hcoll(ompi_type_id);
 205         }
 206     } else {
 207         if (TRY_FIND_DERIVED == mode)
 208             dte_data_rep =  find_derived_mapping(dtype);
 209 #endif
 210     }
 211     if (HCOL_DTE_IS_ZERO(dte_data_rep) && TRY_FIND_DERIVED == mode &&
 212         !mca_coll_hcoll_component.hcoll_datatype_fallback) {
 213         dte_data_rep = DTE_ZERO;
 214         dte_data_rep.rep.in_line_rep.data_handle.in_line.in_line = 0;
 215         dte_data_rep.rep.in_line_rep.data_handle.pointer_to_handle = (uint64_t ) &dtype->super;
 216     }
 217     return dte_data_rep;
 218 }
 219 
 220 static hcoll_dte_op_t* ompi_op_2_hcoll_op[OMPI_OP_BASE_FORTRAN_OP_MAX + 1] = {
 221    &hcoll_dte_op_null,          /* OMPI_OP_BASE_FORTRAN_NULL = 0 */
 222    &hcoll_dte_op_max,           /* OMPI_OP_BASE_FORTRAN_MAX */
 223    &hcoll_dte_op_min,           /* OMPI_OP_BASE_FORTRAN_MIN */
 224    &hcoll_dte_op_sum,           /* OMPI_OP_BASE_FORTRAN_SUM */
 225    &hcoll_dte_op_prod,          /* OMPI_OP_BASE_FORTRAN_PROD */
 226    &hcoll_dte_op_land,          /* OMPI_OP_BASE_FORTRAN_LAND */
 227    &hcoll_dte_op_band,          /* OMPI_OP_BASE_FORTRAN_BAND */
 228    &hcoll_dte_op_lor,           /* OMPI_OP_BASE_FORTRAN_LOR */
 229    &hcoll_dte_op_bor,           /* OMPI_OP_BASE_FORTRAN_BOR */
 230    &hcoll_dte_op_lxor,          /* OMPI_OP_BASE_FORTRAN_LXOR */
 231    &hcoll_dte_op_bxor,          /* OMPI_OP_BASE_FORTRAN_BXOR */
 232    &hcoll_dte_op_null,          /* OMPI_OP_BASE_FORTRAN_MAXLOC */
 233    &hcoll_dte_op_null,          /* OMPI_OP_BASE_FORTRAN_MINLOC */
 234    &hcoll_dte_op_null,          /* OMPI_OP_BASE_FORTRAN_REPLACE */
 235    &hcoll_dte_op_null,          /* OMPI_OP_BASE_FORTRAN_NO_OP */
 236    &hcoll_dte_op_null           /* OMPI_OP_BASE_FORTRAN_OP_MAX */
 237 };
 238 static hcoll_dte_op_t* ompi_op_2_hcolrte_op(ompi_op_t *op) {
 239     if (op->o_f_to_c_index > OMPI_OP_BASE_FORTRAN_OP_MAX) {
 240         return ompi_op_2_hcoll_op[0]; /* return null */
 241     }
 242     return ompi_op_2_hcoll_op[op->o_f_to_c_index];
 243 }
 244 
 245 
 246 #if HCOLL_API >= HCOLL_VERSION(3,6)
 247 static int hcoll_type_attr_del_fn(MPI_Datatype type, int keyval, void *attr_val, void *extra) {
 248     int ret = OMPI_SUCCESS;
 249     mca_coll_hcoll_dtype_t *dtype =
 250         (mca_coll_hcoll_dtype_t*) attr_val;
 251 
 252     assert(dtype);
 253     if (&zero_dte_mapping == dtype) {
 254         return OMPI_SUCCESS;
 255     }
 256     if (HCOLL_SUCCESS != (ret = hcoll_dt_destroy(dtype->type))) {
 257         HCOL_ERROR("failed to delete type attr: hcoll_dte_destroy returned %d",ret);
 258         return OMPI_ERROR;
 259     }
 260     opal_free_list_return(&mca_coll_hcoll_component.dtypes,
 261                           &dtype->super);
 262 
 263     return OMPI_SUCCESS;
 264 }
 265 #else
 266 static int hcoll_type_attr_del_fn(MPI_Datatype type, int keyval, void *attr_val, void *extra) {
 267     /*Do nothing - it's an old version of hcoll w/o dtypes support */
 268     return OMPI_SUCCESS;
 269 }
 270 #endif
 271 #endif /* COLL_HCOLL_DTYPES_H */

/* [<][>][^][v][top][bottom][index][help] */