Repository navigation
Commit ab3bc3d
authored
[PyBindings] Wait for the device instead of per-result flags, and fix bfloat16 result layout and input errors (#23999)
Follow-up to the Python bindings change that added torch-free execution
and device memory support.
## What was wrong
A CUDA result borrowed from a method, through
`get_outputs(clone_outputs=False)` or a method that returns its own
input, shares the method's memory. The bindings tracked "might another
library still be writing this?" with a flag on each result object, and
every borrowed result started with a fresh flag. So when another library
wrote the memory through one result, and a second view of the same
memory was passed back in, the call could read the old data.
A bfloat16 result on the host, passed back in, was read in the method's
layout instead of its own. A result in another dim order came back
permuted, with no error.
## What this changes
The flags are replaced by device waits. Before a call runs, it waits
once per device for its CUDA inputs, including results of these
bindings. A method also waits for the device of an output buffer it
writes again, since another library may still be reading a dropped
result there. After a call, it waits once per output device.
`__dlpack__` and `to_host()` on a CUDA result always wait. In bindings
built without CUDA, `__dlpack__` now waits through torch, as calls
already do, instead of failing.
A result of these bindings passed back in always takes the DLPack path,
which keeps its dtype, shape and strides. This fixes the bfloat16 layout
bug, and a bfloat16 result now keeps its own shape instead of taking the
method's.
A failed device allocation no longer turns off the no-copy output
return. A `clone_outputs=False` read is now its own borrowed view.
An error raised while reading an input keeps its Python type. A Python
exception gets the input and method as a note, and C++ errors name them
in the message.
The torch-free CI job now also builds a channels-last bfloat16 program,
so the layout test runs there.
## Tested
On Linux x86_64 with H100 GPUs, built the bindings with CUDA, without
CUDA, and as the standalone torch-free module. Ran
`test_pybindings_cuda_dlpack.py`, `test_pybindings_no_aten.py`,
`test_pybindings.py` and `runtime/test/test_runtime.py` in both output
modes. Every failure there also fails without this change: tests written
for the other output mode, two quantized-op tests whose kernels are not
registered here, and three subprocess tests that need the CUDA runtime
library outside torch. Each new or changed test fails with its fix
removed.1 parent cf8d91e commit ab3bc3d
9 files changed
Lines changed: 321 additions & 227 deletions
File tree
- .github/workflows
- extension/pybindings
- test
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
182 | 182 | | |
183 | 183 | | |
184 | 184 | | |
| 185 | + | |
185 | 186 | | |
186 | 187 | | |
187 | 188 | | |
188 | 189 | | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
189 | 194 | | |
190 | 195 | | |
191 | 196 | | |
| |||
205 | 210 | | |
206 | 211 | | |
207 | 212 | | |
| 213 | + | |
208 | 214 | | |
209 | 215 | | |
210 | 216 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
54 | 56 | | |
55 | 57 | | |
56 | 58 | | |
| |||
99 | 101 | | |
100 | 102 | | |
101 | 103 | | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
111 | 120 | | |
112 | 121 | | |
113 | 122 | | |
114 | 123 | | |
115 | | - | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
116 | 127 | | |
117 | 128 | | |
118 | 129 | | |
| |||
0 commit comments