root/opal/datatype/opal_datatype_module.c

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

DEFINITIONS

This source file includes following definitions.
  1. opal_datatype_register_params
  2. opal_datatype_finalize
  3. opal_datatype_init
  4. opal_datatype_safeguard_pointer_debug_breakpoint

   1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
   2 /*
   3  * Copyright (c) 2004-2006 The Trustees of Indiana University and Indiana
   4  *                         University Research and Technology
   5  *                         Corporation.  All rights reserved.
   6  * Copyright (c) 2004-2018 The University of Tennessee and The University
   7  *                         of Tennessee Research Foundation.  All rights
   8  *                         reserved.
   9  * Copyright (c) 2004-2006 High Performance Computing Center Stuttgart,
  10  *                         University of Stuttgart.  All rights reserved.
  11  * Copyright (c) 2004-2006 The Regents of the University of California.
  12  *                         All rights reserved.
  13  * Copyright (c) 2007-2018 Cisco Systems, Inc.  All rights reserved
  14  * Copyright (c) 2009      Sun Microsystems, Inc.  All rights reserved.
  15  * Copyright (c) 2009      Oak Ridge National Labs.  All rights reserved.
  16  * Copyright (c) 2013      Los Alamos National Security, LLC. All rights
  17  *                         reserved.
  18  * Copyright (c) 2015      Research Organization for Information Science
  19  *                         and Technology (RIST). All rights reserved.
  20  * Copyright (c) 2018      Triad National Security, LLC. All rights
  21  *                         reserved.
  22  * Copyright (c) 2018      FUJITSU LIMITED.  All rights reserved.
  23  * $COPYRIGHT$
  24  *
  25  * Additional copyrights may follow
  26  *
  27  * $HEADER$
  28  */
  29 
  30 #include "opal_config.h"
  31 
  32 #include <stddef.h>
  33 
  34 #include "opal/runtime/opal.h"
  35 #include "opal/util/arch.h"
  36 #include "opal/util/output.h"
  37 #include "opal/datatype/opal_datatype_internal.h"
  38 #include "opal/datatype/opal_datatype.h"
  39 #include "opal/datatype/opal_convertor_internal.h"
  40 #include "opal/mca/base/mca_base_var.h"
  41 
  42 /* by default the debuging is turned off */
  43 int opal_datatype_dfd = -1;
  44 bool opal_unpack_debug = false;
  45 bool opal_pack_debug = false;
  46 bool opal_position_debug = false;
  47 bool opal_copy_debug = false;
  48 int opal_ddt_verbose = -1;  /* Has the datatype verbose it's own output stream */
  49 
  50 extern int opal_cuda_verbose;
  51 
  52 /* Using this macro implies that at this point _all_ informations needed
  53  * to fill up the datatype are known.
  54  * We fill all the static information, the pointer to desc.desc is setup
  55  * into an array, which is initialized at runtime.
  56  * Everything is constant.
  57  */
  58 OPAL_DECLSPEC const opal_datatype_t opal_datatype_empty =       OPAL_DATATYPE_INITIALIZER_EMPTY(0);
  59 
  60 OPAL_DECLSPEC const opal_datatype_t opal_datatype_loop =        OPAL_DATATYPE_INITIALIZER_LOOP(0);
  61 OPAL_DECLSPEC const opal_datatype_t opal_datatype_end_loop =    OPAL_DATATYPE_INITIALIZER_END_LOOP(0);
  62 OPAL_DECLSPEC const opal_datatype_t opal_datatype_lb =          OPAL_DATATYPE_INITIALIZER_LB(0);
  63 OPAL_DECLSPEC const opal_datatype_t opal_datatype_ub =          OPAL_DATATYPE_INITIALIZER_UB(0);
  64 OPAL_DECLSPEC const opal_datatype_t opal_datatype_int1 =        OPAL_DATATYPE_INITIALIZER_INT1(0);
  65 OPAL_DECLSPEC const opal_datatype_t opal_datatype_int2 =        OPAL_DATATYPE_INITIALIZER_INT2(0);
  66 OPAL_DECLSPEC const opal_datatype_t opal_datatype_int4 =        OPAL_DATATYPE_INITIALIZER_INT4(0);
  67 OPAL_DECLSPEC const opal_datatype_t opal_datatype_int8 =        OPAL_DATATYPE_INITIALIZER_INT8(0);
  68 OPAL_DECLSPEC const opal_datatype_t opal_datatype_int16 =       OPAL_DATATYPE_INITIALIZER_INT16(0);
  69 OPAL_DECLSPEC const opal_datatype_t opal_datatype_uint1 =       OPAL_DATATYPE_INITIALIZER_UINT1(0);
  70 OPAL_DECLSPEC const opal_datatype_t opal_datatype_uint2 =       OPAL_DATATYPE_INITIALIZER_UINT2(0);
  71 OPAL_DECLSPEC const opal_datatype_t opal_datatype_uint4 =       OPAL_DATATYPE_INITIALIZER_UINT4(0);
  72 OPAL_DECLSPEC const opal_datatype_t opal_datatype_uint8 =       OPAL_DATATYPE_INITIALIZER_UINT8(0);
  73 OPAL_DECLSPEC const opal_datatype_t opal_datatype_uint16 =      OPAL_DATATYPE_INITIALIZER_UINT16(0);
  74 OPAL_DECLSPEC const opal_datatype_t opal_datatype_float2 =      OPAL_DATATYPE_INITIALIZER_FLOAT2(0);
  75 OPAL_DECLSPEC const opal_datatype_t opal_datatype_float4 =      OPAL_DATATYPE_INITIALIZER_FLOAT4(0);
  76 OPAL_DECLSPEC const opal_datatype_t opal_datatype_float8 =      OPAL_DATATYPE_INITIALIZER_FLOAT8(0);
  77 OPAL_DECLSPEC const opal_datatype_t opal_datatype_float12 =     OPAL_DATATYPE_INITIALIZER_FLOAT12(0);
  78 OPAL_DECLSPEC const opal_datatype_t opal_datatype_float16 =     OPAL_DATATYPE_INITIALIZER_FLOAT16(0);
  79 OPAL_DECLSPEC const opal_datatype_t opal_datatype_short_float_complex = OPAL_DATATYPE_INITIALIZER_SHORT_FLOAT_COMPLEX(0);
  80 OPAL_DECLSPEC const opal_datatype_t opal_datatype_float_complex = OPAL_DATATYPE_INITIALIZER_FLOAT_COMPLEX(0);
  81 OPAL_DECLSPEC const opal_datatype_t opal_datatype_double_complex = OPAL_DATATYPE_INITIALIZER_DOUBLE_COMPLEX(0);
  82 OPAL_DECLSPEC const opal_datatype_t opal_datatype_long_double_complex = OPAL_DATATYPE_INITIALIZER_LONG_DOUBLE_COMPLEX(0);
  83 OPAL_DECLSPEC const opal_datatype_t opal_datatype_bool =        OPAL_DATATYPE_INITIALIZER_BOOL(0);
  84 OPAL_DECLSPEC const opal_datatype_t opal_datatype_wchar =       OPAL_DATATYPE_INITIALIZER_WCHAR(0);
  85 OPAL_DECLSPEC const opal_datatype_t opal_datatype_unavailable = OPAL_DATATYPE_INITIALIZER_UNAVAILABLE_NAMED(UNAVAILABLE, 0);
  86 
  87 OPAL_DECLSPEC dt_elem_desc_t opal_datatype_predefined_elem_desc[2 * OPAL_DATATYPE_MAX_PREDEFINED] = {{{{0}}}};
  88 
  89 /*
  90  * NOTE: The order of this array *MUST* match the order in opal_datatype_basicDatatypes
  91  * (use of designated initializers should relax this restrictions some)
  92  */
  93 OPAL_DECLSPEC const size_t opal_datatype_local_sizes[OPAL_DATATYPE_MAX_PREDEFINED] =
  94 {
  95     [OPAL_DATATYPE_INT1] = sizeof(int8_t),
  96     [OPAL_DATATYPE_INT2] = sizeof(int16_t),
  97     [OPAL_DATATYPE_INT4] = sizeof(int32_t),
  98     [OPAL_DATATYPE_INT8] = sizeof(int64_t),
  99     [OPAL_DATATYPE_INT16] = 16,    /* sizeof (int128_t) */
 100     [OPAL_DATATYPE_UINT1] = sizeof(uint8_t),
 101     [OPAL_DATATYPE_UINT2] = sizeof(uint16_t),
 102     [OPAL_DATATYPE_UINT4] = sizeof(uint32_t),
 103     [OPAL_DATATYPE_UINT8] = sizeof(uint64_t),
 104     [OPAL_DATATYPE_UINT16] = 16,    /* sizeof (uint128_t) */
 105     [OPAL_DATATYPE_FLOAT2] = 2,     /* sizeof (float2) */
 106     [OPAL_DATATYPE_FLOAT4] = 4,     /* sizeof (float4) */
 107     [OPAL_DATATYPE_FLOAT8] = 8,     /* sizeof (float8) */
 108     [OPAL_DATATYPE_FLOAT12] = 12,   /* sizeof (float12) */
 109     [OPAL_DATATYPE_FLOAT16] = 16,   /* sizeof (float16) */
 110 #if defined(HAVE_SHORT_FLOAT__COMPLEX)
 111     [OPAL_DATATYPE_SHORT_FLOAT_COMPLEX] = sizeof(short float _Complex),
 112 #elif defined(HAVE_OPAL_SHORT_FLOAT_COMPLEX_T)
 113     [OPAL_DATATYPE_SHORT_FLOAT_COMPLEX] = sizeof(opal_short_float_complex_t),
 114 #else
 115     [OPAL_DATATYPE_SHORT_FLOAT_COMPLEX] = 4, /* typical sizeof(short float _Complex) */
 116 #endif
 117     [OPAL_DATATYPE_FLOAT_COMPLEX] = sizeof(float _Complex),
 118     [OPAL_DATATYPE_DOUBLE_COMPLEX] = sizeof(double _Complex),
 119     [OPAL_DATATYPE_LONG_DOUBLE_COMPLEX] = sizeof(long double _Complex),
 120     [OPAL_DATATYPE_BOOL] = sizeof (_Bool),
 121     [OPAL_DATATYPE_WCHAR] = sizeof (wchar_t),
 122 };
 123 
 124 /*
 125  * NOTE: The order of this array *MUST* match what is listed in datatype.h
 126  * (use of designated initializers should relax this restrictions some)
 127  */
 128 OPAL_DECLSPEC const opal_datatype_t* opal_datatype_basicDatatypes[OPAL_DATATYPE_MAX_PREDEFINED] = {
 129     [OPAL_DATATYPE_LOOP] = &opal_datatype_loop,
 130     [OPAL_DATATYPE_END_LOOP] = &opal_datatype_end_loop,
 131     [OPAL_DATATYPE_LB] = &opal_datatype_lb,
 132     [OPAL_DATATYPE_UB] = &opal_datatype_ub,
 133     [OPAL_DATATYPE_INT1] = &opal_datatype_int1,
 134     [OPAL_DATATYPE_INT2] = &opal_datatype_int2,
 135     [OPAL_DATATYPE_INT4] = &opal_datatype_int4,
 136     [OPAL_DATATYPE_INT8] = &opal_datatype_int8,
 137     [OPAL_DATATYPE_INT16] = &opal_datatype_int16,       /* Yes, double-machine word integers are available */
 138     [OPAL_DATATYPE_UINT1] = &opal_datatype_uint1,
 139     [OPAL_DATATYPE_UINT2] = &opal_datatype_uint2,
 140     [OPAL_DATATYPE_UINT4] = &opal_datatype_uint4,
 141     [OPAL_DATATYPE_UINT8] = &opal_datatype_uint8,
 142     [OPAL_DATATYPE_UINT16] = &opal_datatype_uint16,      /* Yes, double-machine word integers are available */
 143     [OPAL_DATATYPE_FLOAT2] = &opal_datatype_float2,
 144     [OPAL_DATATYPE_FLOAT4] = &opal_datatype_float4,
 145     [OPAL_DATATYPE_FLOAT8] = &opal_datatype_float8,
 146     [OPAL_DATATYPE_FLOAT12] = &opal_datatype_float12,
 147     [OPAL_DATATYPE_FLOAT16] = &opal_datatype_float16,
 148     [OPAL_DATATYPE_SHORT_FLOAT_COMPLEX] = &opal_datatype_short_float_complex,
 149     [OPAL_DATATYPE_FLOAT_COMPLEX] = &opal_datatype_float_complex,
 150     [OPAL_DATATYPE_DOUBLE_COMPLEX] = &opal_datatype_double_complex,
 151     [OPAL_DATATYPE_LONG_DOUBLE_COMPLEX] = &opal_datatype_long_double_complex,
 152     [OPAL_DATATYPE_BOOL] = &opal_datatype_bool,
 153     [OPAL_DATATYPE_WCHAR] = &opal_datatype_wchar,
 154     [OPAL_DATATYPE_UNAVAILABLE] = &opal_datatype_unavailable,
 155 };
 156 
 157 
 158 int opal_datatype_register_params(void)
 159 {
 160 #if OPAL_ENABLE_DEBUG
 161     int ret;
 162 
 163     ret = mca_base_var_register ("opal", "mpi", NULL, "ddt_unpack_debug",
 164                                  "Whether to output debugging information in the ddt unpack functions (nonzero = enabled)",
 165                                  MCA_BASE_VAR_TYPE_BOOL, NULL, 0, MCA_BASE_VAR_FLAG_SETTABLE, OPAL_INFO_LVL_3,
 166                                  MCA_BASE_VAR_SCOPE_LOCAL, &opal_unpack_debug);
 167     if (0 > ret) {
 168         return ret;
 169     }
 170 
 171     ret = mca_base_var_register ("opal", "mpi", NULL, "ddt_pack_debug",
 172                                  "Whether to output debugging information in the ddt pack functions (nonzero = enabled)",
 173                                  MCA_BASE_VAR_TYPE_BOOL, NULL, 0, MCA_BASE_VAR_FLAG_SETTABLE, OPAL_INFO_LVL_3,
 174                                  MCA_BASE_VAR_SCOPE_LOCAL, &opal_pack_debug);
 175     if (0 > ret) {
 176         return ret;
 177     }
 178 
 179     ret = mca_base_var_register ("opal", "mpi", NULL, "ddt_position_debug",
 180                                  "Non zero lead to output generated by the datatype position functions",
 181                                  MCA_BASE_VAR_TYPE_BOOL, NULL, 0, MCA_BASE_VAR_FLAG_SETTABLE, OPAL_INFO_LVL_3,
 182                                  MCA_BASE_VAR_SCOPE_LOCAL, &opal_position_debug);
 183     if (0 > ret) {
 184         return ret;
 185     }
 186 
 187     ret = mca_base_var_register ("opal", "mpi", NULL, "ddt_copy_debug",
 188                                  "Whether to output debugging information in the ddt copy functions (nonzero = enabled)",
 189                                  MCA_BASE_VAR_TYPE_BOOL, NULL, 0, MCA_BASE_VAR_FLAG_SETTABLE, OPAL_INFO_LVL_3,
 190                                  MCA_BASE_VAR_SCOPE_LOCAL, &opal_copy_debug);
 191     if (0 > ret) {
 192         return ret;
 193     }
 194 
 195     ret = mca_base_var_register ("opal", "opal", NULL, "ddt_verbose",
 196                                  "Set level of opal datatype verbosity",
 197                                  MCA_BASE_VAR_TYPE_INT, NULL, 0, MCA_BASE_VAR_FLAG_SETTABLE,
 198                                  OPAL_INFO_LVL_8, MCA_BASE_VAR_SCOPE_LOCAL,
 199                                  &opal_ddt_verbose);
 200     if (0 > ret) {
 201         return ret;
 202     }
 203 #if OPAL_CUDA_SUPPORT
 204     /* Set different levels of verbosity in the cuda related code. */
 205     ret = mca_base_var_register ("opal", "opal", NULL, "cuda_verbose",
 206                                  "Set level of opal cuda verbosity",
 207                                  MCA_BASE_VAR_TYPE_INT, NULL, 0, MCA_BASE_VAR_FLAG_SETTABLE,
 208                                  OPAL_INFO_LVL_8, MCA_BASE_VAR_SCOPE_LOCAL,
 209                                  &opal_cuda_verbose);
 210     if (0 > ret) {
 211         return ret;
 212     }
 213 #endif
 214 
 215 #endif /* OPAL_ENABLE_DEBUG */
 216 
 217     return OPAL_SUCCESS;
 218 }
 219 
 220 static void opal_datatype_finalize (void)
 221 {
 222     /* As the synonyms are just copies of the internal data we should not free them.
 223      * Anyway they are over the limit of OPAL_DATATYPE_MAX_PREDEFINED so they will never get freed.
 224      */
 225 
 226     /* As they are statically allocated they cannot be released. But we
 227      * can call OBJ_DESTRUCT, just to free all internally allocated ressources.
 228      */
 229     /* clear all master convertors */
 230     opal_convertor_destroy_masters();
 231 
 232     opal_output_close (opal_datatype_dfd);
 233     opal_datatype_dfd = -1;
 234 }
 235 
 236 int32_t opal_datatype_init( void )
 237 {
 238     const opal_datatype_t* datatype;
 239     int32_t i;
 240 
 241     /**
 242      * Force he initialization of the opal_datatype_t class. This will allow us to
 243      * call OBJ_DESTRUCT without going too deep in the initialization process.
 244      */
 245     opal_class_initialize(OBJ_CLASS(opal_datatype_t));
 246     for( i = OPAL_DATATYPE_FIRST_TYPE; i < OPAL_DATATYPE_MAX_PREDEFINED; i++ ) {
 247         datatype = opal_datatype_basicDatatypes[i];
 248 
 249         /* All of the predefined OPAL types don't have any GAPS! */
 250         datatype->desc.desc[0].elem.common.flags = OPAL_DATATYPE_FLAG_PREDEFINED |
 251                                                    OPAL_DATATYPE_FLAG_DATA |
 252                                                    OPAL_DATATYPE_FLAG_CONTIGUOUS |
 253                                                    OPAL_DATATYPE_FLAG_NO_GAPS;
 254         datatype->desc.desc[0].elem.common.type  = i;
 255         /* datatype->desc.desc[0].elem.blocklen XXX not set at the moment, it will be needed later */
 256         datatype->desc.desc[0].elem.count        = 1;
 257         datatype->desc.desc[0].elem.disp         = 0;
 258         datatype->desc.desc[0].elem.extent       = datatype->size;
 259 
 260         datatype->desc.desc[1].end_loop.common.flags    = 0;
 261         datatype->desc.desc[1].end_loop.common.type     = OPAL_DATATYPE_END_LOOP;
 262         datatype->desc.desc[1].end_loop.items           = 1;
 263         datatype->desc.desc[1].end_loop.first_elem_disp = datatype->desc.desc[0].elem.disp;
 264         datatype->desc.desc[1].end_loop.size            = datatype->size;
 265     }
 266 
 267     /* Enable a private output stream for datatype */
 268     if( opal_ddt_verbose > 0 ) {
 269         opal_datatype_dfd = opal_output_open(NULL);
 270         opal_output_set_verbosity(opal_datatype_dfd, opal_ddt_verbose);
 271     }
 272 
 273     opal_finalize_register_cleanup (opal_datatype_finalize);
 274 
 275     return OPAL_SUCCESS;
 276 }
 277 
 278 #if OPAL_ENABLE_DEBUG
 279 /*
 280  * Set a breakpoint to this function in your favorite debugger
 281  * to make it stop on all pack and unpack errors.
 282  */
 283 int opal_datatype_safeguard_pointer_debug_breakpoint( const void* actual_ptr, int length,
 284                                                       const void* initial_ptr,
 285                                                       const opal_datatype_t* pData,
 286                                                       int count )
 287 {
 288     return 0;
 289 }
 290 #endif  /* OPAL_ENABLE_DEBUG */

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