Repository navigation
Commit 9868f97
committed
[PyBindings] Wait for the device instead of per-result flags, and fix bfloat16 result layout and input errors
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. Whether
another library might still be writing that memory was tracked 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 data from before
that write.
The flags are gone. Before a call runs, it now waits once for each device that
holds one of its CUDA inputs, including results of these bindings. A method
also waits for the device of each output buffer it writes again, because
another library may still be reading a dropped result that used it. After the
call runs, it waits once for each device that holds an output, as before.
Handing a CUDA result to another library through __dlpack__ or to_host() always
waits too. 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 now always takes the DLPack path,
which keeps its real dtype, shape and strides. A bfloat16 result used to take
the buffer path, whose flat bytes were read in the method's layout, so a result
in another dim order came back permuted with no error. A bfloat16 result now
also keeps its own shape instead of taking the method's.
A failed device allocation no longer turns off the no-copy output return for
the rest of a method's life, because the new buffer is allocated into a local
first. A clone_outputs=False read is now its own borrowed view, not the object
a default read handed over.
An error raised while reading an input keeps its Python type. A Python
exception gets the input and method as a note instead of being rebuilt, which
failed for types such as UnicodeDecodeError. C++ runtime errors, the device
checks and the unsupported-type error name the input and method in their
message, and std::bad_alloc still becomes MemoryError.1 parent b1beef3 commit 9868f97
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