@@ -3870,6 +3870,7 @@ hwloc__topology_init (struct hwloc_topology **topologyp,
3870
3870
3871
3871
hwloc__topology_filter_init (topology );
3872
3872
3873
+ /* always initialize since we don't know flags to disable those yet */
3873
3874
hwloc_internal_distances_init (topology );
3874
3875
hwloc_internal_memattrs_init (topology );
3875
3876
hwloc_internal_cpukinds_init (topology );
@@ -4134,9 +4135,12 @@ hwloc_topology_clear (struct hwloc_topology *topology)
4134
4135
{
4135
4136
/* no need to set to NULL after free() since callers will call setup_defaults() or just destroy the rest of the topology */
4136
4137
unsigned l ;
4138
+
4139
+ /* always destroy cpukinds/distances/memattrs since there are always initialized during init() */
4137
4140
hwloc_internal_cpukinds_destroy (topology );
4138
4141
hwloc_internal_distances_destroy (topology );
4139
4142
hwloc_internal_memattrs_destroy (topology );
4143
+
4140
4144
hwloc_free_object_and_children (topology -> levels [0 ][0 ]);
4141
4145
hwloc_bitmap_free (topology -> allowed_cpuset );
4142
4146
hwloc_bitmap_free (topology -> allowed_nodeset );
@@ -4189,8 +4193,10 @@ hwloc_topology_load (struct hwloc_topology *topology)
4189
4193
topology -> state |= HWLOC_TOPOLOGY_STATE_IS_LOADING ;
4190
4194
4191
4195
/* initialize envvar-related things */
4192
- hwloc_internal_distances_prepare (topology );
4193
- hwloc_internal_memattrs_prepare (topology );
4196
+ if (!(topology -> flags & HWLOC_TOPOLOGY_FLAG_NO_DISTANCES ))
4197
+ hwloc_internal_distances_prepare (topology );
4198
+ if (!(topology -> flags & HWLOC_TOPOLOGY_FLAG_NO_MEMATTRS ))
4199
+ hwloc_internal_memattrs_prepare (topology );
4194
4200
4195
4201
/* check if any cpu cache filter is not NONE */
4196
4202
topology -> want_some_cpu_caches = 0 ;
@@ -4275,24 +4281,29 @@ hwloc_topology_load (struct hwloc_topology *topology)
4275
4281
#endif
4276
4282
hwloc_topology_check (topology );
4277
4283
4278
- /* Rank cpukinds */
4279
- hwloc_internal_cpukinds_rank (topology );
4284
+ if (!(topology -> flags & HWLOC_TOPOLOGY_FLAG_NO_CPUKINDS )) {
4285
+ /* Rank cpukinds */
4286
+ hwloc_internal_cpukinds_rank (topology );
4287
+ }
4280
4288
4281
- /* Mark distances objs arrays as invalid since we may have removed objects
4282
- * from the topology after adding the distances (remove_empty, etc).
4283
- * It would be hard to actually verify whether it's needed.
4284
- */
4285
- hwloc_internal_distances_invalidate_cached_objs (topology );
4286
- /* And refresh distances so that multithreaded concurrent distances_get()
4287
- * don't refresh() concurrently (disallowed).
4288
- */
4289
- hwloc_internal_distances_refresh (topology );
4289
+ if (!(topology -> flags & HWLOC_TOPOLOGY_FLAG_NO_DISTANCES )) {
4290
+ /* Mark distances objs arrays as invalid since we may have removed objects
4291
+ * from the topology after adding the distances (remove_empty, etc).
4292
+ * It would be hard to actually verify whether it's needed.
4293
+ */
4294
+ hwloc_internal_distances_invalidate_cached_objs (topology );
4295
+ /* And refresh distances so that multithreaded concurrent distances_get()
4296
+ * don't refresh() concurrently (disallowed).
4297
+ */
4298
+ hwloc_internal_distances_refresh (topology );
4299
+ }
4290
4300
4291
- /* Same for memattrs */
4292
- hwloc_internal_memattrs_need_refresh ( topology );
4293
- hwloc_internal_memattrs_refresh (topology );
4294
- if (!( topology -> flags & HWLOC_TOPOLOGY_FLAG_NO_MEMATTRS ))
4301
+ if (!( topology -> flags & HWLOC_TOPOLOGY_FLAG_NO_MEMATTRS )) {
4302
+ /* Same for memattrs */
4303
+ hwloc_internal_memattrs_need_refresh (topology );
4304
+ hwloc_internal_memattrs_refresh ( topology );
4295
4305
hwloc_internal_memattrs_guess_memory_tiers (topology );
4306
+ }
4296
4307
4297
4308
topology -> state &= ~HWLOC_TOPOLOGY_STATE_IS_LOADING ;
4298
4309
topology -> state |= HWLOC_TOPOLOGY_STATE_IS_LOADED ;
@@ -4582,13 +4593,18 @@ hwloc_topology_restrict(struct hwloc_topology *topology, hwloc_const_bitmap_t se
4582
4593
if (hwloc_filter_levels_keep_structure (topology ) < 0 ) /* takes care of reconnecting internally */
4583
4594
goto out ;
4584
4595
4585
- /* some objects may have disappeared, we need to update distances objs arrays */
4586
- hwloc_internal_distances_invalidate_cached_objs (topology );
4587
- hwloc_internal_memattrs_need_refresh (topology );
4596
+ /* some objects may have disappeared and sets were modified,
4597
+ * we need to update distances, etc */
4598
+ if (!(topology -> flags & HWLOC_TOPOLOGY_FLAG_NO_DISTANCES ))
4599
+ hwloc_internal_distances_invalidate_cached_objs (topology );
4600
+ if (!(topology -> flags & HWLOC_TOPOLOGY_FLAG_NO_MEMATTRS ))
4601
+ hwloc_internal_memattrs_need_refresh (topology );
4602
+ if (!(topology -> flags & HWLOC_TOPOLOGY_FLAG_NO_CPUKINDS ))
4603
+ hwloc_internal_cpukinds_restrict (topology );
4604
+
4588
4605
4589
4606
hwloc_propagate_symmetric_subtree (topology , topology -> levels [0 ][0 ]);
4590
4607
propagate_total_memory (topology -> levels [0 ][0 ]);
4591
- hwloc_internal_cpukinds_restrict (topology );
4592
4608
4593
4609
#ifndef HWLOC_DEBUG
4594
4610
if (getenv ("HWLOC_DEBUG_CHECK" ))
@@ -4671,9 +4687,12 @@ hwloc_topology_allow(struct hwloc_topology *topology,
4671
4687
int
4672
4688
hwloc_topology_refresh (struct hwloc_topology * topology )
4673
4689
{
4674
- hwloc_internal_cpukinds_rank (topology );
4675
- hwloc_internal_distances_refresh (topology );
4676
- hwloc_internal_memattrs_refresh (topology );
4690
+ if (!(topology -> flags & HWLOC_TOPOLOGY_FLAG_NO_CPUKINDS ))
4691
+ hwloc_internal_cpukinds_rank (topology );
4692
+ if (!(topology -> flags & HWLOC_TOPOLOGY_FLAG_NO_DISTANCES ))
4693
+ hwloc_internal_distances_refresh (topology );
4694
+ if (!(topology -> flags & HWLOC_TOPOLOGY_FLAG_NO_MEMATTRS ))
4695
+ hwloc_internal_memattrs_refresh (topology );
4677
4696
return 0 ;
4678
4697
}
4679
4698
0 commit comments