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

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

## Static Public Member Functions

static platform_topology & | instance ()

## Private Types

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

## Private Member Functions

bool | intergroup_binding_allowed (size_t groups_num)
| platform_topology ()

## Private Attributes

hwloc_topology_t | topology
hwloc_cpuset_t | process_cpu_affinity_mask
hwloc_nodeset_t | process_node_affinity_mask
std::vector< hwloc_cpuset_t > | affinity_masks_list
std::vector< int > | default_concurrency_list
std::vector< int > | numa_indexes_list
int | numa_nodes_count
enum tbb::internal::platform_topology::init_stages | initialization_state

## 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 74 of file tbb_bind.cpp.

## const_affinity_mask

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

Definition at line 75 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 55 of file tbb_bind.cpp.

{ uninitialized,
started,
topology_allocated,
topology_loaded,
topology_parsed } initialization_state;
tbb::internal::platform_topology::initialization_state
enum tbb::internal::platform_topology::init_stages initialization_state
tbb::internal::platform_topology::uninitialized
@ uninitialized
Definition: tbb_bind.cpp:55
tbb::internal::platform_topology::topology_parsed
@ topology_parsed
Definition: tbb_bind.cpp:59
tbb::internal::platform_topology::topology_loaded
@ topology_loaded
Definition: tbb_bind.cpp:58
tbb::internal::platform_topology::started
@ started
Definition: tbb_bind.cpp:56
tbb::internal::platform_topology::topology_allocated
@ topology_allocated
Definition: tbb_bind.cpp:57

## Constructor & Destructor Documentation

## platform_topology()

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

inline private

Definition at line 67 of file tbb_bind.cpp.

: topology(NULL),
process_cpu_affinity_mask(NULL),
process_node_affinity_mask(NULL),
numa_nodes_count(0),
initialization_state(uninitialized) {}
tbb::internal::platform_topology::process_cpu_affinity_mask
hwloc_cpuset_t process_cpu_affinity_mask
Definition: tbb_bind.cpp:47
tbb::internal::platform_topology::topology
hwloc_topology_t topology
Definition: tbb_bind.cpp:46
tbb::internal::platform_topology::numa_nodes_count
int numa_nodes_count
Definition: tbb_bind.cpp:53
tbb::internal::platform_topology::process_node_affinity_mask
hwloc_nodeset_t process_node_affinity_mask
Definition: tbb_bind.cpp:48

## ~platform_topology()

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

inline

Definition at line 174 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;
}
tbb::internal::platform_topology::affinity_masks_list
std::vector< hwloc_cpuset_t > affinity_masks_list
Definition: tbb_bind.cpp:49
tbb::internal::platform_topology::is_topology_parsed
bool is_topology_parsed()
Definition: tbb_bind.cpp:82
tbb::internal::platform_topology::numa_indexes_list
std::vector< int > numa_indexes_list
Definition: tbb_bind.cpp:52

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()

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

inline

Definition at line 197 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);
}
__TBB_ASSERT
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:165

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()

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

inline

Definition at line 190 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();
}
tbb::internal::platform_topology::default_concurrency_list
std::vector< int > default_concurrency_list
Definition: tbb_bind.cpp:51

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()

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

inline

Definition at line 202 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()

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

inline

Definition at line 218 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.

## initialize()

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

inline

Definition at line 84 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;
}
assertion_hwloc_wrapper
#define assertion_hwloc_wrapper(command,...)
Definition: tbb_bind.cpp:33
tbb::internal::platform_topology::intergroup_binding_allowed
bool intergroup_binding_allowed(size_t groups_num)
Definition: tbb_bind.cpp:65

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:

## instance()

static platform_topology& tbb::internal::platform_topology::instance | ( |  | ) |

inline static

Definition at line 77 of file tbb_bind.cpp.

{
static platform_topology topology;
return topology;
}
tbb::internal::platform_topology::platform_topology
platform_topology()
Definition: tbb_bind.cpp:67

References topology.

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

Here is the caller graph for this function:

## intergroup_binding_allowed()

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

inline private

Definition at line 65 of file tbb_bind.cpp.

{ return groups_num > 1; }

Referenced by initialize().

Here is the caller graph for this function:

## is_topology_parsed()

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

inline

Definition at line 82 of file tbb_bind.cpp.

{ return initialization_state == topology_parsed; }

References initialization_state, and topology_parsed.

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

Here is the caller graph for this function:

## set_new_affinity_mask()

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

inline

Definition at line 214 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()

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

inline

Definition at line 206 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

private

Definition at line 49 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

private

Definition at line 51 of file tbb_bind.cpp.

Referenced by fill(), and initialize().

## initialization_state

enum tbb::internal::platform_topology::init_stages tbb::internal::platform_topology::initialization_state

private

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

## numa_indexes_list

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

private

Definition at line 52 of file tbb_bind.cpp.

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

## numa_nodes_count

int tbb::internal::platform_topology::numa_nodes_count

private

Definition at line 53 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

private

Definition at line 47 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

private

Definition at line 48 of file tbb_bind.cpp.

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

## topology

hwloc_topology_t tbb::internal::platform_topology::topology

private

Definition at line 46 of file tbb_bind.cpp.

Referenced by initialize(), instance(), 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

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.