Skip to content

Commit d92b1a4

Browse files
committed
xml/import/v2: add Backend info to the root object from OS devices
Keep the Backend info in the OS device. Signed-off-by: Brice Goglin <[email protected]>
1 parent daa3850 commit d92b1a4

File tree

2 files changed

+60
-1
lines changed

2 files changed

+60
-1
lines changed

hwloc/topology-xml.c

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,26 @@ hwloc__xml_import_object(hwloc_topology_t topology,
754754
obj->type = HWLOC_OBJ_DIE;
755755
}
756756

757+
/* 2.x backward compatibility */
758+
if (data->version_major <= 2 && obj->type == HWLOC_OBJ_OS_DEVICE) {
759+
/* check if we need to add backend info to the root */
760+
const char *backend = hwloc_obj_get_info_by_name(obj, "Backend");
761+
if (backend) {
762+
if (!strcmp(backend, "CUDA"))
763+
data->need_cuda_backend_info = 1;
764+
else if (!strcmp(backend, "NVML"))
765+
data->need_nvml_backend_info = 1;
766+
else if (!strcmp(backend, "RSMI"))
767+
data->need_rsmi_backend_info = 1;
768+
else if (!strcmp(backend, "LevelZero"))
769+
data->need_levelzero_backend_info = 1;
770+
else if (!strcmp(backend, "OpenCL"))
771+
data->need_opencl_backend_info = 1;
772+
else if (!strcmp(backend, "GL"))
773+
data->need_gl_backend_info = 1;
774+
}
775+
}
776+
757777
/* check that cache attributes are coherent with the actual type */
758778
if (hwloc__obj_type_is_cache(obj->type)
759779
&& obj->type != hwloc_cache_type_by_depth_type(obj->attr->cache.depth, obj->attr->cache.type)) {
@@ -1690,6 +1710,12 @@ hwloc_look_xml(struct hwloc_backend *backend, struct hwloc_disc_status *dstatus)
16901710
hwloc_localeswitch_init();
16911711

16921712
data->nbnumanodes = 0;
1713+
data->need_cuda_backend_info = 0;
1714+
data->need_nvml_backend_info = 0;
1715+
data->need_rsmi_backend_info = 0;
1716+
data->need_levelzero_backend_info = 0;
1717+
data->need_opencl_backend_info = 0;
1718+
data->need_gl_backend_info = 0;
16931719

16941720
ret = data->look_init(data, &state);
16951721
if (ret < 0)
@@ -1805,7 +1831,39 @@ hwloc_look_xml(struct hwloc_backend *backend, struct hwloc_disc_status *dstatus)
18051831
/* allocate default cpusets and nodesets if missing, the core will restrict them */
18061832
hwloc_alloc_root_sets(root);
18071833

1808-
/* keep the "Backend" information intact */
1834+
/* keep the "Backend" information intact, but we had missing ones from v3 */
1835+
if (data->version_major <= 2) {
1836+
unsigned i;
1837+
/* check if root already has some backend info */
1838+
for(i=0; i<root->infos_count; i++)
1839+
if (!strcmp(root->infos[i].name, "Backend")) {
1840+
if (!strcmp(root->infos[i].value, "CUDA"))
1841+
data->need_cuda_backend_info = 0;
1842+
if (!strcmp(root->infos[i].value, "NVML"))
1843+
data->need_nvml_backend_info = 0;
1844+
if (!strcmp(root->infos[i].value, "RSMI"))
1845+
data->need_rsmi_backend_info = 0;
1846+
if (!strcmp(root->infos[i].value, "LevelZero"))
1847+
data->need_levelzero_backend_info = 0;
1848+
if (!strcmp(root->infos[i].value, "OpenCL"))
1849+
data->need_opencl_backend_info = 0;
1850+
if (!strcmp(root->infos[i].value, "GL"))
1851+
data->need_gl_backend_info = 0;
1852+
}
1853+
/* add missing backend info */
1854+
if (data->need_cuda_backend_info)
1855+
hwloc_obj_add_info(root, "Backend", "CUDA");
1856+
if (data->need_nvml_backend_info)
1857+
hwloc_obj_add_info(root, "Backend", "NVML");
1858+
if (data->need_rsmi_backend_info)
1859+
hwloc_obj_add_info(root, "Backend", "RSMI");
1860+
if (data->need_levelzero_backend_info)
1861+
hwloc_obj_add_info(root, "Backend", "LevelZero");
1862+
if (data->need_opencl_backend_info)
1863+
hwloc_obj_add_info(root, "Backend", "OpenCL");
1864+
if (data->need_gl_backend_info)
1865+
hwloc_obj_add_info(root, "Backend", "GL");
1866+
}
18091867
/* we could add "BackendSource=XML" to notify that XML was used between the actual backend and here */
18101868

18111869
if (!(topology->flags & HWLOC_TOPOLOGY_FLAG_IMPORT_SUPPORT)) {

include/private/xml.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ struct hwloc_xml_backend_data_s {
4545
void *data; /* libxml2 doc, or nolibxml buffer */
4646
unsigned version_major, version_minor;
4747
unsigned nbnumanodes;
48+
unsigned char need_cuda_backend_info, need_nvml_backend_info, need_rsmi_backend_info, need_levelzero_backend_info, need_opencl_backend_info, need_gl_backend_info;
4849
};
4950

5051
/**************

0 commit comments

Comments
 (0)