hpx/topology/topology.hpp#

Defined in header hpx/topology/topology.hpp.

See Public API for a list of names and headers that are part of the public HPX API.

namespace hpx
namespace threads

Typedefs

using hwloc_bitmap_ptr = std::shared_ptr<hpx_hwloc_bitmap_wrapper>#

Enums

enum hpx_hwloc_membind_policy#

Please see hwloc documentation for the corresponding enums HWLOC_MEMBIND_XXX.

Values:

enumerator membind_default#
enumerator membind_firsttouch#
enumerator membind_bind#
enumerator membind_interleave#
enumerator membind_replicate#
enumerator membind_nexttouch#
enumerator membind_mixed#
enumerator membind_user#

Functions

topology &create_topology()#
inline std::size_t get_memory_page_size()#
struct hpx_hwloc_bitmap_wrapper#

Public Functions

HPX_NON_COPYABLE(hpx_hwloc_bitmap_wrapper)#
inline hpx_hwloc_bitmap_wrapper() noexcept#
inline explicit hpx_hwloc_bitmap_wrapper(void *bmp) noexcept#
inline ~hpx_hwloc_bitmap_wrapper()#
inline void reset(hwloc_bitmap_t bmp) noexcept#
inline explicit constexpr operator bool() const noexcept#
inline hwloc_bitmap_t get_bmp() const noexcept#

Private Members

hwloc_bitmap_t bmp_#

Friends

friend std::ostream &operator<<(std::ostream &os, hpx_hwloc_bitmap_wrapper const *bmp)#
struct topology#

Public Functions

topology()#
topology(topology const&) = delete#
topology(topology&&) = delete#
topology &operator=(topology const&) = delete#
topology &operator=(topology&&) = delete#
~topology()#
inline std::size_t get_socket_number(std::size_t num_thread, [[maybe_unused]] error_code &ec = throws) const noexcept#

Return the Socket number of the processing unit the given thread is running on.

Parameters
  • num_thread – [in]

  • ec – [in,out] this represents the error status on exit, if this is pre-initialized to hpx::throws the function will throw on error instead.

inline std::size_t get_numa_node_number(std::size_t num_thread, [[maybe_unused]] error_code &ec = throws) const noexcept#

Return the NUMA node number of the processing unit the given thread is running on.

Parameters
  • num_thread – [in]

  • ec – [in,out] this represents the error status on exit, if this is pre-initialized to hpx::throws the function will throw on error instead.

mask_cref_type get_machine_affinity_mask(error_code &ec = throws) const noexcept#

Return a bit mask where each set bit corresponds to a processing unit available to the application.

Parameters

ec – [in,out] this represents the error status on exit, if this is pre-initialized to hpx::throws the function will throw on error instead.

mask_type get_service_affinity_mask(mask_cref_type used_processing_units, error_code &ec = throws) const#

Return a bit mask where each set bit corresponds to a processing unit available to the service threads in the application.

Parameters
  • used_processing_units – [in] This is the mask of processing units which are not available for service threads.

  • ec – [in,out] this represents the error status on exit, if this is pre-initialized to hpx::throws the function will throw on error instead.

mask_cref_type get_socket_affinity_mask(std::size_t num_thread, error_code &ec = throws) const#

Return a bit mask where each set bit corresponds to a processing unit available to the given thread inside the socket it is running on.

Parameters
  • num_thread – [in]

  • ec – [in,out] this represents the error status on exit, if this is pre-initialized to hpx::throws the function will throw on error instead.

mask_cref_type get_numa_node_affinity_mask(std::size_t num_thread, error_code &ec = throws) const#

Return a bit mask where each set bit corresponds to a processing unit available to the given thread inside the NUMA domain it is running on.

Parameters
  • num_thread – [in]

  • ec – [in,out] this represents the error status on exit, if this is pre-initialized to hpx::throws the function will throw on error instead.

mask_cref_type get_core_affinity_mask(std::size_t num_thread, error_code &ec = throws) const#

Return a bit mask where each set bit corresponds to a processing unit available to the given thread inside the core it is running on.

Parameters
  • num_thread – [in]

  • ec – [in,out] this represents the error status on exit, if this is pre-initialized to hpx::throws the function will throw on error instead.

mask_cref_type get_thread_affinity_mask(std::size_t num_thread, error_code &ec = throws) const#

Return a bit mask where each set bit corresponds to a processing unit available to the given thread.

Parameters
  • num_thread – [in]

  • ec – [in,out] this represents the error status on exit, if this is pre-initialized to hpx::throws the function will throw on error instead.

void set_thread_affinity_mask(mask_cref_type mask, error_code &ec = throws) const#

Use the given bit mask to set the affinity of the given thread. Each set bit corresponds to a processing unit the thread will be allowed to run on.

Note

Use this function on systems where the affinity must be set from inside the thread itself.

Parameters
  • mask – [in]

  • ec – [in,out] this represents the error status on exit, if this is pre-initialized to hpx::throws the function will throw on error instead.

mask_type get_thread_affinity_mask_from_lva(void const *lva, error_code &ec = throws) const#

Return a bit mask where each set bit corresponds to a processing unit co-located with the memory the given address is currently allocated on.

Parameters
  • lva – [in]

  • ec – [in,out] this represents the error status on exit, if this is pre-initialized to hpx::throws the function will throw on error instead.

void print_affinity_mask(std::ostream &os, std::size_t num_thread, mask_cref_type m, std::string const &pool_name) const#

Prints the given mask m to os in a human readable form.

bool reduce_thread_priority(error_code &ec = throws) const#

Reduce thread priority of the current thread.

Parameters

ec – [in,out] this represents the error status on exit, if this is pre-initialized to hpx::throws the function will throw on error instead.

std::size_t get_number_of_sockets() const#

Return the number of available NUMA domains.

std::size_t get_number_of_numa_nodes() const#

Return the number of available NUMA domains.

std::size_t get_number_of_cores() const#

Return the number of available cores.

std::size_t get_number_of_pus() const noexcept#

Return the number of available hardware processing units.

std::size_t get_number_of_numa_node_cores(std::size_t numa) const#

Return number of cores in given numa domain.

std::size_t get_number_of_numa_node_pus(std::size_t numa) const#

Return number of processing units in a given numa domain.

std::size_t get_number_of_socket_pus(std::size_t socket) const#

Return number of processing units in a given socket.

std::size_t get_number_of_core_pus(std::size_t core) const#

Return number of processing units in given core.

std::size_t get_number_of_socket_cores(std::size_t socket) const#

Return number of cores units in given socket.

inline std::size_t get_core_number(std::size_t num_thread, error_code& = throws) const#
std::size_t get_pu_number(std::size_t num_core, std::size_t num_pu, error_code &ec = throws) const#
std::size_t get_cache_size(mask_cref_type mask, int level) const#

Return the size of the cache associated with the given mask.

mask_type get_cpubind_mask(error_code &ec = throws) const#
mask_type get_cpubind_mask(std::thread &handle, error_code &ec = throws) const#
hwloc_bitmap_ptr cpuset_to_nodeset(mask_cref_type mask) const#

convert a cpu mask into a numa node mask in hwloc bitmap form

void write_to_log() const#
void *allocate(std::size_t len) const#

This is equivalent to malloc(), except that it tries to allocate page-aligned memory from the OS.

void *allocate_membind(std::size_t len, const hwloc_bitmap_ptr &bitmap, hpx_hwloc_membind_policy policy, int flags) const#

allocate memory with binding to a numa node set as specified by the policy and flags (see hwloc docs)

threads::mask_type get_area_membind_nodeset(void const *addr, std::size_t len) const#
bool set_area_membind_nodeset(void const *addr, std::size_t len, void *nodeset) const#
int get_numa_domain(void const *addr) const#
void deallocate(void *addr, std::size_t len) const noexcept#

Free memory that was previously allocated by allocate.

void print_hwloc(std::ostream&) const#
mask_type init_socket_affinity_mask_from_socket(std::size_t num_socket) const#
mask_type init_numa_node_affinity_mask_from_numa_node(std::size_t num_numa_node) const#
mask_type init_core_affinity_mask_from_core(std::size_t num_core, mask_cref_type default_mask = empty_mask) const#
mask_type init_thread_affinity_mask(std::size_t num_thread) const#
mask_type init_thread_affinity_mask(std::size_t num_core, std::size_t num_pu) const#
hwloc_bitmap_t mask_to_bitmap(mask_cref_type mask, hwloc_obj_type_t htype) const#
mask_type bitmap_to_mask(hwloc_bitmap_t bitmap, hwloc_obj_type_t htype) const#

Public Static Functions

static void print_vector(std::ostream &os, std::vector<std::size_t> const &v)#
static void print_mask_vector(std::ostream &os, std::vector<mask_type> const &v)#

Private Types

using mutex_type = hpx::util::spinlock#

Private Functions

std::size_t init_node_number(std::size_t num_thread, hwloc_obj_type_t type) const#
inline std::size_t init_socket_number(std::size_t num_thread) const#
std::size_t init_numa_node_number(std::size_t num_thread) const#
inline std::size_t init_core_number(std::size_t num_thread) const#
void extract_node_mask(hwloc_obj_t parent, mask_type &mask) const#
std::size_t get_number_of_core_pus_locked(std::size_t core) const#
std::size_t extract_node_count(hwloc_obj_t parent, hwloc_obj_type_t type, std::size_t count) const#
std::size_t extract_node_count_locked(hwloc_obj_t parent, hwloc_obj_type_t type, std::size_t count) const#
mask_type init_machine_affinity_mask() const#
inline mask_type init_socket_affinity_mask(std::size_t num_thread) const#
inline mask_type init_numa_node_affinity_mask(std::size_t num_thread) const#
inline mask_type init_core_affinity_mask(std::size_t num_thread) const#
void init_num_of_pus()#
hwloc_obj_t get_pu_obj(std::size_t num_pu) const#

Private Members

hwloc_topology_t topo = nullptr#
std::size_t num_of_pus_ = 0#
bool use_pus_as_cores_ = false#
mutable mutex_type topo_mtx#
std::vector<std::size_t> socket_numbers_#
std::vector<std::size_t> numa_node_numbers_#
std::vector<std::size_t> core_numbers_#
mask_type machine_affinity_mask_ = mask_type()#
std::vector<mask_type> socket_affinity_masks_#
std::vector<mask_type> numa_node_affinity_masks_#
std::vector<mask_type> core_affinity_masks_#
std::vector<mask_type> thread_affinity_masks_#

Private Static Attributes

static mask_type empty_mask#
static std::size_t memory_page_size_#
static constexpr std::size_t pu_offset = 0#
static constexpr std::size_t core_offset = 0#

Friends

friend std::size_t get_memory_page_size()#