Skip to content

[Feature] Add defensive assertion for DLPack device_id #920

@viiccwen

Description

@viiccwen

Summary

In qdp/qdp-python/src/lib.rs, the CUDA tensor device is validated in two places:

  • Via PyTorch APIs in validate_cuda_tensor_for_encoding(...), which checks that the tensor device matches QdpEngine’s device.
  • Via DLPack metadata inside extract_dlpack_tensor(...), which reads dl_tensor.device.device_id from the DLManagedTensor.

Currently, there is no check that these two views of the device ID are consistent. If, for any reason (framework bug, interop change, or misuse), the PyTorch-validated device ID diverges from the DLPack device_id, this could lead to hard‑to‑debug failures (e.g., using memory from the wrong device).

reference: comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions