PY-PERF0001 · tensor_interoperability_round_trip_count
Find avoidable host, NumPy, or explicit DLPack tensor round trips.
This is a deterministic rule for python. Read its implementation.
Definition
Section titled “Definition”Resolve explicit Torch, CuPy, and RAPIDS import aliases. Report a recognized destination call
only when its argument syntax proves an intermediate cpu, numpy, asnumpy, to_pandas, or
explicit to_dlpack conversion from another supported tensor ecosystem. These libraries expose
direct CUDA array or DLPack interoperability, so application code should pass the device object
directly when the installed versions support that contract.
Evidence
Section titled “Evidence”Each finding identifies the complete destination call and classifies the unnecessary bridge. The value is the number of destination calls fed through an avoidable host bridge.
Exceptions
Section titled “Exceptions”Unqualified constructors, unknown aliases, serialization, deliberate host ownership, device
changes, and a plain from_dlpack(value) call are excluded. A boundary may keep an explicit
bridge when version constraints or lifetime semantics require it.
Examples
Section titled “Examples”array = cp.asarray(tensor.cpu().numpy())tensor = torch.from_numpy(cp.asnumpy(array))array = cp.from_dlpack(torch.utils.dlpack.to_dlpack(tensor))array = cp.asarray(tensor)tensor = torch.as_tensor(array)References
Section titled “References”- Cites “CuPy documentation”, interoperability with PyTorch and the CUDA Array Interface. Open reference
- Cites “PyTorch documentation”,
torch.as_tensorinteroperability. Open reference - Cites “cuDF documentation”, CuPy interoperability guide. Open reference