25
25
struct hwloc_calc_location_context_s {
26
26
hwloc_topology_t topology ;
27
27
int topodepth ;
28
- int only_hbm ; /* -1 for everything, 0 for only non-HBM, 1 for only HBM numa nodes */
28
+ int only_hbm ; /* -1 for everything, 0 for only non-HBM, 1 for only HBM numa nodes
29
+ * stored by caller, and passed to struct hwloc_calc_level for actual filtering
30
+ */
29
31
int logical ;
30
32
int verbose ;
31
33
};
@@ -35,6 +37,7 @@ struct hwloc_calc_level {
35
37
int depth ;
36
38
hwloc_obj_type_t type ;
37
39
union hwloc_obj_attr_u attr ;
40
+ int only_hbm ; /* -1 for everything, 0 for only non-HBM, 1 for only HBM numa nodes */
38
41
};
39
42
40
43
typedef enum hwloc_calc_append_mode_e {
@@ -87,13 +90,13 @@ hwloc_calc_append_set(hwloc_bitmap_t set, hwloc_const_bitmap_t newset,
87
90
static __hwloc_inline unsigned
88
91
hwloc_calc_get_nbobjs_inside_sets_by_depth (struct hwloc_calc_location_context_s * lcontext ,
89
92
hwloc_const_bitmap_t cpuset , hwloc_const_bitmap_t nodeset ,
90
- int depth )
93
+ struct hwloc_calc_level * level )
91
94
{
92
95
hwloc_topology_t topology = lcontext -> topology ;
93
- int only_hbm = lcontext -> only_hbm ;
96
+ int only_hbm = level -> only_hbm ;
94
97
hwloc_obj_t obj = NULL ;
95
98
unsigned n = 0 ;
96
- while ((obj = hwloc_get_next_obj_by_depth (topology , depth , obj )) != NULL ) {
99
+ while ((obj = hwloc_get_next_obj_by_depth (topology , level -> depth , obj )) != NULL ) {
97
100
if (!hwloc_bitmap_iszero (obj -> cpuset ) && !hwloc_bitmap_intersects (obj -> cpuset , cpuset ))
98
101
continue ;
99
102
if (!hwloc_bitmap_iszero (obj -> nodeset ) && !hwloc_bitmap_intersects (obj -> nodeset , nodeset ))
@@ -115,14 +118,14 @@ hwloc_calc_get_nbobjs_inside_sets_by_depth(struct hwloc_calc_location_context_s
115
118
static __hwloc_inline hwloc_obj_t
116
119
hwloc_calc_get_obj_inside_sets_by_depth (struct hwloc_calc_location_context_s * lcontext ,
117
120
hwloc_const_bitmap_t cpuset , hwloc_const_bitmap_t nodeset ,
118
- int depth , unsigned ind )
121
+ struct hwloc_calc_level * level , unsigned ind )
119
122
{
120
123
hwloc_topology_t topology = lcontext -> topology ;
121
- int only_hbm = lcontext -> only_hbm ;
124
+ int only_hbm = level -> only_hbm ;
122
125
int logical = lcontext -> logical ;
123
126
hwloc_obj_t obj = NULL ;
124
127
unsigned i = 0 ;
125
- while ((obj = hwloc_get_next_obj_by_depth (topology , depth , obj )) != NULL ) {
128
+ while ((obj = hwloc_get_next_obj_by_depth (topology , level -> depth , obj )) != NULL ) {
126
129
if (!hwloc_bitmap_iszero (obj -> cpuset ) && !hwloc_bitmap_intersects (obj -> cpuset , cpuset ))
127
130
continue ;
128
131
if (!hwloc_bitmap_iszero (obj -> nodeset ) && !hwloc_bitmap_intersects (obj -> nodeset , nodeset ))
@@ -158,6 +161,10 @@ hwloc_calc_parse_level(struct hwloc_calc_location_context_s *lcontext,
158
161
char * endptr ;
159
162
int err ;
160
163
164
+ level -> only_hbm = -1 ;
165
+ if (lcontext )
166
+ level -> only_hbm = lcontext -> only_hbm ;
167
+
161
168
level -> depth = HWLOC_TYPE_DEPTH_UNKNOWN ;
162
169
163
170
if (typelen >= sizeof (typestring ))
@@ -175,8 +182,7 @@ hwloc_calc_parse_level(struct hwloc_calc_location_context_s *lcontext,
175
182
}
176
183
177
184
if (!strcasecmp (typestring , "HBM" ) || !strcasecmp (typestring , "MCDRAM" )) {
178
- if (lcontext && lcontext -> only_hbm == -1 )
179
- lcontext -> only_hbm = 1 ;
185
+ level -> only_hbm = 1 ;
180
186
level -> type = HWLOC_OBJ_NUMANODE ;
181
187
level -> depth = HWLOC_TYPE_DEPTH_NUMANODE ;
182
188
return 0 ;
@@ -292,7 +298,7 @@ hwloc_calc_parse_range(const char *_string,
292
298
293
299
static __hwloc_inline int
294
300
hwloc_calc_append_object_range (struct hwloc_calc_location_context_s * lcontext ,
295
- hwloc_const_bitmap_t rootcpuset , hwloc_const_bitmap_t rootnodeset , int depth ,
301
+ hwloc_const_bitmap_t rootcpuset , hwloc_const_bitmap_t rootnodeset , struct hwloc_calc_level * level ,
296
302
const char * string , /* starts with indexes following the colon */
297
303
void (* cbfunc )(struct hwloc_calc_location_context_s * , void * , hwloc_obj_t ), void * cbdata )
298
304
{
@@ -301,7 +307,7 @@ hwloc_calc_append_object_range(struct hwloc_calc_location_context_s *lcontext,
301
307
hwloc_obj_t obj ;
302
308
unsigned width ;
303
309
const char * dot , * nextsep = NULL ;
304
- int nextdepth = -1 ;
310
+ struct hwloc_calc_level nextlevel ;
305
311
int first , wrap , amount , step ;
306
312
unsigned i ,j ;
307
313
int found = 0 ;
@@ -321,7 +327,6 @@ hwloc_calc_append_object_range(struct hwloc_calc_location_context_s *lcontext,
321
327
if (dot ) {
322
328
/* parse the next string before calling ourself recursively */
323
329
size_t typelen ;
324
- struct hwloc_calc_level level ;
325
330
const char * nextstring = dot + 1 ;
326
331
typelen = strspn (nextstring , "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" );
327
332
if (!typelen || nextstring [typelen ] != ':' ) {
@@ -331,55 +336,54 @@ hwloc_calc_append_object_range(struct hwloc_calc_location_context_s *lcontext,
331
336
}
332
337
nextsep = & nextstring [typelen ];
333
338
334
- err = hwloc_calc_parse_level (lcontext , topology , nextstring , typelen , & level );
339
+ err = hwloc_calc_parse_level (lcontext , topology , nextstring , typelen , & nextlevel );
335
340
if (err < 0 ) {
336
- if (level .depth == HWLOC_TYPE_DEPTH_UNKNOWN ) {
341
+ if (nextlevel .depth == HWLOC_TYPE_DEPTH_UNKNOWN ) {
337
342
if (verbose >= 0 )
338
343
fprintf (stderr , "could not find level specified by location %s\n" , nextstring );
339
344
return -1 ;
340
345
}
341
- if (level .depth == HWLOC_TYPE_DEPTH_MULTIPLE ) {
346
+ if (nextlevel .depth == HWLOC_TYPE_DEPTH_MULTIPLE ) {
342
347
if (verbose >= 0 )
343
348
fprintf (stderr , "found multiple levels for location %s\n" , nextstring );
344
349
return -1 ;
345
350
}
346
351
}
347
- nextdepth = level .depth ;
348
352
349
353
/* we need an object with a cpuset, that's depth>=0 or memory */
350
- if (nextdepth < 0 && nextdepth != HWLOC_TYPE_DEPTH_NUMANODE ) {
354
+ if (nextlevel . depth < 0 && nextlevel . depth != HWLOC_TYPE_DEPTH_NUMANODE ) {
351
355
if (verbose >= 0 )
352
356
fprintf (stderr , "hierarchical location %s only supported with normal object types\n" , string );
353
357
return -1 ;
354
358
}
355
359
}
356
360
357
- width = hwloc_calc_get_nbobjs_inside_sets_by_depth (lcontext , rootcpuset , rootnodeset , depth );
361
+ width = hwloc_calc_get_nbobjs_inside_sets_by_depth (lcontext , rootcpuset , rootnodeset , level );
358
362
if (amount == -1 )
359
363
amount = (width - first + step - 1 )/step ;
360
364
361
365
for (i = first , j = 0 ; j < (unsigned )amount ; i += step , j ++ ) {
362
366
if (wrap && i >=width )
363
367
i = 0 ;
364
368
365
- obj = hwloc_calc_get_obj_inside_sets_by_depth (lcontext , rootcpuset , rootnodeset , depth , i );
369
+ obj = hwloc_calc_get_obj_inside_sets_by_depth (lcontext , rootcpuset , rootnodeset , level , i );
366
370
if (verbose > 0 || (!obj && verbose >= 0 )) {
367
371
char * sc , * sn ;
368
372
hwloc_bitmap_asprintf (& sc , rootcpuset );
369
373
hwloc_bitmap_asprintf (& sn , rootnodeset );
370
374
if (obj )
371
375
printf ("using object #%u depth %d below cpuset %s nodeset %s\n" ,
372
- i , depth , sc , sn );
376
+ i , level -> depth , sc , sn );
373
377
else
374
378
fprintf (stderr , "object #%u depth %d below cpuset %s nodeset %s does not exist\n" ,
375
- i , depth , sc , sn );
379
+ i , level -> depth , sc , sn );
376
380
free (sc );
377
381
free (sn );
378
382
}
379
383
if (obj ) {
380
384
found ++ ;
381
385
if (dot ) {
382
- hwloc_calc_append_object_range (lcontext , obj -> cpuset , obj -> nodeset , nextdepth , nextsep + 1 , cbfunc , cbdata );
386
+ hwloc_calc_append_object_range (lcontext , obj -> cpuset , obj -> nodeset , & nextlevel , nextsep + 1 , cbfunc , cbdata );
383
387
} else {
384
388
/* add to the temporary cpuset
385
389
* and let the caller add/clear/and/xor for the actual final cpuset depending on cmdline options
@@ -629,7 +633,7 @@ hwloc_calc_process_location(struct hwloc_calc_location_context_s *lcontext,
629
633
return hwloc_calc_append_object_range (lcontext ,
630
634
hwloc_topology_get_complete_cpuset (topology ),
631
635
hwloc_topology_get_complete_nodeset (topology ),
632
- level . depth , sep + 1 , cbfunc , cbdata );
636
+ & level , sep + 1 , cbfunc , cbdata );
633
637
}
634
638
635
639
struct hwloc_calc_set_context_s {
0 commit comments