tbb::internal::platform_topology Class Reference
Collaboration diagram for tbb::internal::platform_topology:

## Public Types

typedef hwloc_cpuset_t | affinity_mask
typedef hwloc_const_cpuset_t | const_affinity_mask

## Public Member Functions

| ~platform_topology ()

## Static Public Member Functions

static bool | is_topology_parsed ()
static void | initialize (size_t groups_num)
static void | fill (int &nodes_count, int *&indexes_list, int *&concurrency_list)
static affinity_mask | allocate_process_affinity_mask ()
static void | free_affinity_mask (affinity_mask mask_to_free)
static void | store_current_affinity_mask (affinity_mask current_mask)
static void | set_new_affinity_mask (const_affinity_mask new_mask)
static const_affinity_mask | get_node_affinity_mask (int node_index)

## Private Types

enum | init_stages { uninitialized, started, topology_allocated, topology_loaded, topology_parsed }

## Static Private Member Functions

static bool | intergroup_binding_allowed (size_t groups_num)

## Static Private Attributes

static hwloc_topology_t | topology = NULL
static hwloc_cpuset_t | process_cpu_affinity_mask = NULL
static hwloc_nodeset_t | process_node_affinity_mask = NULL
static std::vector< hwloc_cpuset_t > | affinity_masks_list
static std::vector< int > | default_concurrency_list
static std::vector< int > | numa_indexes_list
static int | numa_nodes_count = 0
static init_stages | initialization_state = uninitialized

## Friends

class | numa_affinity_handler

## Detailed Description

Definition at line 42 of file tbb_bind.cpp.

## Member Typedef Documentation

## affinity_mask

typedef hwloc_cpuset_t tbb::internal::platform_topology::affinity_mask

Definition at line 64 of file tbb_bind.cpp.

## const_affinity_mask

typedef hwloc_const_cpuset_t tbb::internal::platform_topology::const_affinity_mask

Definition at line 65 of file tbb_bind.cpp.

## Member Enumeration Documentation

## init_stages

enum tbb::internal::platform_topology::init_stages

private

Enumerator
uninitialized |
started |
topology_allocated |
topology_loaded |
topology_parsed |

Definition at line 54 of file tbb_bind.cpp.

{ uninitialized, started, topology_allocated, topology_loaded, topology_parsed };

## Constructor & Destructor Documentation

## ~platform_topology()

tbb::internal::platform_topology::~platform_topology | ( |  | ) |

inline

Definition at line 159 of file tbb_bind.cpp.

{
if ( is_topology_parsed() ) {
for (int i = 0; i < numa_nodes_count; i++) {
hwloc_bitmap_free(affinity_masks_list[numa_indexes_list[i]]);
}
hwloc_bitmap_free(process_node_affinity_mask);
hwloc_bitmap_free(process_cpu_affinity_mask);
}
if ( initialization_state >= topology_allocated ) {
hwloc_topology_destroy(topology);
}
initialization_state = uninitialized;
}

References affinity_masks_list, initialization_state, is_topology_parsed(), numa_indexes_list, numa_nodes_count, process_cpu_affinity_mask, process_node_affinity_mask, topology, topology_allocated, and uninitialized.

Here is the call graph for this function:

## Member Function Documentation

## allocate_process_affinity_mask()

static affinity_mask tbb::internal::platform_topology::allocate_process_affinity_mask | ( |  | ) |

inline static

Definition at line 182 of file tbb_bind.cpp.

{
__TBB_ASSERT(is_topology_parsed(), "Trying to get access to uninitialized platform_topology");
return hwloc_bitmap_dup(process_cpu_affinity_mask);
}

References __TBB_ASSERT, is_topology_parsed(), and process_cpu_affinity_mask.

Referenced by tbb::internal::binding_handler::binding_handler().

Here is the call graph for this function:
Here is the caller graph for this function:

## fill()

static void tbb::internal::platform_topology::fill | ( | int & | nodes_count,
|  | int *& | indexes_list,
|  | int *& | concurrency_list
| ) |  |

inline static

Definition at line 175 of file tbb_bind.cpp.

{
__TBB_ASSERT(is_topology_parsed(), "Trying to get access to uninitialized platform_topology");
nodes_count = numa_nodes_count;
indexes_list = &numa_indexes_list.front();
concurrency_list = &default_concurrency_list.front();
}

References __TBB_ASSERT, default_concurrency_list, is_topology_parsed(), numa_indexes_list, and numa_nodes_count.

Referenced by tbb::internal::initialize_numa_topology().

Here is the call graph for this function:
Here is the caller graph for this function:

## free_affinity_mask()

static void tbb::internal::platform_topology::free_affinity_mask | ( | affinity_mask | mask_to_free | ) |

inline static

Definition at line 187 of file tbb_bind.cpp.

{
hwloc_bitmap_free(mask_to_free); // If bitmap is NULL, no operation is performed.
}

Referenced by tbb::internal::binding_handler::~binding_handler().

Here is the caller graph for this function:

## get_node_affinity_mask()

static const_affinity_mask tbb::internal::platform_topology::get_node_affinity_mask | ( | int | node_index | ) |

inline static

Definition at line 203 of file tbb_bind.cpp.

{
__TBB_ASSERT((int)affinity_masks_list.size() > node_index,
"Trying to get affinity mask for uninitialized NUMA node");
return affinity_masks_list[node_index];
}

References __TBB_ASSERT, and affinity_masks_list.

Referenced by tbb::internal::binding_handler::bind_thread_to_node().

Here is the caller graph for this function:

## initialize()

static void tbb::internal::platform_topology::initialize | ( | size_t | groups_num | ) |

inline static

Definition at line 69 of file tbb_bind.cpp.

{
if ( initialization_state != uninitialized )
return;
initialization_state = started;
// Parse topology
if ( hwloc_topology_init( &topology ) == 0 ) {
initialization_state = topology_allocated;
if ( hwloc_topology_load( topology ) == 0 ) {
initialization_state = topology_loaded;
}
}
// Fill parameters with stubs if topology parsing is broken.
if ( initialization_state != topology_loaded ) {
if ( initialization_state == topology_allocated ) {
hwloc_topology_destroy(topology);
}
numa_nodes_count = 1;
numa_indexes_list.push_back(-1);
default_concurrency_list.push_back(-1);
return;
}
// Getting process affinity mask
if ( intergroup_binding_allowed(groups_num) ) {
process_cpu_affinity_mask = hwloc_bitmap_dup(hwloc_topology_get_complete_cpuset (topology));
process_node_affinity_mask = hwloc_bitmap_dup(hwloc_topology_get_complete_nodeset(topology));
} else {
process_cpu_affinity_mask = hwloc_bitmap_alloc();
process_node_affinity_mask = hwloc_bitmap_alloc();
assertion_hwloc_wrapper(hwloc_get_cpubind, topology, process_cpu_affinity_mask, 0);
hwloc_cpuset_to_nodeset(topology, process_cpu_affinity_mask, process_node_affinity_mask);
}
// If system contains no NUMA nodes, HWLOC 1.11 returns an infinitely filled bitmap.
// hwloc_bitmap_weight() returns negative value for such bitmaps, so we use this check
// to change way of topology initialization.
if (hwloc_bitmap_weight(process_node_affinity_mask) < 0) {
numa_nodes_count = 1;
numa_indexes_list.push_back(0);
default_concurrency_list.push_back(hwloc_bitmap_weight(process_cpu_affinity_mask));
affinity_masks_list.push_back(hwloc_bitmap_dup(process_cpu_affinity_mask));
initialization_state = topology_parsed;
return;
}
// Get number of available NUMA nodes
numa_nodes_count = hwloc_bitmap_weight(process_node_affinity_mask);
__TBB_ASSERT(numa_nodes_count > 0, "Any system must contain one or more NUMA nodes");
// Get NUMA logical indexes list
unsigned counter = 0;
int i = 0;
int max_numa_index = -1;
numa_indexes_list.resize(numa_nodes_count);
hwloc_obj_t node_buffer;
hwloc_bitmap_foreach_begin(i, process_node_affinity_mask) {
node_buffer = hwloc_get_obj_by_type(topology, HWLOC_OBJ_NUMANODE, i);
numa_indexes_list[counter] = static_cast<int>(node_buffer->logical_index);
if ( numa_indexes_list[counter] > max_numa_index ) {
max_numa_index = numa_indexes_list[counter];
}
counter++;
} hwloc_bitmap_foreach_end();
__TBB_ASSERT(max_numa_index >= 0, "Maximal NUMA index must not be negative");
// Fill concurrency and affinity masks lists
default_concurrency_list.resize(max_numa_index + 1);
affinity_masks_list.resize(max_numa_index + 1);
int index = 0;
hwloc_bitmap_foreach_begin(i, process_node_affinity_mask) {
node_buffer = hwloc_get_obj_by_type(topology, HWLOC_OBJ_NUMANODE, i);
index = static_cast<int>(node_buffer->logical_index);
hwloc_cpuset_t& current_mask = affinity_masks_list[index];
current_mask = hwloc_bitmap_dup(node_buffer->cpuset);
hwloc_bitmap_and(current_mask, current_mask, process_cpu_affinity_mask);
__TBB_ASSERT(!hwloc_bitmap_iszero(current_mask), "hwloc detected unavailable NUMA node");
default_concurrency_list[index] = hwloc_bitmap_weight(current_mask);
} hwloc_bitmap_foreach_end();
initialization_state = topology_parsed;
}

References __TBB_ASSERT, affinity_masks_list, assertion_hwloc_wrapper, default_concurrency_list, initialization_state, intergroup_binding_allowed(), numa_indexes_list, numa_nodes_count, process_cpu_affinity_mask, process_node_affinity_mask, started, topology, topology_allocated, topology_loaded, topology_parsed, and uninitialized.

Referenced by tbb::internal::initialize_numa_topology().

Here is the call graph for this function:
Here is the caller graph for this function:

## intergroup_binding_allowed()

static bool tbb::internal::platform_topology::intergroup_binding_allowed | ( | size_t | groups_num | ) |

inline static private

Definition at line 61 of file tbb_bind.cpp.

{ return groups_num > 1; }

Referenced by initialize().

Here is the caller graph for this function:

## is_topology_parsed()

static bool tbb::internal::platform_topology::is_topology_parsed | ( |  | ) |

inline static

Definition at line 67 of file tbb_bind.cpp.

{ return initialization_state == topology_parsed; }

References initialization_state, and topology_parsed.

Referenced by allocate_process_affinity_mask(), tbb::internal::binding_handler::bind_thread_to_node(), tbb::internal::bind_to_node(), fill(), tbb::internal::restore_affinity(), tbb::internal::binding_handler::restore_previous_affinity_mask(), and ~platform_topology().

Here is the caller graph for this function:

## set_new_affinity_mask()

static void tbb::internal::platform_topology::set_new_affinity_mask | ( | const_affinity_mask | new_mask | ) |

inline static

Definition at line 199 of file tbb_bind.cpp.

{
assertion_hwloc_wrapper(hwloc_set_cpubind, topology, new_mask, HWLOC_CPUBIND_THREAD);
}

References assertion_hwloc_wrapper, and topology.

Referenced by tbb::internal::binding_handler::bind_thread_to_node(), and tbb::internal::binding_handler::restore_previous_affinity_mask().

Here is the caller graph for this function:

## store_current_affinity_mask()

static void tbb::internal::platform_topology::store_current_affinity_mask | ( | affinity_mask | current_mask | ) |

inline static

Definition at line 191 of file tbb_bind.cpp.

{
assertion_hwloc_wrapper(hwloc_get_cpubind, topology, current_mask, HWLOC_CPUBIND_THREAD);
hwloc_bitmap_and(current_mask, current_mask, process_cpu_affinity_mask);
__TBB_ASSERT(!hwloc_bitmap_iszero(current_mask),
"Current affinity mask must intersects with process affinity mask");
}

References __TBB_ASSERT, assertion_hwloc_wrapper, process_cpu_affinity_mask, and topology.

Referenced by tbb::internal::binding_handler::bind_thread_to_node().

Here is the caller graph for this function:

## Friends And Related Function Documentation

## numa_affinity_handler

friend class numa_affinity_handler

friend

Definition at line 43 of file tbb_bind.cpp.

## Member Data Documentation

## affinity_masks_list

std::vector< hwloc_cpuset_t > tbb::internal::platform_topology::affinity_masks_list

static private

Definition at line 48 of file tbb_bind.cpp.

Referenced by get_node_affinity_mask(), initialize(), and ~platform_topology().

## default_concurrency_list

std::vector< int > tbb::internal::platform_topology::default_concurrency_list

static private

Definition at line 50 of file tbb_bind.cpp.

Referenced by fill(), and initialize().

## initialization_state

platform_topology::init_stages tbb::internal::platform_topology::initialization_state = uninitialized

static private

Definition at line 55 of file tbb_bind.cpp.

Referenced by initialize(), is_topology_parsed(), and ~platform_topology().

## numa_indexes_list

std::vector< int > tbb::internal::platform_topology::numa_indexes_list

static private

Definition at line 51 of file tbb_bind.cpp.

Referenced by fill(), initialize(), and ~platform_topology().

## numa_nodes_count

int tbb::internal::platform_topology::numa_nodes_count = 0

static private

Definition at line 52 of file tbb_bind.cpp.

Referenced by fill(), initialize(), and ~platform_topology().

## process_cpu_affinity_mask

hwloc_cpuset_t tbb::internal::platform_topology::process_cpu_affinity_mask = NULL

static private

Definition at line 46 of file tbb_bind.cpp.

Referenced by allocate_process_affinity_mask(), initialize(), store_current_affinity_mask(), and ~platform_topology().

## process_node_affinity_mask

hwloc_nodeset_t tbb::internal::platform_topology::process_node_affinity_mask = NULL

static private

Definition at line 47 of file tbb_bind.cpp.

Referenced by initialize(), and ~platform_topology().

## topology

hwloc_topology_t tbb::internal::platform_topology::topology = NULL

static private

Definition at line 45 of file tbb_bind.cpp.

Referenced by initialize(), set_new_affinity_mask(), store_current_affinity_mask(), and ~platform_topology().

The documentation for this class was generated from the following file:

- tbb_bind.cpp

tbb::internal::platform_topology::topology_loaded
Definition: tbb_bind.cpp:54
tbb::internal::platform_topology::numa_nodes_count
static int numa_nodes_count
Definition: tbb_bind.cpp:52
__TBB_ASSERT
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:165
tbb::internal::platform_topology::initialization_state
static init_stages initialization_state
Definition: tbb_bind.cpp:55
tbb::internal::platform_topology::process_node_affinity_mask
static hwloc_nodeset_t process_node_affinity_mask
Definition: tbb_bind.cpp:47
tbb::internal::platform_topology::topology_parsed
Definition: tbb_bind.cpp:54
assertion_hwloc_wrapper
#define assertion_hwloc_wrapper(command,...)
Definition: tbb_bind.cpp:33
tbb::internal::platform_topology::uninitialized
Definition: tbb_bind.cpp:54
tbb::internal::platform_topology::started
Definition: tbb_bind.cpp:54
tbb::internal::platform_topology::process_cpu_affinity_mask
static hwloc_cpuset_t process_cpu_affinity_mask
Definition: tbb_bind.cpp:46
tbb::internal::platform_topology::numa_indexes_list
static std::vector< int > numa_indexes_list
Definition: tbb_bind.cpp:51
tbb::internal::platform_topology::topology
static hwloc_topology_t topology
Definition: tbb_bind.cpp:45
tbb::internal::platform_topology::intergroup_binding_allowed
static bool intergroup_binding_allowed(size_t groups_num)
Definition: tbb_bind.cpp:61
tbb::internal::platform_topology::topology_allocated
Definition: tbb_bind.cpp:54
tbb::internal::platform_topology::is_topology_parsed
static bool is_topology_parsed()
Definition: tbb_bind.cpp:67
tbb::internal::platform_topology::default_concurrency_list
static std::vector< int > default_concurrency_list
Definition: tbb_bind.cpp:50
tbb::internal::platform_topology::affinity_masks_list
static std::vector< hwloc_cpuset_t > affinity_masks_list
Definition: tbb_bind.cpp:48

Copyright © 2005-2020 Intel Corporation. All Rights Reserved.

Intel, Pentium, Intel Xeon, Itanium, Intel XScale and VTune are registered trademarks or trademarks of Intel Corporation or its subsidiaries in the United States and other countries.

* Other names and brands may be claimed as the property of others.