# torch 2.15.0 (BSD-3-Clause), harvested by tools/harvest_corpus.py
=== input
A zero-copy, read-only view of a tensor for DLPack interop only.

    Wrapping a tensor with ``ReadOnlyTensorWrapper`` declares the intent that
    consumers must not mutate its data. It changes only the DLPack export
    behavior; the wrapper shares storage with the source tensor and does not
    copy.

    Both DLPack export paths are routed to read-only variants:

    * the fast ``__dlpack_c_exchange_api__`` C exchange protocol (used by
      tvm-ffi / CuteDSL) points at the const exchange API, which exports
      through ``const_data_ptr()`` and sets
      ``DLPACK_FLAG_BITMASK_READ_ONLY``;
    * the ``__dlpack__()`` capsule protocol forces ``read_only=True``.

    Because the export uses ``const_data_ptr()``, exporting a copy-on-write
    tensor does not materialize it.

    The wrapper is export-only: every torch operation other than the DLPack
    protocol methods raises ``RuntimeError``. Unwrap it (e.g. via the original
    tensor) to operate on the data.

    Example::

        x = torch.randn(8)
        ro = ReadOnlyTensorWrapper(x)
        cute.runtime.from_dlpack(ro, enable_tvm_ffi=True)  # read-only export
    
=== parse google
short_description: 'A zero-copy, read-only view of a tensor for DLPack interop only.'
long_description: |
  Wrapping a tensor with ``ReadOnlyTensorWrapper`` declares the intent that
  consumers must not mutate its data. It changes only the DLPack export
  behavior; the wrapper shares storage with the source tensor and does not
  copy.
  
  Both DLPack export paths are routed to read-only variants:
  
  * the fast ``__dlpack_c_exchange_api__`` C exchange protocol (used by
    tvm-ffi / CuteDSL) points at the const exchange API, which exports
    through ``const_data_ptr()`` and sets
    ``DLPACK_FLAG_BITMASK_READ_ONLY``;
  * the ``__dlpack__()`` capsule protocol forces ``read_only=True``.
  
  Because the export uses ``const_data_ptr()``, exporting a copy-on-write
  tensor does not materialize it.
  
  The wrapper is export-only: every torch operation other than the DLPack
  protocol methods raises ``RuntimeError``. Unwrap it (e.g. via the original
  tensor) to operate on the data.
  
  Example::
  
      x = torch.randn(8)
      ro = ReadOnlyTensorWrapper(x)
      cute.runtime.from_dlpack(ro, enable_tvm_ffi=True)  # read-only export
blank_after_short_description: True
blank_after_long_description: False
style: google
=== detect
rest
=== compose google
A zero-copy, read-only view of a tensor for DLPack interop only.

Wrapping a tensor with ``ReadOnlyTensorWrapper`` declares the intent that
consumers must not mutate its data. It changes only the DLPack export
behavior; the wrapper shares storage with the source tensor and does not
copy.

Both DLPack export paths are routed to read-only variants:

* the fast ``__dlpack_c_exchange_api__`` C exchange protocol (used by
  tvm-ffi / CuteDSL) points at the const exchange API, which exports
  through ``const_data_ptr()`` and sets
  ``DLPACK_FLAG_BITMASK_READ_ONLY``;
* the ``__dlpack__()`` capsule protocol forces ``read_only=True``.

Because the export uses ``const_data_ptr()``, exporting a copy-on-write
tensor does not materialize it.

The wrapper is export-only: every torch operation other than the DLPack
protocol methods raises ``RuntimeError``. Unwrap it (e.g. via the original
tensor) to operate on the data.

Example::

    x = torch.randn(8)
    ro = ReadOnlyTensorWrapper(x)
    cute.runtime.from_dlpack(ro, enable_tvm_ffi=True)  # read-only export
