Commit e92f0a2
committed
Fix TPU7x chip counting to account for chiplet architecture
For TPU7x devices, each physical chip contains 2 chiplets that are
exposed to the host as separate devices. The previous
implementation counted these devices directly, resulting in 2x the
actual chip count being reported.
Example of the issue:
- tpu7x-8 has 4 physical chips with 8 chiplets total
- Previous behavior: reported num_chips=8 (incorrect)
- Fixed behavior: reports num_chips=4 (correct)
Changes:
- Add get_num_chiplets_per_chip() helper function that returns 2 for
tpu7x devices and 1 for all other TPU types, following the same
pattern as get_num_cores_per_chip()
- Modify get_num_chips() to divide device count by chiplets_per_chip
using integer division
- Update logging to conditionally show chiplets_per_chip for tpu7x
devices only (non-tpu7x devices don't have chiplets, so we avoid
showing confusing information)
- Add comprehensive tests for tpu7x chip counting scenarios
- Update existing get_num_chips() tests to mock get_tpu_type() since
the function now calls it
Test coverage:
- test_get_num_chiplets_per_chip: Tests tpu7x variants, other TPU
types, and edge cases (None, empty string)
- test_get_num_chips_tpu7x_from_accel: Tests tpu7x-8 with /dev/accel*
- test_get_num_chips_tpu7x_4_from_accel: Tests tpu7x-4 with /dev/accel*
- test_get_num_chips_tpu7x_from_vfio: Tests tpu7x-8 with /dev/vfio
- test_get_num_chips_non_tpu7x_unchanged: Verifies backward compatibility
Backward compatibility:
All non-tpu7x devices return chiplets_per_chip=1, making the division
a no-op. Behavior is identical to before the fix.
Signed-off-by: burbajr <[email protected]>1 parent 0d4a4d1 commit e92f0a2
3 files changed
+122
-9
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
9 | | - | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
| |||
98 | 99 | | |
99 | 100 | | |
100 | 101 | | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
101 | 122 | | |
| 123 | + | |
102 | 124 | | |
103 | 125 | | |
104 | | - | |
| 126 | + | |
105 | 127 | | |
106 | 128 | | |
107 | 129 | | |
108 | 130 | | |
| 131 | + | |
109 | 132 | | |
110 | 133 | | |
111 | | - | |
| 134 | + | |
112 | 135 | | |
113 | 136 | | |
114 | 137 | | |
115 | 138 | | |
| 139 | + | |
116 | 140 | | |
117 | 141 | | |
118 | | - | |
| 142 | + | |
| 143 | + | |
119 | 144 | | |
120 | 145 | | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
45 | 50 | | |
46 | | - | |
| 51 | + | |
47 | 52 | | |
48 | | - | |
| 53 | + | |
49 | 54 | | |
50 | 55 | | |
51 | 56 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
63 | 63 | | |
64 | 64 | | |
65 | 65 | | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
66 | 82 | | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
67 | 92 | | |
68 | 93 | | |
69 | | - | |
| 94 | + | |
70 | 95 | | |
71 | 96 | | |
72 | 97 | | |
73 | 98 | | |
74 | 99 | | |
75 | | - | |
| 100 | + | |
76 | 101 | | |
77 | 102 | | |
78 | 103 | | |
0 commit comments