Module Device.Allocator

Backend allocator interface.

An allocator manages device buffer lifecycle: allocation, data transfer, addressing, and optional features such as offset views and device-to-device copies. The buffer type 'buf is backend-specific and hidden behind packed at the device level.

See Lru_allocator for LRU caching on top of a raw allocator.

Types

type 'buf transfer = dest:'buf -> src:'buf -> int -> unit

The type for device-to-device transfers. transfer ~dest ~src nbytes copies nbytes from src to dest. Both buffers belong to the same backend.

type 'buf t = {
  1. alloc : int -> Buffer_spec.t -> 'buf;
    (*

    alloc nbytes spec allocates a device buffer of nbytes bytes with options spec.

    *)
  2. free : 'buf -> int -> Buffer_spec.t -> unit;
    (*

    free buf nbytes spec releases buf. nbytes and spec must match the values passed to alloc.

    *)
  3. copyin : 'buf -> bytes -> unit;
    (*

    copyin buf src copies src into buf.

    *)
  4. copyout : bytes -> 'buf -> unit;
    (*

    copyout dst buf copies buf into dst.

    *)
  5. addr : 'buf -> nativeint;
    (*

    addr buf is the device address of buf.

    *)
  6. offset : ('buf -> int -> int -> 'buf) option;
    (*

    offset buf nbytes byte_offset is a view into buf starting at byte_offset and spanning nbytes, or None if the backend does not support offset views.

    *)
  7. transfer : 'buf transfer option;
    (*

    Device-to-device transfer, or None if unsupported.

    *)
  8. supports_transfer : bool;
    (*

    true iff transfer is Some _.

    *)
  9. copy_from_disk : ('buf -> 'buf -> int -> unit) option;
    (*

    Direct disk-to-device copy, or None if unsupported.

    *)
  10. supports_copy_from_disk : bool;
    (*

    true iff copy_from_disk is Some _.

    *)
}

The type for backend allocators parameterised by the buffer representation 'buf.

type packed =
  1. | Pack : 'buf t -> packed
    (*

    Existential wrapper hiding the backend buffer type.

    *)