Commit 6c815cd
committed
Offload cleanup (round 4): centralize validation at the payload parser
Net -288 lines. The trust-boundary architecture is now clean:
the payload parser in payload.h validates everything a downstream
consumer might want to know about a parsed Payload, and downstream
code (cuda_backend.cpp init, Session) just trusts the parsed struct.
Parser additions (payload.h):
* dtype allow-list (the supported set the runtime can elementSize +
H2D for). Rejects unknown / corrupt dtype codes before they can
truncate through the int8_t-backed ScalarType cast downstream.
* nbytes == element_size(dtype) * product(sizes) cross-field check
with overflow-aware multiplication. Catches schema drift in the
serializer.
* C-contiguous + offset-zero check (storage_offset == 0,
strides[i] == product(sizes[i+1..])). The host mirror is sized
for logical bytes and the H2D copy is dense, so any non-
contiguous layout would over- or under-read.
* pin_fqns dedup + pin_fqns subset-of schedule.
Downstream removals (session.cpp):
* logical_nbytes_for(): used info.storage_nbytes directly (the
parser already validated nbytes == elementSize * product).
* validate_scheduled_layout(): contiguity / storage_offset /
storage==logical all validated at parse.
* Per-FQN device_type / device_index single-device tracking
(parser hard-fails device_index != 0; session unconditionally
on device 0).
* Per-FQN catalog-lookup defensive error (use catalog.at()).
* pin_set_.insert duplicate check (parser dedups).
* pin_fqns subset-of validated check (parser enforces).
* pinned_bytes_total recompute loop + overflow check (now a
parameter into Session::create from init).
* required_total = floor + pinned overflow check (init resolves
the budget; the < required_total enforcement stays).
Downstream removals (cuda_backend.cpp init):
* pin_seen dedup loop (parser).
* device_index re-check on first metadata entry (parser).
* Per-FQN dtype allow-list + sizes-positive + logical_nbytes
overflow + payload-nbytes-vs-derived-logical cross-check
(parser owns all of these). KEPT the AOTI data_sizes[i] vs
payload nbytes check -- AOTI is the one genuinely independent
source of truth, and the two could drift if the .pte and .so
were built from different versions.
Downstream removals (weight_offload_pass.py):
* pin_fqns dedup loop in _apply_weight_offload (the partitioner
is the user-facing API; raw-spec test paths flow through the
parser which now dedups).
* Pruned the contiguity-check rationale to one line (Python int
can't overflow so no overflow comment).
API change: Session::create gains a uint64_t pinned_bytes_total
parameter (init computes it once and passes it in, instead of
session recomputing). The next round will fold this and several
other init-managed inputs into Session itself as the structural
refactor lands.
61 of 61 offload tests pass; lint clean.
Authored with Claude.1 parent 4a05736 commit 6c815cd
5 files changed
Lines changed: 128 additions & 416 deletions
File tree
- backends/cuda
- passes
- runtime
- weight_offload
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
702 | 702 | | |
703 | 703 | | |
704 | 704 | | |
705 | | - | |
706 | | - | |
707 | | - | |
708 | | - | |
709 | | - | |
710 | | - | |
711 | | - | |
712 | | - | |
713 | | - | |
714 | | - | |
715 | | - | |
716 | | - | |
| 705 | + | |
717 | 706 | | |
718 | 707 | | |
719 | 708 | | |
| |||
781 | 770 | | |
782 | 771 | | |
783 | 772 | | |
784 | | - | |
785 | | - | |
786 | | - | |
787 | | - | |
788 | | - | |
789 | | - | |
| 773 | + | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
790 | 777 | | |
791 | 778 | | |
792 | | - | |
| 779 | + | |
793 | 780 | | |
794 | | - | |
795 | | - | |
796 | | - | |
| 781 | + | |
797 | 782 | | |
798 | 783 | | |
799 | 784 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
430 | 430 | | |
431 | 431 | | |
432 | 432 | | |
433 | | - | |
434 | | - | |
435 | | - | |
436 | | - | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
437 | 438 | | |
438 | | - | |
439 | | - | |
440 | | - | |
441 | | - | |
442 | | - | |
443 | | - | |
444 | | - | |
445 | | - | |
446 | | - | |
447 | | - | |
448 | | - | |
449 | | - | |
450 | | - | |
451 | | - | |
452 | | - | |
453 | | - | |
454 | | - | |
455 | | - | |
456 | | - | |
457 | | - | |
458 | | - | |
459 | | - | |
460 | | - | |
461 | | - | |
462 | | - | |
463 | | - | |
464 | | - | |
465 | | - | |
466 | | - | |
467 | | - | |
468 | | - | |
469 | | - | |
470 | | - | |
471 | | - | |
472 | | - | |
473 | | - | |
474 | | - | |
475 | | - | |
476 | 439 | | |
477 | 440 | | |
478 | 441 | | |
| |||
876 | 839 | | |
877 | 840 | | |
878 | 841 | | |
| 842 | + | |
| 843 | + | |
| 844 | + | |
| 845 | + | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
879 | 849 | | |
880 | 850 | | |
881 | | - | |
882 | | - | |
883 | | - | |
884 | | - | |
885 | | - | |
886 | | - | |
887 | | - | |
888 | | - | |
889 | | - | |
890 | | - | |
891 | | - | |
892 | | - | |
893 | | - | |
894 | | - | |
895 | | - | |
896 | | - | |
897 | | - | |
898 | | - | |
899 | | - | |
900 | | - | |
901 | | - | |
902 | | - | |
903 | | - | |
904 | | - | |
905 | | - | |
906 | | - | |
907 | | - | |
908 | | - | |
909 | | - | |
910 | | - | |
911 | | - | |
912 | | - | |
913 | | - | |
914 | | - | |
915 | | - | |
916 | | - | |
917 | | - | |
918 | | - | |
919 | | - | |
920 | | - | |
921 | | - | |
922 | | - | |
923 | | - | |
924 | | - | |
925 | | - | |
926 | | - | |
927 | | - | |
928 | | - | |
929 | | - | |
930 | | - | |
931 | | - | |
932 | | - | |
933 | | - | |
934 | | - | |
935 | | - | |
936 | | - | |
937 | | - | |
938 | | - | |
939 | | - | |
940 | | - | |
941 | | - | |
942 | | - | |
943 | | - | |
944 | | - | |
945 | | - | |
946 | | - | |
947 | | - | |
948 | | - | |
949 | | - | |
950 | | - | |
951 | | - | |
952 | | - | |
953 | | - | |
954 | | - | |
955 | | - | |
956 | | - | |
957 | | - | |
958 | | - | |
959 | | - | |
960 | | - | |
961 | | - | |
962 | | - | |
963 | | - | |
| 851 | + | |
| 852 | + | |
964 | 853 | | |
965 | 854 | | |
966 | 855 | | |
967 | | - | |
| 856 | + | |
968 | 857 | | |
969 | 858 | | |
970 | | - | |
971 | | - | |
972 | | - | |
973 | | - | |
974 | | - | |
975 | | - | |
976 | | - | |
977 | | - | |
978 | | - | |
979 | | - | |
980 | | - | |
981 | | - | |
982 | | - | |
983 | | - | |
984 | | - | |
985 | | - | |
986 | | - | |
987 | | - | |
| 859 | + | |
988 | 860 | | |
989 | 861 | | |
990 | 862 | | |
| |||
1274 | 1146 | | |
1275 | 1147 | | |
1276 | 1148 | | |
| 1149 | + | |
1277 | 1150 | | |
1278 | 1151 | | |
1279 | 1152 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| 38 | + | |
38 | 39 | | |
| 40 | + | |
39 | 41 | | |
40 | 42 | | |
41 | 43 | | |
| |||
166 | 168 | | |
167 | 169 | | |
168 | 170 | | |
169 | | - | |
170 | | - | |
| 171 | + | |
| 172 | + | |
| 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 | + | |
171 | 201 | | |
172 | 202 | | |
173 | 203 | | |
174 | 204 | | |
175 | 205 | | |
176 | 206 | | |
177 | 207 | | |
178 | | - | |
179 | | - | |
180 | 208 | | |
181 | 209 | | |
182 | 210 | | |
183 | 211 | | |
184 | 212 | | |
185 | 213 | | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
186 | 218 | | |
187 | 219 | | |
188 | 220 | | |
| |||
191 | 223 | | |
192 | 224 | | |
193 | 225 | | |
| 226 | + | |
194 | 227 | | |
195 | 228 | | |
196 | 229 | | |
197 | 230 | | |
198 | | - | |
199 | | - | |
200 | | - | |
201 | | - | |
| 231 | + | |
| 232 | + | |
202 | 233 | | |
203 | 234 | | |
204 | 235 | | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
205 | 241 | | |
206 | 242 | | |
207 | 243 | | |
208 | 244 | | |
209 | 245 | | |
210 | 246 | | |
211 | 247 | | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
212 | 261 | | |
213 | 262 | | |
214 | 263 | | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
215 | 267 | | |
216 | 268 | | |
217 | 269 | | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
218 | 277 | | |
219 | 278 | | |
220 | 279 | | |
| |||
331 | 390 | | |
332 | 391 | | |
333 | 392 | | |
334 | | - | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
335 | 397 | | |
336 | 398 | | |
337 | 399 | | |
| |||
353 | 415 | | |
354 | 416 | | |
355 | 417 | | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
356 | 432 | | |
357 | 433 | | |
358 | 434 | | |
| |||
0 commit comments