root/opal/mca/hwloc/hwloc-internal.h

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

INCLUDED FROM


   1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
   2 /*
   3  * Copyright (c) 2011-2012 Cisco Systems, Inc.  All rights reserved.
   4  * Copyright (c) 2013-2018 Intel, Inc. All rights reserved.
   5  * Copyright (c) 2015      Los Alamos National Security, LLC. All rights
   6  *                         reserved.
   7  *
   8  * $COPYRIGHT$
   9  *
  10  * Additional copyrights may follow
  11  */
  12 
  13 #ifndef OPAL_MCA_HWLOC_H
  14 #define OPAL_MCA_HWLOC_H
  15 
  16 #include "opal_config.h"
  17 
  18 #ifdef HAVE_SYS_TYPES_H
  19 #include <sys/types.h>
  20 #endif
  21 #ifdef HAVE_SYS_TIME_H
  22 #include <sys/time.h>
  23 #endif
  24 #include <stdint.h>
  25 #include <stdarg.h>
  26 
  27 #include "opal/class/opal_list.h"
  28 #include "opal/class/opal_value_array.h"
  29 
  30 #include "opal/mca/mca.h"
  31 #include "opal/mca/base/base.h"
  32 
  33 BEGIN_C_DECLS
  34 
  35 #ifdef WIN32
  36 #define WIN32_LEAN_AND_MEAN
  37 #include <windows.h>
  38 #undef WIN32_LEAN_AND_MEAN
  39 typedef unsigned char u_char;
  40 typedef unsigned short u_short;
  41 #endif
  42 
  43 /**
  44  * Structure for hwloc components.
  45  */
  46 struct opal_hwloc_base_component_2_0_0_t {
  47     /** MCA base component */
  48     mca_base_component_t base_version;
  49     /** MCA base data */
  50     mca_base_component_data_t base_data;
  51 };
  52 
  53 /**
  54  * Convenience typedef
  55  */
  56 typedef struct opal_hwloc_base_component_2_0_0_t opal_hwloc_base_component_2_0_0_t;
  57 typedef struct opal_hwloc_base_component_2_0_0_t opal_hwloc_component_t;
  58 
  59 /**
  60  * Macro for use in components that are of type hwloc
  61  */
  62 #define OPAL_HWLOC_BASE_VERSION_2_0_0 \
  63     OPAL_MCA_BASE_VERSION_2_1_0("hwloc", 2, 0, 0)
  64 
  65 
  66 /* ******************************************************************** */
  67 /* Although we cannot bind if --without-hwloc is set,
  68  * we do still need to know some basic locality data
  69  * like on_node and not_on_node. So ensure that we
  70  * always have access to that much info by including
  71  * the definitions here, outside the if-have-hwloc test
  72  */
  73 typedef uint16_t opal_hwloc_locality_t;
  74 #define OPAL_HWLOC_LOCALITY_T OPAL_UINT16
  75 
  76 /** Process locality definitions */
  77 enum {
  78     OPAL_PROC_LOCALITY_UNKNOWN  = 0x0000,
  79     OPAL_PROC_NON_LOCAL         = 0x8000,
  80     OPAL_PROC_ON_CLUSTER        = 0x0001,
  81     OPAL_PROC_ON_CU             = 0x0002,
  82     OPAL_PROC_ON_HOST           = 0x0004,
  83     OPAL_PROC_ON_BOARD          = 0x0008,
  84     OPAL_PROC_ON_NODE           = 0x000c,   // same host and board
  85     OPAL_PROC_ON_NUMA           = 0x0010,
  86     OPAL_PROC_ON_SOCKET         = 0x0020,
  87     OPAL_PROC_ON_L3CACHE        = 0x0040,
  88     OPAL_PROC_ON_L2CACHE        = 0x0080,
  89     OPAL_PROC_ON_L1CACHE        = 0x0100,
  90     OPAL_PROC_ON_CORE           = 0x0200,
  91     OPAL_PROC_ON_HWTHREAD       = 0x0400,
  92     OPAL_PROC_ALL_LOCAL         = 0x0fff,
  93 };
  94 
  95 /** Process locality macros */
  96 #define OPAL_PROC_ON_LOCAL_CLUSTER(n)   (!!((n) & OPAL_PROC_ON_CLUSTER))
  97 #define OPAL_PROC_ON_LOCAL_CU(n)        (!!((n) & OPAL_PROC_ON_CU))
  98 #define OPAL_PROC_ON_LOCAL_HOST(n)      (!!((n) & OPAL_PROC_ON_HOST))
  99 #define OPAL_PROC_ON_LOCAL_BOARD(n)     (!!((n) & OPAL_PROC_ON_BOARD))
 100 #define OPAL_PROC_ON_LOCAL_NODE(n)      (OPAL_PROC_ON_LOCAL_HOST(n) && OPAL_PROC_ON_LOCAL_BOARD(n))
 101 #define OPAL_PROC_ON_LOCAL_NUMA(n)      (!!((n) & OPAL_PROC_ON_NUMA))
 102 #define OPAL_PROC_ON_LOCAL_SOCKET(n)    (!!((n) & OPAL_PROC_ON_SOCKET))
 103 #define OPAL_PROC_ON_LOCAL_L3CACHE(n)   (!!((n) & OPAL_PROC_ON_L3CACHE))
 104 #define OPAL_PROC_ON_LOCAL_L2CACHE(n)   (!!((n) & OPAL_PROC_ON_L2CACHE))
 105 #define OPAL_PROC_ON_LOCAL_L1CACHE(n)   (!!((n) & OPAL_PROC_ON_L1CACHE))
 106 #define OPAL_PROC_ON_LOCAL_CORE(n)      (!!((n) & OPAL_PROC_ON_CORE))
 107 #define OPAL_PROC_ON_LOCAL_HWTHREAD(n)  (!!((n) & OPAL_PROC_ON_HWTHREAD))
 108 
 109 /* ******************************************************************** */
 110 
 111 /**
 112  * Struct used to describe a section of memory (starting address
 113  * and length). This is really the same thing as an iovec, but
 114  * we include a separate type for it for at least 2 reasons:
 115  *
 116  * 1. Some OS's iovec definitions are exceedingly lame (e.g.,
 117  * Solaris 9 has the length argument as an int, instead of a
 118  * size_t).
 119  *
 120  * 2. We reserve the right to expand/change this struct in the
 121  * future.
 122  */
 123 typedef struct {
 124     /** Starting address of segment */
 125     void *mbs_start_addr;
 126     /** Length of segment */
 127     size_t mbs_len;
 128 } opal_hwloc_base_memory_segment_t;
 129 
 130 /* include implementation to call */
 131 #include MCA_hwloc_IMPLEMENTATION_HEADER
 132 
 133 /* define type of processor info requested */
 134 typedef uint8_t opal_hwloc_resource_type_t;
 135 #define OPAL_HWLOC_PHYSICAL   1
 136 #define OPAL_HWLOC_LOGICAL    2
 137 #define OPAL_HWLOC_AVAILABLE  3
 138 
 139 /* structs for storing info on objects */
 140 typedef struct {
 141     opal_object_t super;
 142     bool npus_calculated;
 143     unsigned int npus;
 144     unsigned int idx;
 145     unsigned int num_bound;
 146 } opal_hwloc_obj_data_t;
 147 OBJ_CLASS_DECLARATION(opal_hwloc_obj_data_t);
 148 
 149 typedef struct {
 150     opal_list_item_t super;
 151     hwloc_obj_type_t type;
 152     unsigned cache_level;
 153     unsigned int num_objs;
 154     opal_hwloc_resource_type_t rtype;
 155     opal_list_t sorted_by_dist_list;
 156 } opal_hwloc_summary_t;
 157 OBJ_CLASS_DECLARATION(opal_hwloc_summary_t);
 158 
 159 typedef struct {
 160     opal_object_t super;
 161     hwloc_cpuset_t available;
 162     opal_list_t summaries;
 163 
 164     /** \brief Additional space for custom data */
 165     void *userdata;
 166 } opal_hwloc_topo_data_t;
 167 OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_hwloc_topo_data_t);
 168 
 169 /* define binding policies */
 170 typedef uint16_t opal_binding_policy_t;
 171 #define OPAL_BINDING_POLICY OPAL_UINT16
 172 
 173 /* binding directives */
 174 #define OPAL_BIND_IF_SUPPORTED      0x1000
 175 /* allow assignment of multiple procs to
 176  * same cpu */
 177 #define OPAL_BIND_ALLOW_OVERLOAD    0x2000
 178 /* the binding policy was specified by the user */
 179 #define OPAL_BIND_GIVEN             0x4000
 180 /* bind each rank to the cpu in the given
 181  * cpu list based on its node-local-rank */
 182 #define OPAL_BIND_ORDERED           0x8000
 183 
 184 /* binding policies - any changes in these
 185  * values must be reflected in orte/mca/rmaps/rmaps.h
 186  */
 187 #define OPAL_BIND_TO_NONE           1
 188 #define OPAL_BIND_TO_BOARD          2
 189 #define OPAL_BIND_TO_NUMA           3
 190 #define OPAL_BIND_TO_SOCKET         4
 191 #define OPAL_BIND_TO_L3CACHE        5
 192 #define OPAL_BIND_TO_L2CACHE        6
 193 #define OPAL_BIND_TO_L1CACHE        7
 194 #define OPAL_BIND_TO_CORE           8
 195 #define OPAL_BIND_TO_HWTHREAD       9
 196 #define OPAL_BIND_TO_CPUSET         10
 197 #define OPAL_GET_BINDING_POLICY(pol) \
 198     ((pol) & 0x0fff)
 199 #define OPAL_SET_BINDING_POLICY(target, pol) \
 200     (target) = (pol) | (((target) & 0xf000) | OPAL_BIND_GIVEN)
 201 #define OPAL_SET_DEFAULT_BINDING_POLICY(target, pol)            \
 202     do {                                                        \
 203         if (!OPAL_BINDING_POLICY_IS_SET((target))) {            \
 204             (target) = (pol) | (((target) & 0xf000) |           \
 205                                 OPAL_BIND_IF_SUPPORTED);        \
 206         }                                                       \
 207     } while(0);
 208 
 209 /* check if policy is set */
 210 #define OPAL_BINDING_POLICY_IS_SET(pol) \
 211     ((pol) & 0x4000)
 212 /* macro to detect if binding was qualified */
 213 #define OPAL_BINDING_REQUIRED(n) \
 214     (!(OPAL_BIND_IF_SUPPORTED & (n)))
 215 /* macro to detect if binding is forced */
 216 #define OPAL_BIND_OVERLOAD_ALLOWED(n) \
 217     (OPAL_BIND_ALLOW_OVERLOAD & (n))
 218 #define OPAL_BIND_ORDERED_REQUESTED(n) \
 219     (OPAL_BIND_ORDERED & (n))
 220 
 221 /* some global values */
 222 OPAL_DECLSPEC extern hwloc_topology_t opal_hwloc_topology;
 223 OPAL_DECLSPEC extern opal_binding_policy_t opal_hwloc_binding_policy;
 224 OPAL_DECLSPEC extern hwloc_cpuset_t opal_hwloc_my_cpuset;
 225 OPAL_DECLSPEC extern bool opal_hwloc_report_bindings;
 226 OPAL_DECLSPEC extern hwloc_obj_type_t opal_hwloc_levels[];
 227 OPAL_DECLSPEC extern bool opal_hwloc_use_hwthreads_as_cpus;
 228 
 229 END_C_DECLS
 230 
 231 #endif /* OPAL_HWLOC_H_ */

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