Skip to content

[HAL] Add HAL allocator selection based on optimal affinity for a particular usage + API. #20857

Closed

Description

@benvanik

Heterogeneous allocations may require runtime routing in order to select a device and queue affinity from a potential set. In the compiler a new #hal.device.optimal<...> affinity attribute can declare such a potential set and be assigned to operations like stream.resource.alloca to indicate that the "optimal" device (maybe meaning "the one that works") should be used for the allocation. Such situations would lower into a new hal.allocator.select (or something) op taking the set of potential devices and the allocation parameters (minus size). This op should be memoizable so that selection is performed at initialization time based on the available devices and reused during execution.

Similar to the debug sink provided to the HAL module at creation a new iree_hal_module_device_policy_t set of callbacks will be added to implement the selection logic with a select_allocator(devices/queue affinities, memory types, usage, ...) callback that returns the device/queue affinity selected. By default it could return the first device, but this could be overridden with a command line flag; for the tooling device_util.h could support a --device_lead_allocator=1-style flag that specifies a device ordinal and expose a iree_hal_device_lead_allocator_ordinal accessor that can be used to get the iree_hal_device_t* from the device set and compare against the query.

Future work can figure out a decentralized way for HAL implementations to rank/opt-in/etc themselves. For now the expectation is that users will indicate the lead allocator.

Metadata

Metadata

Assignees

Labels

compiler/dialectsruntime

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions