Skip to content

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.

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.

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.

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.

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)
  • Cites “CuPy documentation”, interoperability with PyTorch and the CUDA Array Interface. Open reference
  • Cites “PyTorch documentation”, torch.as_tensor interoperability. Open reference
  • Cites “cuDF documentation”, CuPy interoperability guide. Open reference