@@ -63,18 +63,21 @@ hwloc__levelzero_osdev_array_find(struct hwloc_osdev_array *array,
63
63
64
64
static void
65
65
hwloc__levelzero_properties_get (ze_device_handle_t zeh , zes_device_handle_t zesh ,
66
- hwloc_obj_t osdev ,
67
- int * is_integrated_p )
66
+ hwloc_obj_t osdev , ze_device_properties_t * prop )
68
67
{
69
68
ze_result_t res ;
70
- ze_device_properties_t prop ;
69
+ ze_device_properties_t _prop ;
71
70
zes_device_properties_t prop2 ;
72
71
int is_subdevice = 0 ;
73
- int is_integrated = 0 ;
74
72
75
- memset (& prop , 0 , sizeof (prop ));
76
- res = zeDeviceGetProperties (zeh , & prop );
77
- if (res == ZE_RESULT_SUCCESS ) {
73
+ if (!prop ) {
74
+ /* no properties were given, get ours */
75
+ memset (& _prop , 0 , sizeof (_prop ));
76
+ res = zeDeviceGetProperties (zeh , & _prop );
77
+ if (res == ZE_RESULT_SUCCESS )
78
+ prop = & _prop ;
79
+ }
80
+ if (prop ) {
78
81
/* name is the model name followed by the deviceID
79
82
* flags 1<<0 means integrated (vs discrete).
80
83
*/
@@ -83,41 +86,35 @@ hwloc__levelzero_properties_get(ze_device_handle_t zeh, zes_device_handle_t zesh
83
86
unsigned i ;
84
87
const char * type ;
85
88
86
- switch (prop . type ) {
89
+ switch (prop -> type ) {
87
90
case ZE_DEVICE_TYPE_GPU : type = "GPU" ; break ;
88
91
case ZE_DEVICE_TYPE_CPU : type = "CPU" ; break ;
89
92
case ZE_DEVICE_TYPE_FPGA : type = "FPGA" ; break ;
90
93
case ZE_DEVICE_TYPE_MCA : type = "MCA" ; break ;
91
94
case ZE_DEVICE_TYPE_VPU : type = "VPU" ; break ;
92
95
default :
93
96
if (HWLOC_SHOW_ALL_ERRORS ())
94
- fprintf (stderr , "hwloc/levelzero: unexpected device type %u\n" , (unsigned ) prop . type );
97
+ fprintf (stderr , "hwloc/levelzero: unexpected device type %u\n" , (unsigned ) prop -> type );
95
98
type = "Unknown" ;
96
99
}
97
100
hwloc_obj_add_info (osdev , "LevelZeroDeviceType" , type );
98
- snprintf (tmp , sizeof (tmp ), "%u" , prop . numSlices );
101
+ snprintf (tmp , sizeof (tmp ), "%u" , prop -> numSlices );
99
102
hwloc_obj_add_info (osdev , "LevelZeroNumSlices" , tmp );
100
- snprintf (tmp , sizeof (tmp ), "%u" , prop . numSubslicesPerSlice );
103
+ snprintf (tmp , sizeof (tmp ), "%u" , prop -> numSubslicesPerSlice );
101
104
hwloc_obj_add_info (osdev , "LevelZeroNumSubslicesPerSlice" , tmp );
102
- snprintf (tmp , sizeof (tmp ), "%u" , prop . numEUsPerSubslice );
105
+ snprintf (tmp , sizeof (tmp ), "%u" , prop -> numEUsPerSubslice );
103
106
hwloc_obj_add_info (osdev , "LevelZeroNumEUsPerSubslice" , tmp );
104
- snprintf (tmp , sizeof (tmp ), "%u" , prop . numThreadsPerEU );
107
+ snprintf (tmp , sizeof (tmp ), "%u" , prop -> numThreadsPerEU );
105
108
hwloc_obj_add_info (osdev , "LevelZeroNumThreadsPerEU" , tmp );
106
109
107
110
for (i = 0 ; i < ZE_MAX_DEVICE_UUID_SIZE ; i ++ )
108
- snprintf (uuid + 2 * i , 3 , "%02x" , prop . uuid .id [i ]);
111
+ snprintf (uuid + 2 * i , 3 , "%02x" , prop -> uuid .id [i ]);
109
112
hwloc_obj_add_info (osdev , "LevelZeroUUID" , uuid );
110
113
111
- if (prop . flags & ZE_DEVICE_PROPERTY_FLAG_SUBDEVICE )
114
+ if (prop -> flags & ZE_DEVICE_PROPERTY_FLAG_SUBDEVICE )
112
115
is_subdevice = 1 ;
113
-
114
- if (prop .flags & ZE_DEVICE_PROPERTY_FLAG_INTEGRATED )
115
- is_integrated = 1 ;
116
116
}
117
117
118
- if (is_integrated_p )
119
- * is_integrated_p = is_integrated ;
120
-
121
118
if (is_subdevice )
122
119
/* sysman API on subdevice returns the same as root device, and we don't need those duplicate attributes */
123
120
return ;
@@ -172,9 +169,9 @@ hwloc__levelzero_cqprops_get(ze_device_handle_t zeh,
172
169
}
173
170
174
171
static int
175
- hwloc__levelzero_memory_get_from_sysman (zes_device_handle_t zesh ,
176
- hwloc_obj_t root_osdev ,
177
- unsigned nr_osdevs , hwloc_obj_t * sub_osdevs )
172
+ hwloc__levelzero_memory_get (zes_device_handle_t zesh ,
173
+ hwloc_obj_t root_osdev ,
174
+ unsigned nr_osdevs , hwloc_obj_t * sub_osdevs )
178
175
{
179
176
zes_mem_handle_t * mh ;
180
177
uint32_t nr_mems ;
@@ -279,95 +276,6 @@ hwloc__levelzero_memory_get_from_sysman(zes_device_handle_t zesh,
279
276
return 0 ;
280
277
}
281
278
282
- static void
283
- hwloc__levelzero_memory_get_from_coreapi (ze_device_handle_t zeh ,
284
- hwloc_obj_t osdev ,
285
- int ignore_ddr )
286
- {
287
- ze_device_memory_properties_t * mh ;
288
- uint32_t nr_mems ;
289
- ze_result_t res ;
290
-
291
- nr_mems = 0 ;
292
- res = zeDeviceGetMemoryProperties (zeh , & nr_mems , NULL );
293
- if (res != ZE_RESULT_SUCCESS || !nr_mems )
294
- return ;
295
- hwloc_debug ("L0/CoreAPI: found %u memories in osdev %s\n" ,
296
- nr_mems , osdev -> name );
297
-
298
- mh = malloc (nr_mems * sizeof (* mh ));
299
- if (mh ) {
300
- res = zeDeviceGetMemoryProperties (zeh , & nr_mems , mh );
301
- if (res == ZE_RESULT_SUCCESS ) {
302
- unsigned m ;
303
- for (m = 0 ; m < nr_mems ; m ++ ) {
304
- const char * _name = mh [m ].name ;
305
- char name [300 ], value [64 ];
306
- /* FIXME: discrete GPUs report 95% of the physical memory (what sysman sees)
307
- * while integrated GPUs report 80% of the host RAM (sysman sees 0), adjust?
308
- */
309
- hwloc_debug ("L0/CoreAPI: found memory name %s size %llu in osdev %s\n" ,
310
- mh [m ].name , (unsigned long long ) mh [m ].totalSize , osdev -> name );
311
- if (!mh [m ].totalSize )
312
- continue ;
313
- if (ignore_ddr && !strcmp (_name , "DDR" ))
314
- continue ;
315
- if (!_name [0 ])
316
- _name = "Memory" ;
317
- snprintf (name , sizeof (name ), "LevelZero%sSize" , _name ); /* HBM or DDR, or Memory if unknown */
318
- snprintf (value , sizeof (value ), "%lluKiB" , (unsigned long long ) mh [m ].totalSize >> 10 );
319
- hwloc_obj_add_info (osdev , name , value );
320
- }
321
- }
322
- free (mh );
323
- }
324
- }
325
-
326
-
327
- static void
328
- hwloc__levelzero_memory_get (ze_device_handle_t zeh , zes_device_handle_t zesh ,
329
- hwloc_obj_t root_osdev , int is_integrated ,
330
- unsigned nr_subdevices , zes_device_handle_t * subzehs , hwloc_obj_t * sub_osdevs )
331
- {
332
- static int memory_from_coreapi = -1 ; /* 1 means coreapi, 0 means sysman, -1 means sysman if available or coreapi otherwise */
333
- static int first = 1 ;
334
-
335
- if (first ) {
336
- char * env ;
337
- env = getenv ("HWLOC_L0_COREAPI_MEMORY" );
338
- if (env )
339
- memory_from_coreapi = atoi (env );
340
-
341
- if (memory_from_coreapi == -1 ) {
342
- int ret = hwloc__levelzero_memory_get_from_sysman (zesh , root_osdev , nr_subdevices , sub_osdevs );
343
- if (!ret ) {
344
- /* sysman worked, we're done, disable coreapi for next time */
345
- hwloc_debug ("levelzero: sysman/memory succeeded, disabling coreapi memory queries\n" );
346
- memory_from_coreapi = 0 ;
347
- return ;
348
- }
349
- /* sysman failed, enable coreapi */
350
- hwloc_debug ("levelzero: sysman/memory failed, enabling coreapi memory queries\n" );
351
- memory_from_coreapi = 1 ;
352
- }
353
-
354
- first = 0 ;
355
- }
356
-
357
- if (memory_from_coreapi > 0 ) {
358
- unsigned k ;
359
- int ignore_ddr = (memory_from_coreapi != 2 ) && is_integrated ; /* DDR ignored in integrated GPUs, it's like the host DRAM */
360
- hwloc__levelzero_memory_get_from_coreapi (zeh , root_osdev , ignore_ddr );
361
- for (k = 0 ; k < nr_subdevices ; k ++ )
362
- hwloc__levelzero_memory_get_from_coreapi (subzehs [k ], sub_osdevs [k ], ignore_ddr );
363
- } else {
364
- hwloc__levelzero_memory_get_from_sysman (zesh , root_osdev , nr_subdevices , sub_osdevs );
365
- /* no need to call hwloc__levelzero_memory_get() on subdevices,
366
- * the call on the root device is enough (and identical to a call on subdevices)
367
- */
368
- }
369
- }
370
-
371
279
struct hwloc_levelzero_ports {
372
280
unsigned nr_allocated ;
373
281
unsigned nr ;
@@ -551,7 +459,6 @@ hwloc__levelzero_devices_get(struct hwloc_topology *topology,
551
459
hwloc_obj_t osdev , parent , * subosdevs = NULL ;
552
460
ze_device_properties_t props ;
553
461
zes_uuid_t uuid ;
554
- int is_integrated = 0 ;
555
462
ze_bool_t onSubdevice = 0 ;
556
463
uint32_t subdeviceId = 0 ;
557
464
@@ -583,7 +490,7 @@ hwloc__levelzero_devices_get(struct hwloc_topology *topology,
583
490
snprintf (buffer , sizeof (buffer ), "%u" , j );
584
491
hwloc_obj_add_info (osdev , "LevelZeroDriverDeviceIndex" , buffer );
585
492
586
- hwloc__levelzero_properties_get (zeh , zesh , osdev , & is_integrated );
493
+ hwloc__levelzero_properties_get (zeh , zesh , osdev , & props );
587
494
588
495
hwloc__levelzero_cqprops_get (zeh , osdev );
589
496
@@ -641,7 +548,7 @@ hwloc__levelzero_devices_get(struct hwloc_topology *topology,
641
548
}
642
549
643
550
/* get all memory info at once */
644
- hwloc__levelzero_memory_get (zeh , zesh , osdev , is_integrated , nr_subdevices , subzehs , subosdevs );
551
+ hwloc__levelzero_memory_get (zesh , osdev , nr_subdevices , subosdevs );
645
552
646
553
/* get all ports info at once */
647
554
if (!(hwloc_topology_get_flags (topology ) & HWLOC_TOPOLOGY_FLAG_NO_DISTANCES ))
0 commit comments