1
1
/*
2
2
*
3
- * Copyright (C) 2024 Intel Corporation
3
+ * Copyright (C) 2024-2025 Intel Corporation
4
4
*
5
5
* Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
6
6
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
13
13
#include "utils_log.h"
14
14
15
15
static hwloc_topology_t topology = NULL ;
16
+ static hwloc_topology_t topology_reduced = NULL ;
16
17
static UTIL_ONCE_FLAG topology_initialized = UTIL_ONCE_FLAG_INIT ;
18
+ static UTIL_ONCE_FLAG topology_reduced_initialized = UTIL_ONCE_FLAG_INIT ;
17
19
18
20
void umfDestroyTopology (void ) {
19
21
if (topology ) {
@@ -24,22 +26,55 @@ void umfDestroyTopology(void) {
24
26
memcpy (& topology_initialized , & is_initialized ,
25
27
sizeof (topology_initialized ));
26
28
}
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
+ }
27
37
}
28
38
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 )) {
31
42
LOG_ERR ("Failed to initialize topology" );
32
- topology = NULL ;
43
+ * topology_ptr = NULL ;
33
44
return ;
34
45
}
35
46
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 )) {
37
59
LOG_ERR ("Failed to initialize topology" );
38
- hwloc_topology_destroy (topology );
39
- topology = NULL ;
60
+ hwloc_topology_destroy (* topology_ptr );
61
+ * topology_ptr = NULL ;
40
62
}
41
63
}
42
64
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
+
43
78
hwloc_topology_t umfGetTopology (void ) {
44
79
utils_init_once (& topology_initialized , umfCreateTopology );
45
80
return topology ;
0 commit comments