{"record":{"id":"bcf1d39e294e7eb9","repo":"jax-ml/jax","slug":"dlpack-device-only-supported-for-cpu-gpu-and","errorCode":null,"errorMessage":"__dlpack__ device only supported for CPU, GPU and TPU pinned host, got platform: {self.platform()}","messagePattern":"__dlpack__ device only supported for CPU, GPU and TPU pinned host, got platform: (.+?)","errorType":"exception","errorClass":"BufferError","httpStatus":null,"severity":"error","filePath":"jax/_src/array.py","lineNumber":484,"sourceCode":"\n      return dl_device_type, local_hardware_id\n\n    elif self.platform() == \"tpu\":\n      if self.sharding.memory_kind == \"pinned_host\":\n        dl_device_type = DLDeviceType.kDLTPUHost\n      else:\n        raise BufferError(\n            \"__dlpack__ device only supported for TPU pinned host memory\"\n        )\n\n      local_hardware_id = _get_device(self).local_hardware_id\n      if local_hardware_id is None:\n        raise BufferError(\"Couldn't get local_hardware_id for __dlpack__\")\n\n      return dl_device_type, local_hardware_id\n\n    else:\n      raise BufferError(\n          \"__dlpack__ device only supported for CPU, GPU and TPU pinned host,\"\n          f\" got platform: {self.platform()}\"\n      )\n\n  def __reduce__(self):\n    fun, args, arr_state = self._value.__reduce__()\n    aval_state = {'weak_type': self.aval.weak_type}\n    return (_reconstruct_array, (fun, args, arr_state, aval_state))\n\n  @use_cpp_method()\n  def unsafe_buffer_pointer(self):\n    if len(self._arrays) != 1:\n      raise ValueError(\"unsafe_buffer_pointer() is supported only for unsharded\"\n                       \" arrays.\")\n    return self._arrays[0].unsafe_buffer_pointer()\n\n  @property\n  @use_cpp_method()","sourceCodeStart":466,"sourceCodeEnd":502,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/array.py#L466-L502","documentation":"jax.Array.__dlpack_device__ supports only CPU, GPU, and TPU (pinned host) platforms. Arrays on any other backend (e.g. plugin backends, or future/alternate XLA devices) trigger BufferError with the offending platform name included.","triggerScenarios":"Calling from_dlpack consumers on an array whose x.platform() is not 'cpu', 'cuda'/'rocm'/'oneapi' variants, or 'tpu' — e.g. IPU/Metal/plugin backends or custom XLA devices.","commonSituations":"Using jax with third-party plugin backends (ipu, metal, etc.) and attempting DLPack interop with torch/numpy; experimental backends where DLPack was never implemented.","solutions":["Transfer through host memory: np.asarray(x) then move to the target framework","Check x.platform() before attempting DLPack and pick an interop path per backend","Request/await DLPack support for the backend upstream","Pin your workload to a supported backend (cpu/cuda/rocm/tpu) if interop is essential"],"exampleFix":"// before\nt = torch.from_dlpack(x)  # BufferError: only CPU, GPU, TPU pinned host\n// after\nimport numpy as np\nt = torch.as_tensor(np.asarray(x))  # host round-trip works on any backend","handlingStrategy":"validation","validationCode":"DLPACK_PLATFORMS = {'cpu', 'cuda', 'rocm', 'oneapi', 'tpu'}\nif x.platform() not in DLPACK_PLATFORMS:\n    x = np.asarray(x)  # unsupported backend: transfer via host","typeGuard":"def supports_dlpack(x) -> bool:\n    return hasattr(x, '__dlpack__') and x.platform() in {\n        'cpu', 'cuda', 'rocm', 'oneapi', 'tpu'}","tryCatchPattern":"try:\n    t = torch.from_dlpack(x)\nexcept BufferError:\n    t = torch.as_tensor(np.asarray(x))  # backend-agnostic fallback","preventionTips":["Branch interop strategy on x.platform() explicitly","Keep a host-memory transfer path as the universal fallback","Track upstream DLPack support for any plugin backend you depend on"],"tags":["jax","dlpack","backend","unsupported-platform","interop"],"backgroundTag":"dlpack-unsupported-backend","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}