Commit 237e6b6
committed
feat(path_c): device-resident DPS driver — eliminate the per-step host numpy bounce
Rework the physical-bank DPS driver so the banks stay tvm.cuda(0) device
nd-arrays end-to-end in the forward, removing the numpy host round-trip that
was ~96.9% of the Relax-graph train_step wall (docs/RELAX-GRAPH-VS-MEGATRON §4).
path_c_dps_adapter.py:
- device_bank_view / device_pack / device_unpack: zero-copy device sub-range
slicing via Tensor._create_view(byte_offset) + device->device copyto (no numpy).
- alloc_device_banks: banks via tvm.runtime.empty on device, zeroed once, reused.
- make_device_resident_kernel_driver: builds the kernel arg list once (5 device
banks + curried run_backward + device-resident zero scratch), per call runs
kernel(*args)+sync; kernel mutates banks in place at out_idx (nothing to read back).
- make_region_dps_packed._packed routes by output DLPack device type
(__dlpack_device__()[0] != kDLCPU): device VM -> device-resident path, CPU VM ->
numpy reference (clear device-vs-host gate, not a try/except fallback).
- make_real_kernel_driver kept as the numpy-staged reference (CPU self-test + equiv).
path_c_relax_step_banks.py:
- bank_arg_is_device (DLPack-device gate at the VM boundary), bank_copy_prefix_device
(device->device prefix copy + device tail-zero), _zero_device_tensor (device-zero
buffer cache; only first fill per (shape,dtype,device) touches host).
path_c_relax_train_step.py:
- make_real_bank_forward_driver(device=dev): device-resident forward — seeds the
kernel act/param banks via device->device view copies, runs the device-resident
kernel in place, fills act_out/state_out device-side. No .numpy() at the VM
boundary in the forward.
Validated on gb10 tvm.cuda(0), REAL MR JITKernel
(scratch/pr7_device_resident_driver_validate_gb10.py):
(A) numeric equivalence device-resident vs numpy-staged: max|dev-numpy|=1.025e-06.
(B) whole train_step runs e2e on CUDA, loss finite (5.525e-06, 2L x 3 steps).
(C) per-forward-call 8472ms -> 6515ms = 1.30x (matches scout ceiling for this
single-launch MR kernel; the larger lever is the removed VM-boundary host
round-trip of the full 2028 MB banks per forward+remat region per step).
bwd/adam/loss remain the abstract numpy drivers (lever 4); forward+remat is now
device-resident. Forward/remat region fusion deferred.1 parent 04271e3 commit 237e6b6
8 files changed
Lines changed: 1436 additions & 73 deletions
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
141 | 141 | | |
142 | 142 | | |
143 | 143 | | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
144 | 163 | | |
145 | | - | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
146 | 170 | | |
147 | 171 | | |
148 | 172 | | |
| |||
155 | 179 | | |
156 | 180 | | |
157 | 181 | | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
158 | 227 | | |
159 | 228 | | |
160 | 229 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
71 | 71 | | |
72 | 72 | | |
73 | 73 | | |
| 74 | + | |
74 | 75 | | |
| 76 | + | |
75 | 77 | | |
76 | 78 | | |
77 | 79 | | |
78 | 80 | | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
79 | 85 | | |
80 | 86 | | |
81 | 87 | | |
| |||
126 | 132 | | |
127 | 133 | | |
128 | 134 | | |
129 | | - | |
| 135 | + | |
| 136 | + | |
130 | 137 | | |
131 | 138 | | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
137 | 158 | | |
138 | 159 | | |
139 | 160 | | |
140 | 161 | | |
141 | 162 | | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
142 | 173 | | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
143 | 203 | | |
144 | 204 | | |
145 | 205 | | |
146 | 206 | | |
147 | | - | |
148 | | - | |
149 | 207 | | |
150 | 208 | | |
151 | 209 | | |
| |||
161 | 219 | | |
162 | 220 | | |
163 | 221 | | |
164 | | - | |
165 | 222 | | |
166 | 223 | | |
167 | | - | |
168 | 224 | | |
169 | | - | |
170 | 225 | | |
171 | 226 | | |
172 | 227 | | |
| |||
176 | 231 | | |
177 | 232 | | |
178 | 233 | | |
179 | | - | |
| 234 | + | |
180 | 235 | | |
181 | 236 | | |
182 | 237 | | |
183 | 238 | | |
184 | 239 | | |
185 | 240 | | |
186 | | - | |
187 | | - | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
188 | 245 | | |
189 | 246 | | |
190 | 247 | | |
| |||
0 commit comments