Repository navigation
Commit ff4cf27
authored
Let TensorPtrMaker carry the device its buffer lives on (pytorch#21763)
TensorPtrMaker could express every property of a tensor except where its data resides.
make_tensor_ptr already takes a device as its last parameter, defaulting to CPU, and the
builder never passed one, so for_blob(...).make_tensor_ptr() always produced a CPU
labelled tensor.
A caller wrapping accelerator memory therefore got a tensor claiming to be on the host.
Nothing rejects that at the boundary, so the label is simply wrong, and whatever reads
it next acts on the wrong answer. For memory the host cannot address, that means the
host follows a pointer it must not.
The setter is unqualified, matching the five setters already on this builder, so a
caller can pick a device at run time and apply it to a named builder before finishing
it.
Test Plan: extension/tensor/test/tensor_ptr_maker_test.cpp gains four cases. The file
had no device coverage at all, which is why the missing setter went unnoticed.
ForBlobDefaultsToCPU the default is still CPU, so existing
callers are unaffected. Type only: the
default index is 0 in one build mode and -1
in the other
ForBlobCarriesTheDeviceItIsGiven an explicitly set device type and index
reach the tensor
ForBlobDeviceSurvivesLaterSetters a setter running after it does not drop it,
asserted with a non contiguous stride so the
case fails rather than passing for an
unrelated reason
ForBlobDeviceAcceptsANamedBuilder the run time choice above, which an rvalue
only qualifier would have rejected
Compiled and ran all four against the shipped headers on Linux x86_64. The wheel build
sets EXECUTORCH_BUILD_TESTS=OFF, so these do not run there; they run in the unit test
build. Three of the four do not compile without this change, no member named 'device', so they
are not vacuous. The default case is the exception: it only reads the accessor, which
already existed, and would compile against the old builder while reporting CPU.1 parent 1ebd320 commit ff4cf27
2 files changed
Lines changed: 71 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
92 | 92 | | |
93 | 93 | | |
94 | 94 | | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
95 | 111 | | |
96 | 112 | | |
97 | 113 | | |
| |||
106 | 122 | | |
107 | 123 | | |
108 | 124 | | |
109 | | - | |
| 125 | + | |
| 126 | + | |
110 | 127 | | |
111 | 128 | | |
112 | 129 | | |
| |||
141 | 158 | | |
142 | 159 | | |
143 | 160 | | |
| 161 | + | |
| 162 | + | |
144 | 163 | | |
145 | 164 | | |
146 | 165 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
506 | 506 | | |
507 | 507 | | |
508 | 508 | | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
0 commit comments