File indexing completed on 2025-01-18 10:01:16
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #ifndef HWLOC_LEVELZERO_H
0014 #define HWLOC_LEVELZERO_H
0015
0016 #include "hwloc.h"
0017 #include "hwloc/autogen/config.h"
0018 #include "hwloc/helper.h"
0019 #ifdef HWLOC_LINUX_SYS
0020 #include "hwloc/linux.h"
0021 #endif
0022
0023 #include <level_zero/ze_api.h>
0024 #include <level_zero/zes_api.h>
0025
0026
0027 #ifdef __cplusplus
0028 extern "C" {
0029 #endif
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063 static __hwloc_inline int
0064 hwloc_levelzero_get_device_cpuset(hwloc_topology_t topology __hwloc_attribute_unused,
0065 ze_device_handle_t device, hwloc_cpuset_t set)
0066 {
0067 #ifdef HWLOC_LINUX_SYS
0068
0069 #define HWLOC_LEVELZERO_DEVICE_SYSFS_PATH_MAX 128
0070 char path[HWLOC_LEVELZERO_DEVICE_SYSFS_PATH_MAX];
0071 zes_pci_properties_t pci;
0072 zes_device_handle_t sdevice = device;
0073 ze_result_t res;
0074
0075 if (!hwloc_topology_is_thissystem(topology)) {
0076 errno = EINVAL;
0077 return -1;
0078 }
0079
0080 res = zesDevicePciGetProperties(sdevice, &pci);
0081 if (res != ZE_RESULT_SUCCESS) {
0082 errno = EINVAL;
0083 return -1;
0084 }
0085
0086 sprintf(path, "/sys/bus/pci/devices/%04x:%02x:%02x.%01x/local_cpus",
0087 pci.address.domain, pci.address.bus, pci.address.device, pci.address.function);
0088 if (hwloc_linux_read_path_as_cpumask(path, set) < 0
0089 || hwloc_bitmap_iszero(set))
0090 hwloc_bitmap_copy(set, hwloc_topology_get_complete_cpuset(topology));
0091 #else
0092
0093 hwloc_bitmap_copy(set, hwloc_topology_get_complete_cpuset(topology));
0094 #endif
0095 return 0;
0096 }
0097
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109
0110
0111
0112 static __hwloc_inline hwloc_obj_t
0113 hwloc_levelzero_get_device_osdev(hwloc_topology_t topology, ze_device_handle_t device)
0114 {
0115 zes_device_handle_t sdevice = device;
0116 zes_pci_properties_t pci;
0117 ze_result_t res;
0118 hwloc_obj_t osdev;
0119
0120 if (!hwloc_topology_is_thissystem(topology)) {
0121 errno = EINVAL;
0122 return NULL;
0123 }
0124
0125 res = zesDevicePciGetProperties(sdevice, &pci);
0126 if (res != ZE_RESULT_SUCCESS) {
0127
0128 errno = EINVAL;
0129 return NULL;
0130 }
0131
0132 osdev = NULL;
0133 while ((osdev = hwloc_get_next_osdev(topology, osdev)) != NULL) {
0134 hwloc_obj_t pcidev = osdev->parent;
0135
0136 if (strncmp(osdev->name, "ze", 2))
0137 continue;
0138
0139 if (pcidev
0140 && pcidev->type == HWLOC_OBJ_PCI_DEVICE
0141 && pcidev->attr->pcidev.domain == pci.address.domain
0142 && pcidev->attr->pcidev.bus == pci.address.bus
0143 && pcidev->attr->pcidev.dev == pci.address.device
0144 && pcidev->attr->pcidev.func == pci.address.function)
0145 return osdev;
0146
0147
0148 }
0149
0150 return NULL;
0151 }
0152
0153
0154
0155
0156 #ifdef __cplusplus
0157 }
0158 #endif
0159
0160
0161 #endif