From f58cd0e9a0c8e5a014cfb28516243d2072989b65 Mon Sep 17 00:00:00 2001 From: Ryan S <159389674+saariuslystoned@users.noreply.github.com> Date: Sun, 29 Nov 2026 03:54:20 -0500 Subject: [PATCH 1/2] feat(ironwood): add tpu7x 8-device single-chiplet enumeration and CDI/exporter dual-chiplet metadata (#21) --- libopentpu/src/ot_pjrt.cpp | 10 ++++ libopentpu/src/ot_vfio.cpp | 4 +- libopentpu/tests/opentpu_host_test.cpp | 68 ++++++++++++++++++++++++++ ops/tpu-cdi/freetpu_cdi.py | 54 ++++++++++++++++++++ ops/tpu-cdi/test_freetpu_cdi.py | 50 +++++++++++++++++++ ops/tpu-exporter/test_tpu_exporter.py | 13 +++++ ops/tpu-exporter/tpu_exporter.py | 17 +++++++ 7 files changed, 215 insertions(+), 1 deletion(-) diff --git a/libopentpu/src/ot_pjrt.cpp b/libopentpu/src/ot_pjrt.cpp index 2ab4d25d..fcce2487 100644 --- a/libopentpu/src/ot_pjrt.cpp +++ b/libopentpu/src/ot_pjrt.cpp @@ -1174,6 +1174,16 @@ PJRT_Error* ot_pjrt_client_create(PJRT_Client_Create_Args* args) { topo_did = 0x0075u; pci_funcs = 4; chiplets_per_func = 2; + } else if (std::strcmp(topo_env, "tpu7x-4t-single") == 0 || + std::strcmp(topo_env, "tpu7x_4t_single") == 0) { + // Alternative Day-1 PCI enumeration: 8 single-chiplet PCI functions each + // exposing one logical TensorCore (same 8 logical devices, same 96 GiB + // HBM3e per logical device as the 4 dual-chiplet-function default). + has_named_topo = true; + topo_gen = OT_CHIP_TPU7X; + topo_did = 0x0075u; + pci_funcs = 8; + chiplets_per_func = 1; } else if (std::strcmp(topo_env, "v6e-8") == 0 || std::strcmp(topo_env, "v6e_8") == 0) { has_named_topo = true; topo_gen = OT_CHIP_V6E; diff --git a/libopentpu/src/ot_vfio.cpp b/libopentpu/src/ot_vfio.cpp index 07f8b555..8f0fec6f 100644 --- a/libopentpu/src/ot_vfio.cpp +++ b/libopentpu/src/ot_vfio.cpp @@ -626,7 +626,9 @@ bool VfioTransport::open_device(const ot_config_t& cfg, ot_device_info_t* info, } } else if (const char* topo_env = std::getenv("OPENTPU_MOCK_TOPOLOGY")) { if (std::strcmp(topo_env, "tpu7x-1t") == 0 || std::strcmp(topo_env, "tpu7x_1t") == 0 || - std::strcmp(topo_env, "tpu7x-4t") == 0 || std::strcmp(topo_env, "tpu7x_4t") == 0) { + std::strcmp(topo_env, "tpu7x-4t") == 0 || std::strcmp(topo_env, "tpu7x_4t") == 0 || + std::strcmp(topo_env, "tpu7x-4t-single") == 0 || + std::strcmp(topo_env, "tpu7x_4t_single") == 0) { mock_did = 0x0075u; } else if (std::strcmp(topo_env, "v6e-8") == 0 || std::strcmp(topo_env, "v6e_8") == 0) { mock_did = 0x006fu; diff --git a/libopentpu/tests/opentpu_host_test.cpp b/libopentpu/tests/opentpu_host_test.cpp index b7b47616..89d74f3e 100644 --- a/libopentpu/tests/opentpu_host_test.cpp +++ b/libopentpu/tests/opentpu_host_test.cpp @@ -2524,6 +2524,73 @@ static void test_pjrt_dual_chiplet_tpu7x_enumeration() { printf("[PASS] test_pjrt_dual_chiplet_tpu7x_enumeration\n"); } +static void test_pjrt_single_chiplet_tpu7x_enumeration() { + const PJRT_Api* api = GetPjrtApi(); + OT_CHECK(api != nullptr); + + // Alternative Day-1 PCI enumeration: 8 single-chiplet PCI functions each + // exposing one logical TensorCore. Must still yield 8 logical devices with + // the same tpu7x HAL geometry as the 4 dual-chiplet-function default: + // MXU 256x256, FP8 inner tile (4,1), 96 GiB HBM3e per logical device. + setenv("OPENTPU_MOCK", "1", 1); + setenv("OPENTPU_MOCK_CHIP", "tpu7x", 1); + setenv("OPENTPU_MOCK_TOPOLOGY", "tpu7x-4t-single", 1); + + PJRT_Client_Create_Args c_args = {}; + c_args.struct_size = PJRT_Client_Create_Args_STRUCT_SIZE; + OT_CHECK(api->PJRT_Client_Create(&c_args) == nullptr && c_args.client != nullptr); + + PJRT_Client_AddressableDevices_Args d_args = {}; + d_args.struct_size = PJRT_Client_AddressableDevices_Args_STRUCT_SIZE; + d_args.client = c_args.client; + OT_CHECK(api->PJRT_Client_AddressableDevices(&d_args) == nullptr); + OT_CHECK(d_args.num_addressable_devices == 8u); + + ot_device_geometry_t g7 = {}; + OT_CHECK(ot_chip_geometry_for_device_id(0x0075u, &g7) == OT_OK); + OT_CHECK(g7.chip_gen == OT_CHIP_TPU7X); + OT_CHECK(g7.mxu_rows == 256u && g7.mxu_cols == 256u); + OT_CHECK(g7.fp8_inner_rows == 4u && g7.fp8_inner_cols == 1u); + OT_CHECK(g7.supports_native_fp8 == 1u); + OT_CHECK(g7.hbm_bytes_per_logical_chiplet == (96ULL << 30)); + + for (size_t i = 0; i < 8u; ++i) { + PJRT_Device_GetDescription_Args gd = {}; + gd.struct_size = PJRT_Device_GetDescription_Args_STRUCT_SIZE; + gd.device = d_args.addressable_devices[i]; + OT_CHECK(api->PJRT_Device_GetDescription(&gd) == nullptr); + + PJRT_DeviceDescription_Id_Args id_args = {}; + id_args.struct_size = PJRT_DeviceDescription_Id_Args_STRUCT_SIZE; + id_args.device_description = gd.device_description; + OT_CHECK(api->PJRT_DeviceDescription_Id(&id_args) == nullptr); + OT_CHECK(id_args.id == static_cast(i)); + + PJRT_DeviceDescription_Kind_Args k_args = {}; + k_args.struct_size = PJRT_DeviceDescription_Kind_Args_STRUCT_SIZE; + k_args.device_description = gd.device_description; + OT_CHECK(api->PJRT_DeviceDescription_Kind(&k_args) == nullptr); + OT_CHECK(std::string(k_args.device_kind, k_args.device_kind_size) == "TPU v7x"); + + PJRT_DeviceDescription_Attributes_Args attr_args = {}; + attr_args.struct_size = PJRT_DeviceDescription_Attributes_Args_STRUCT_SIZE; + attr_args.device_description = gd.device_description; + OT_CHECK(api->PJRT_DeviceDescription_Attributes(&attr_args) == nullptr); + // Single-chiplet functions expose only coords (no core_on_chip). + OT_CHECK(attr_args.num_attributes == 1u); + } + + PJRT_Client_Destroy_Args cd_args = {}; + cd_args.struct_size = PJRT_Client_Destroy_Args_STRUCT_SIZE; + cd_args.client = c_args.client; + OT_CHECK(api->PJRT_Client_Destroy(&cd_args) == nullptr); + + unsetenv("OPENTPU_MOCK_TOPOLOGY"); + unsetenv("OPENTPU_MOCK_CHIP"); + unsetenv("OPENTPU_MOCK"); + printf("[PASS] test_pjrt_single_chiplet_tpu7x_enumeration\n"); +} + static void test_pjrt_multidevice_isolation_and_topology() { const PJRT_Api* api = GetPjrtApi(); OT_CHECK(api != nullptr); @@ -3282,6 +3349,7 @@ int main() { test_mock_multitile_and_quant_matmul(); test_multigen_hal_geometry_and_rebar(); test_pjrt_dual_chiplet_tpu7x_enumeration(); + test_pjrt_single_chiplet_tpu7x_enumeration(); test_pjrt_multidevice_isolation_and_topology(); printf("ALL_HOST_TESTS_PASSED\n"); return 0; diff --git a/ops/tpu-cdi/freetpu_cdi.py b/ops/tpu-cdi/freetpu_cdi.py index bce6d7f5..eb38a247 100755 --- a/ops/tpu-cdi/freetpu_cdi.py +++ b/ops/tpu-cdi/freetpu_cdi.py @@ -114,6 +114,38 @@ "v2-v3": 2, "tpu7x": 2, } + +# Dual-chiplet topology metadata per generation (Issue #21, Ironwood Day-1): +# `chiplets_per_pkg` = logical TensorCore chiplets per physical package (2 on +# tpu7x Ironwood, 1 otherwise); `hbm_gib_per_logical_device` = HBM3e GiB per +# logical device (96 GiB on tpu7x: 192 GiB/package / 2 chiplets). +# `0x1ae0:0x0075` is provisional pending Day-1 `lspci -nn` capture. +TPU_CHIPLETS_PER_PKG: Dict[str, int] = { + "tpu7x": 2, +} +TPU_HBM_GIB_PER_LOGICAL_DEVICE: Dict[str, int] = { + "tpu7x": 96, + "v5e": 16, + "v6e": 32, + "v6e-pf": 32, + "v5p": 95, + "v4": 32, + "v4lite": 8, +} + + +def tpu_topology_metadata(generation: str) -> Dict[str, int]: + """Return `{'chiplets_per_pkg': int, 'hbm_gib_per_logical_device': int|None}`.""" + gen = generation + chiplets = ( + _PCI_FUNCTIONS_PER_PHYSICAL_CHIP.get(gen, 1) + if gen in _PCI_FUNCTIONS_PER_PHYSICAL_CHIP + else TPU_CHIPLETS_PER_PKG.get(gen, 1) + ) + return { + "chiplets_per_pkg": chiplets, + "hbm_gib_per_logical_device": TPU_HBM_GIB_PER_LOGICAL_DEVICE.get(gen), + } _SYSFS_PCI_ROOT_RE = re.compile(r"^pci([0-9a-fA-F]{4,}:[0-9a-fA-F]{2})\Z") _ALLOWED_HOOK_NAMES = frozenset( { @@ -2147,6 +2179,12 @@ def build_cdi_spec( "freetpu.dev/optional-cap-add": "IPC_LOCK", "freetpu.dev/required-ulimit-memlock": "-1", } + _tpu_meta = tpu_topology_metadata(rep.generation) + ann["freetpu.dev/chiplets-per-pkg"] = str(_tpu_meta["chiplets_per_pkg"]) + if _tpu_meta["hbm_gib_per_logical_device"] is not None: + ann["freetpu.dev/hbm-gib-per-logical-device"] = str( + _tpu_meta["hbm_gib_per_logical_device"] + ) if rep.numa_node is not None: ann["freetpu.dev/numa-node"] = str(rep.numa_node) if devnums_str: @@ -2260,6 +2298,15 @@ def build_cdi_spec( "freetpu.dev/optional-cap-add": "IPC_LOCK", "freetpu.dev/required-ulimit-memlock": "-1", } + if len(set(topo_slice.generations)) == 1: + _slice_meta = tpu_topology_metadata(topo_slice.generations[0]) + slice_ann_base["freetpu.dev/chiplets-per-pkg"] = str( + _slice_meta["chiplets_per_pkg"] + ) + if _slice_meta["hbm_gib_per_logical_device"] is not None: + slice_ann_base["freetpu.dev/hbm-gib-per-logical-device"] = str( + _slice_meta["hbm_gib_per_logical_device"] + ) # Record freetpu.dev/numa-node ONLY with the actual sysfs NUMA node; # never substitute a PCIe domain ordinal or invent a node when sysfs has none. if topo_slice.numa_node is not None: @@ -2349,6 +2396,13 @@ def build_cdi_spec( "freetpu.dev/optional-cap-add": "IPC_LOCK", "freetpu.dev/required-ulimit-memlock": "-1", } + if len(all_generations) == 1: + _all_meta = tpu_topology_metadata(all_generations[0]) + all_ann["freetpu.dev/chiplets-per-pkg"] = str(_all_meta["chiplets_per_pkg"]) + if _all_meta["hbm_gib_per_logical_device"] is not None: + all_ann["freetpu.dev/hbm-gib-per-logical-device"] = str( + _all_meta["hbm_gib_per_logical_device"] + ) if len(chips) != all_complete_chips or all_incomplete_fns > 0: all_ann["freetpu.dev/pci-function-count"] = str(len(chips)) if all_incomplete_fns > 0: diff --git a/ops/tpu-cdi/test_freetpu_cdi.py b/ops/tpu-cdi/test_freetpu_cdi.py index 602878fb..244041ec 100755 --- a/ops/tpu-cdi/test_freetpu_cdi.py +++ b/ops/tpu-cdi/test_freetpu_cdi.py @@ -6580,6 +6580,56 @@ def _fake_mono() -> float: for d_rec in all_devs: self.assertIn(d_rec["bdf"], obs_ann) + def test_tpu7x_dual_chiplet_topology_metadata(self) -> None: + # Issue #21: tpu7x Ironwood exposes 8 logical devices (2 chiplets per + # 192 GiB package) x 96 GiB HBM3e each. 0x1ae0:0x0075 is provisional + # pending Day-1 `lspci -nn` capture. + self.assertEqual(freetpu_cdi.TPU_PCI_DEVICES["0x0075"][0], "tpu7x") + self.assertEqual(freetpu_cdi.TPU_PCI_DEVICES["0x0076"][0], "tpu7x") + self.assertEqual(freetpu_cdi.TPU_CHIPLETS_PER_PKG["tpu7x"], 2) + self.assertEqual(freetpu_cdi.TPU_HBM_GIB_PER_LOGICAL_DEVICE["tpu7x"], 96) + self.assertEqual( + freetpu_cdi.tpu_topology_metadata("tpu7x"), + {"chiplets_per_pkg": 2, "hbm_gib_per_logical_device": 96}, + ) + # Single-chiplet generations default to 1. + self.assertEqual(freetpu_cdi.tpu_topology_metadata("v6e")["chiplets_per_pkg"], 1) + + with tempfile.TemporaryDirectory() as tmp: + root = Path(tmp) + devices = [ + { + "bdf": f"0000:00:0{4 + (i // 2):x}.{i % 2}", + "vendor": "0x1ae0", + "device": "0x0075", + "driver": "vfio-pci", + "iommu_group": str(i), + } + for i in range(4) + ] + sysfs_root, dev_root = _make_mock_pci_vfio( + root, + devices=devices, + create_vfio_nodes=[str(i) for i in range(4)], + ) + with _mock_vfio_char_devices(): + chips, ctrl = freetpu_cdi.discover_tpu_chips( + sysfs_root=sysfs_root, dev_root=dev_root + ) + self.assertEqual(len(chips), 4) + self.assertTrue(all(c.generation == "tpu7x" for c in chips)) + spec = freetpu_cdi.build_cdi_spec(chips, ctrl) + self.assertEqual(freetpu_cdi.validate_cdi_spec(spec), []) + by_name = {d["name"]: d for d in spec["devices"]} + pci_sel = by_name["pci-0000-00-04-0"] + self.assertEqual(pci_sel["annotations"]["freetpu.dev/chiplets-per-pkg"], "2") + self.assertEqual( + pci_sel["annotations"]["freetpu.dev/hbm-gib-per-logical-device"], "96" + ) + all_ann = by_name["all"]["annotations"] + self.assertEqual(all_ann["freetpu.dev/chiplets-per-pkg"], "2") + self.assertEqual(all_ann["freetpu.dev/hbm-gib-per-logical-device"], "96") + if __name__ == "__main__": unittest.main() diff --git a/ops/tpu-exporter/test_tpu_exporter.py b/ops/tpu-exporter/test_tpu_exporter.py index 4746a25c..2a856a38 100755 --- a/ops/tpu-exporter/test_tpu_exporter.py +++ b/ops/tpu-exporter/test_tpu_exporter.py @@ -7244,6 +7244,19 @@ def _run_with_pypath(cmd: list[str], *, timeout_s: float) -> subprocess.Complete f"Duty RPC timeout must subtract startup+import time from parent deadline: {seen_t}", ) + def test_tpu7x_dual_chiplet_topology_metadata(self) -> None: + # Issue #21: tpu7x Ironwood exposes 8 logical devices (2 chiplets per + # 192 GiB package) x 96 GiB HBM3e each. 0x1ae0:0x0075 is provisional + # pending Day-1 `lspci -nn` capture. + self.assertEqual(tpu_exporter.TPU_PCI_DEVICES["0x0075"][0], "tpu7x") + self.assertEqual(tpu_exporter.TPU_PCI_DEVICES["0x0076"][0], "tpu7x") + self.assertEqual(tpu_exporter.TPU_PCI_DEVICES["0x0075"][2], 96 * 1024**3) + self.assertEqual(tpu_exporter.TPU_PCI_DEVICES["0x0076"][2], 96 * 1024**3) + self.assertEqual(tpu_exporter.TPU_CHIPLETS_PER_PKG["tpu7x"], 2) + self.assertEqual(tpu_exporter.TPU_HBM_GIB_PER_LOGICAL_DEVICE["tpu7x"], 96) + self.assertEqual(tpu_exporter.TPU_CHIPLETS_PER_PKG["v6e"], 1) + self.assertEqual(tpu_exporter.TPU_HBM_GIB_PER_LOGICAL_DEVICE["v6e"], 32) + def _assert_valid_prometheus_text(self, text: str) -> None: lines = [ln for ln in text.splitlines() if ln.strip()] self.assertGreater(len(lines), 0) diff --git a/ops/tpu-exporter/tpu_exporter.py b/ops/tpu-exporter/tpu_exporter.py index 8e5de33a..e68b4cce 100755 --- a/ops/tpu-exporter/tpu_exporter.py +++ b/ops/tpu-exporter/tpu_exporter.py @@ -255,6 +255,23 @@ def _parse_bytes(value_str: str, unit_str: str) -> int: "tpu7x": 2, } +# Dual-chiplet topology metadata per generation (Issue #21, Ironwood Day-1): +# `chiplets_per_pkg` = logical TensorCore chiplets per physical package (2 on +# tpu7x Ironwood: 4 packages x 2 chiplets = 8 logical devices on +# `tpu7x-standard-4t`); `hbm_gib_per_logical_device` = HBM3e GiB per logical +# device (96 GiB on tpu7x). `0x1ae0:0x0075` is provisional pending Day-1 +# `lspci -nn` capture. +TPU_CHIPLETS_PER_PKG: Dict[str, int] = dict(_GEN_DEVICES_PER_CHIP) +TPU_HBM_GIB_PER_LOGICAL_DEVICE: Dict[str, int] = { + "tpu7x": 96, + "v5e": 16, + "v6e": 32, + "v6e-pf": 32, + "v5p": 95, + "v4": 32, + "v4lite": 8, +} + def _read_fdinfo_flags(fdinfo_path: Path) -> Tuple[Optional[int], bool]: """Read octal open `flags:` from `/proc//fdinfo/`. From 26ec5d86389f8481e68a064f6297e19ec95e5eb2 Mon Sep 17 00:00:00 2001 From: Ryan S <159389674+saariuslystoned@users.noreply.github.com> Date: Sun, 29 Nov 2026 08:58:37 -0500 Subject: [PATCH 2/2] harden(freetpu-47): adversarial red-team sanitizer stress, fuzz & hardening - parse_hex_u64: require *end==\0 (fail-closed on trailing junk e.g. 0x75JUNK) - ot_pjrt_client_create: guard zero/absurd pci/chiplet dims, overflow check on pci_funcs*chiplets_per_func, enforce total_logical <=64, double check for mock & live paths - freetpu_cdi.tpu_topology_metadata: fail-closed on non-str/unhashable gens (None/int/list/dict), correct Optional[int] hint, add PEP8 blank line - build_cdi_spec: emit chiplets-per-pkg/hbm for homogeneous shared-iommu-group selectors (Ironwood dual-chiplet gap), keep mixed-generation suppression - No public-roads violations; ASan+UBSan clean; all Python tests pass --- libopentpu/src/ot_pjrt.cpp | 18 ++++++++++++++++++ libopentpu/src/ot_vfio.cpp | 2 +- ops/tpu-cdi/freetpu_cdi.py | 31 ++++++++++++++++++++++++------- 3 files changed, 43 insertions(+), 8 deletions(-) diff --git a/libopentpu/src/ot_pjrt.cpp b/libopentpu/src/ot_pjrt.cpp index fcce2487..277d3420 100644 --- a/libopentpu/src/ot_pjrt.cpp +++ b/libopentpu/src/ot_pjrt.cpp @@ -1260,9 +1260,27 @@ PJRT_Error* ot_pjrt_client_create(PJRT_Client_Create_Args* args) { chiplets_per_func = mock_geom.logical_chiplets_per_pci_func > 0 ? mock_geom.logical_chiplets_per_pci_func : 1u; } + // Fail closed on any zero or absurd topology derived from hostile env/geometry. + if (pci_funcs == 0 || chiplets_per_func == 0) { + return make_err(PJRT_Error_Code_INTERNAL, "invalid mock topology: zero pci/chiplet count"); + } + if (pci_funcs > 64u || chiplets_per_func > 64u) { + return make_err(PJRT_Error_Code_INTERNAL, "invalid mock topology: exceeds sanity bound"); + } } + if (pci_funcs == 0 || chiplets_per_func == 0 || pci_funcs > 64u || + chiplets_per_func > 64u) { + return make_err(PJRT_Error_Code_INTERNAL, "invalid topology dimensions"); + } + // Overflow guard: total_logical = pci_funcs * chiplets_per_func must not wrap size_t. + if (chiplets_per_func != 0 && (pci_funcs > (std::numeric_limits::max() / chiplets_per_func))) { + return make_err(PJRT_Error_Code_INTERNAL, "mock topology size overflow"); + } const size_t total_logical = pci_funcs * chiplets_per_func; + if (total_logical == 0 || total_logical > 64u) { + return make_err(PJRT_Error_Code_INTERNAL, "mock topology logical device count out of range"); + } std::vector selected_ids; if (has_visible_devs) { selected_ids.reserve(visible_devs.size()); diff --git a/libopentpu/src/ot_vfio.cpp b/libopentpu/src/ot_vfio.cpp index 8f0fec6f..848d89ad 100644 --- a/libopentpu/src/ot_vfio.cpp +++ b/libopentpu/src/ot_vfio.cpp @@ -27,7 +27,7 @@ bool parse_hex_u64(const std::string& text, uint64_t* out) { char* end = nullptr; errno = 0; unsigned long long v = std::strtoull(text.c_str(), &end, 0); - if (errno != 0 || end == text.c_str()) return false; + if (errno != 0 || end == text.c_str() || (end && *end != '\0')) return false; *out = static_cast(v); return true; } diff --git a/ops/tpu-cdi/freetpu_cdi.py b/ops/tpu-cdi/freetpu_cdi.py index eb38a247..f0ce9ba0 100755 --- a/ops/tpu-cdi/freetpu_cdi.py +++ b/ops/tpu-cdi/freetpu_cdi.py @@ -134,18 +134,27 @@ } -def tpu_topology_metadata(generation: str) -> Dict[str, int]: +def tpu_topology_metadata(generation: object) -> Dict[str, Optional[int]]: """Return `{'chiplets_per_pkg': int, 'hbm_gib_per_logical_device': int|None}`.""" + # Fail-closed: any non-str or unhashable generation defaults to 1/None. + if not isinstance(generation, str): + return {"chiplets_per_pkg": 1, "hbm_gib_per_logical_device": None} gen = generation - chiplets = ( - _PCI_FUNCTIONS_PER_PHYSICAL_CHIP.get(gen, 1) - if gen in _PCI_FUNCTIONS_PER_PHYSICAL_CHIP - else TPU_CHIPLETS_PER_PKG.get(gen, 1) - ) + try: + chiplets = ( + _PCI_FUNCTIONS_PER_PHYSICAL_CHIP.get(gen, 1) + if gen in _PCI_FUNCTIONS_PER_PHYSICAL_CHIP + else TPU_CHIPLETS_PER_PKG.get(gen, 1) + ) + hbm = TPU_HBM_GIB_PER_LOGICAL_DEVICE.get(gen) + except TypeError: + return {"chiplets_per_pkg": 1, "hbm_gib_per_logical_device": None} return { "chiplets_per_pkg": chiplets, - "hbm_gib_per_logical_device": TPU_HBM_GIB_PER_LOGICAL_DEVICE.get(gen), + "hbm_gib_per_logical_device": hbm, } + + _SYSFS_PCI_ROOT_RE = re.compile(r"^pci([0-9a-fA-F]{4,}:[0-9a-fA-F]{2})\Z") _ALLOWED_HOOK_NAMES = frozenset( { @@ -2229,6 +2238,14 @@ def build_cdi_spec( only_numa = next(iter(unit_numas)) if only_numa is not None: ann["freetpu.dev/numa-node"] = str(only_numa) + # Emit topology metadata for homogeneous shared groups (Ironwood dual-chiplet). + if len(set(unit_gens)) == 1: + _shared_meta = tpu_topology_metadata(unit_gens[0]) + ann["freetpu.dev/chiplets-per-pkg"] = str(_shared_meta["chiplets_per_pkg"]) + if _shared_meta["hbm_gib_per_logical_device"] is not None: + ann["freetpu.dev/hbm-gib-per-logical-device"] = str( + _shared_meta["hbm_gib_per_logical_device"] + ) if devnums_str: ann["freetpu.dev/vfio-devnums"] = devnums_str devices.append(