File tree Expand file tree Collapse file tree 1 file changed +10
-3
lines changed
Expand file tree Collapse file tree 1 file changed +10
-3
lines changed Original file line number Diff line number Diff line change @@ -12,11 +12,18 @@ The ``pyobj_to_aten_handle`` trick exploits the internal layout of
1212
1313 struct THPVariable {
1414 PyObject_HEAD
15- MaybeOwned<at::Tensor> cdata; // <-- this IS the AtenTensorHandle
15+ at::Tensor cdata; // <-- &cdata is usable as AtenTensorHandle
16+ ...
1617 };
1718
18- Offsetting past ``PyObject_HEAD`` gives us the ``at::Tensor`` pointer
19- without any Python attribute access or method calls (~10 ns per tensor).
19+ In PyTorch 2.3–2.9 ``cdata`` was ``c10::MaybeOwned<at::Tensor>``;
20+ from 2.10 onward it is ``at::Tensor``. In both cases ``&cdata``
21+ (offset ``sizeof(PyObject)`` from the start of the object) is accepted
22+ by the AOTI stable C ABI functions as an ``AtenTensorHandle``.
23+
24+ Offsetting past ``PyObject_HEAD`` gives us the handle
25+ without any Python attribute access or method calls (~14 ns for all
26+ 7 metadata queries).
2027
2128Credit: Emilio Castillo (ecastillo@nvidia.com) – original tensor-bridge POC.
2229
You can’t perform that action at this time.
0 commit comments