Repository navigation
Commit 7479760
committed
[PyBindings] Reject host buffers for device inputs, wait for every tensor of a run, and name input errors consistently
Follow-up to the device wait rework in the Python bindings.
A NumPy array or another host buffer passed for an input that the method
expects on a CUDA 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, before any host layout work, and
the message says how to pass device memory instead.
Before a run, the bindings wait in case another library still uses the
memory of an input, or of an output from an earlier run. That wait covered
only outputs in memory the bindings allocated, and a Module call covered no
outputs at all, so a memory-planned output could be overwritten while
another library was still reading it. After a run, only outputs were waited
for, although a method may update an input in place. Now one helper waits,
before and after each run, for every device that holds a non-empty tensor
input or output of the method.
Input errors now name the input and method the same way: a DLPack device
mismatch names both devices; a changed input storage, in both the borrow
check and the aliased torch output, says to pass the input again instead of
calling set_inputs(); a wrong number or an error while choosing how to read
an input gets the name; and a Method checks the input count before it reads
any input. A Module call now looks its method up once.
The README says that each wait is for the whole device, that it holds the
GIL in CUDA-enabled bindings, how short a wait is on an idle device, that CUDA outputs come back without
a copy only with MemoryPlanningPass(alloc_graph_output=False), and what a
planned CUDA output costs with clone_outputs=True.1 parent a39d597 commit 7479760
7 files changed
Lines changed: 316 additions & 212 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
48 | | - | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
49 | 55 | | |
50 | 56 | | |
51 | 57 | | |
| |||
105 | 111 | | |
106 | 112 | | |
107 | 113 | | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
120 | 136 | | |
121 | 137 | | |
122 | 138 | | |
| |||
0 commit comments