Commit 20d271a
Fix TPU time measurements in
The current code uses the time difference between the completions of two `_squareit()` calls to measure the TPU time spent in yield. But the two calls to `_squareit()` are started on a worker thread and are not synchronized with the calling thread.
```
with report.timed('foobar'):
tpu_fn() # <- this can slip in before start_measurement()
tpu_fn() # <- this can slip in before stop_measurement()
```
To guarantee that the TPU programs are dispatched in the right order we need to dispatch them on the main thread. `block_until_ready()` is still called on the WorkerThread so the main thread isn't blocked.
Drive-by changes:
- Split the two code paths (`wait_jax_async_dispatch`) as they share even less common code now.
- No longer launder variables through `_time_per_thread`. Instead pass the start time in a future.
PiperOrigin-RevId: 538146372PeriodicAction.timed().1 parent dd4af73 commit 20d271a
1 file changed
+32
-24
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | | - | |
23 | 22 | | |
24 | 23 | | |
25 | 24 | | |
| |||
46 | 45 | | |
47 | 46 | | |
48 | 47 | | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | 48 | | |
60 | 49 | | |
61 | 50 | | |
| |||
197 | 186 | | |
198 | 187 | | |
199 | 188 | | |
200 | | - | |
201 | 189 | | |
202 | 190 | | |
203 | 191 | | |
| |||
269 | 257 | | |
270 | 258 | | |
271 | 259 | | |
272 | | - | |
273 | | - | |
274 | | - | |
275 | | - | |
276 | | - | |
277 | | - | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
278 | 282 | | |
279 | 283 | | |
280 | | - | |
281 | | - | |
282 | | - | |
283 | | - | |
284 | | - | |
285 | | - | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
286 | 294 | | |
287 | 295 | | |
288 | 296 | | |
| |||
0 commit comments