Repository navigation
Commit 11a2109
committed
[PyBindings] Reject host buffers for device inputs, release the GIL during device waits, and wait for every output
Three problems remained in the Python bindings for methods whose inputs or
outputs live on a CUDA device.
A NumPy array or another host buffer passed for an input that the method
expects on the device was accepted, and the method then read a host pointer
as device memory. Torch tensors and DLPack inputs were already checked. Now a
non-empty buffer is rejected the same way, with the same message:
"Input 0 of method 'forward' is on device cpu, but the method expects cuda:0".
Every wait for the device held the GIL, so all other Python threads stopped
until the device finished all its queued work. CUDA-enabled bindings now
release the GIL around cudaDeviceSynchronize, when the calling thread holds
it. The fallback that waits through torch keeps the GIL.
Before a run, the bindings wait in case another library is still reading the
memory of an output from an earlier run. That wait covered only outputs in
memory the bindings allocated, and a Module call passed no outputs at all.
Now it covers the device of every non-empty tensor output, for Method and
Module, including memory-planned outputs and inputs the method returns.
Input errors now name the input and method the same way: a DLPack device
mismatch names both devices, a changed storage no longer tells Module users
to call set_inputs(), an error while choosing how to read an input gets the
name too, and a Method checks the input count before it reads any input.
The README now says that each wait is for the whole device, that the GIL is
released during it, and what a wait costs on an idle device. It also says
that returning CUDA outputs without a copy needs
MemoryPlanningPass(alloc_graph_output=False).1 parent ab3bc3d commit 11a2109
7 files changed
Lines changed: 286 additions & 162 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
48 | | - | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
49 | 51 | | |
50 | 52 | | |
51 | 53 | | |
| |||
105 | 107 | | |
106 | 108 | | |
107 | 109 | | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
120 | 128 | | |
121 | 129 | | |
122 | 130 | | |
| |||
0 commit comments