Repository navigation
Commit c1d7efb
authored
[PyBindings] Fix wrong results for inputs in another layout, refuse stale or mixed state, return CUDA outputs without copies (#23957)
## What is wrong today
- An input in another dimension order, such as a transposed array, is
silently read as contiguous.
- After `set_inputs()` fails partway, `execute()` runs on a mix of new
and old inputs (#23913), and
before any `set_inputs()` it reads unset inputs. Modules have the same
problems.
- A module reads freed memory once its program bytes are dropped.
- Every CUDA output is copied once more before it is returned.
- Without torch, CUDA results cannot reach the host.
## What this change does
- The portable bindings copy an input in another dimension order into
the exported order, on the host
for buffers, on the device for torch tensors. Other CUDA DLPack inputs
in another order raise.
ATen bindings still read them as they are.
```python
method.set_inputs([array.T]) # was read as contiguous, now copied first
```
- `execute()` raises before the first `set_inputs()`, and after one that
failed partway, until every
input is passed again; a wrong count or dtype keeps the old inputs.
`get_outputs()` raises after
`set_inputs()` until `execute()` succeeds. Modules do the same.
- Modules keep their program bytes.
- With `clone_outputs=True` (the default), a CUDA output filling memory
the bindings allocated is
returned without a copy. While it lives, a method's next call uses a
second buffer, then the two
take turns.
- A call waits for the device once after it runs, and before it runs
only when an input may still be
written on another library's stream.
- `ExecuTorchResult` gains `to_host()`, `from_host()`, `dtype_name`, and
a `repr`, and is exported from
`executorch.runtime`.
- Buffers accept complex numbers and a native byte-order prefix, CUDA
DLPack inputs work on any GPU,
and number inputs take NumPy numbers and must match the declared kind
(an `int` works for a float).
Input errors name the input and method.
The state checks and input formats apply to both portable and ATen
bindings.
## Testing
New tests for each fixed problem fail without this change. The CUDA
tests pass in both output modes
on four GPUs (CI has one, so the multi-GPU test skips there). The
portable suites pass, except two
quantized tests that also fail without it.
On a chain of 8 outputs on one GPU, a median call takes 0.37 ms, not
0.43 ms, with `Method`, and
0.31 ms, not 0.59 ms, with `Module` (5 runs of 200 calls).
Fixes #23913.1 parent 450cc5d commit c1d7efb
11 files changed
Lines changed: 2674 additions & 363 deletions
File tree
- docs/source
- extension/pybindings
- test
- runtime
- test
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
| 14 | + | |
| 15 | + | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
20 | | - | |
21 | | - | |
22 | | - | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
23 | 35 | | |
24 | 36 | | |
25 | 37 | | |
| |||
28 | 40 | | |
29 | 41 | | |
30 | 42 | | |
31 | | - | |
32 | | - | |
33 | | - | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
34 | 57 | | |
35 | 58 | | |
36 | | - | |
37 | | - | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
38 | 62 | | |
39 | 63 | | |
40 | 64 | | |
| |||
63 | 87 | | |
64 | 88 | | |
65 | 89 | | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
66 | 102 | | |
67 | 103 | | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
72 | 111 | | |
73 | 112 | | |
74 | 113 | | |
| |||
87 | 126 | | |
88 | 127 | | |
89 | 128 | | |
90 | | - | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
91 | 133 | | |
92 | 134 | | |
93 | 135 | | |
| |||
0 commit comments