11/*
22 *
3- * Copyright (C) 2024 Intel Corporation
3+ * Copyright (C) 2024-2025 Intel Corporation
44 *
55 * Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
66 * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
1313#include "utils_log.h"
1414
1515static hwloc_topology_t topology = NULL ;
16+ static hwloc_topology_t topology_reduced = NULL ;
1617static UTIL_ONCE_FLAG topology_initialized = UTIL_ONCE_FLAG_INIT ;
18+ static UTIL_ONCE_FLAG topology_reduced_initialized = UTIL_ONCE_FLAG_INIT ;
1719
1820void umfDestroyTopology (void ) {
1921 if (topology ) {
@@ -24,22 +26,55 @@ void umfDestroyTopology(void) {
2426 memcpy (& topology_initialized , & is_initialized ,
2527 sizeof (topology_initialized ));
2628 }
29+ if (topology_reduced ) {
30+ hwloc_topology_destroy (topology_reduced );
31+
32+ // portable version of "topology_initialized = UTIL_ONCE_FLAG_INIT;"
33+ static UTIL_ONCE_FLAG is_initialized = UTIL_ONCE_FLAG_INIT ;
34+ memcpy (& topology_reduced_initialized , & is_initialized ,
35+ sizeof (topology_reduced_initialized ));
36+ }
2737}
2838
29- static void umfCreateTopology (void ) {
30- if (hwloc_topology_init (& topology )) {
39+ static void umfCreateTopologyHelper (bool reduced ,
40+ hwloc_topology_t * topology_ptr ) {
41+ if (hwloc_topology_init (topology_ptr )) {
3142 LOG_ERR ("Failed to initialize topology" );
32- topology = NULL ;
43+ * topology_ptr = NULL ;
3344 return ;
3445 }
3546
36- if (hwloc_topology_load (topology )) {
47+ if (reduced ) {
48+ // Set the topology to only include NUMA nodes and memory
49+ // to improve performance of the topology load on large systems
50+ if (hwloc_topology_set_all_types_filter (* topology_ptr ,
51+ HWLOC_TYPE_FILTER_KEEP_NONE )) {
52+ LOG_ERR ("Failed to set topology filter" );
53+ hwloc_topology_destroy (* topology_ptr );
54+ * topology_ptr = NULL ;
55+ return ;
56+ }
57+ }
58+ if (hwloc_topology_load (* topology_ptr )) {
3759 LOG_ERR ("Failed to initialize topology" );
38- hwloc_topology_destroy (topology );
39- topology = NULL ;
60+ hwloc_topology_destroy (* topology_ptr );
61+ * topology_ptr = NULL ;
4062 }
4163}
4264
65+ static void umfCreateTopology (void ) {
66+ umfCreateTopologyHelper (false, & topology );
67+ }
68+
69+ static void umfCreateTopologyReduced (void ) {
70+ umfCreateTopologyHelper (true, & topology_reduced );
71+ }
72+
73+ hwloc_topology_t umfGetTopologyReduced (void ) {
74+ utils_init_once (& topology_reduced_initialized , umfCreateTopologyReduced );
75+ return topology_reduced ;
76+ }
77+
4378hwloc_topology_t umfGetTopology (void ) {
4479 utils_init_once (& topology_initialized , umfCreateTopology );
4580 return topology ;
0 commit comments