Repository navigation
Description
Conceptually HAL drivers are like schema handlers, devices are like resources, and device configuration has a set of information that is used to select the device and a set of information used to change device options. This naturally maps to URIs: scheme://path?query#fragment. This analogy helps show what information we need and when, how to shape the API, and gives us a convenient format we can use consistently in tools/APIs.
Things we need to be able to do:
- Query available drivers (aka schema handlers);
cuda,local-inline,local-task,remote-tcp, etc - Query discoverable devices on a driver;
remote-tcp-> [localhost:4000,localhost:4001],local-task-> [NUMAnode/0,node/1], etc - Create a device with some configuration;
local-task://node/0?loaders=vmvx,local-task://?topology=0:0:1,0:1:0,vulkan://?features=shader64, etc - Express availability for when modules choose devices (Starting moving device enumeration into the HAL dialect/compiled modules. #5724);
cuda://GPU-abcdef0,cuda://GPU-abcdef1,...,local-task://node/0-9, etc - Configure created devices;
cuda://GPU-8932f937-d72c-4106-c12f-20bd9faed9f6#force_graph=1
An important thing here is that querying available drivers is easy/fast but querying available devices is not; in most cases it requires bringing up an entire subsystem (loading cuda/vulkan drivers, connecting to the kernel interface and creating process-lifetime internal junk, etc) - so we only want device discovery to happen once a driver is selected or the user is strictly querying and going to exit the process (so you don't end up with cuda loaded forever even if you decide to use the CPU, etc). We need to ensure the common usage does not require querying, even if only for validation (it's way cheaper to try and fail then query and conditionally create).
The current driver registry and driver interface work for the schema handler part but the queried device and device ID stuff needs to change to allow for driver-specific specifications and to take the new configuration strings. From there the rest is just an extension to iree_hal_driver_create_device:
iree_status_t iree_hal_driver_create_device(
iree_hal_driver_t* driver, iree_string_view_t device_path,
iree_host_size_t device_config_count, const iree_string_view_t* device_config_values,
iree_allocator_t host_allocator, iree_hal_device_t** out_device);We can also have helpers that do the URI parsing consistently:
// full schema://path, creating driver from the registry:
iree_status_t iree_hal_driver_registry_create_device_from_uri(
iree_hal_driver_registry_t* driver_registry, iree_string_view_t uri,
iree_allocator_t host_allocator, iree_hal_device_t** out_device);
// already selected schema (no need for a registry):
iree_status_t iree_hal_driver_create_device_from_uri(
iree_hal_driver_t* driver, iree_string_view_t uri,
iree_allocator_t host_allocator, iree_hal_device_t** out_device);Our tools can then drop --driver and several of the associated flags to then just have a repeated --device= flag:
# run on local executor with task system, default topology, all loaders
iree-run-module ... --device=local-task
# run on local executor with task system, only NUMA node 0, all loaders
iree-run-module ... --device=local-task://node/0
# run on local executor with task system, default topology, only allow vmvx loader
iree-run-module ... --device=local-task://?loaders=vmvx
# run on two cuda devices, peering and multiplexing both
iree-run-module ... --device=cuda://GPU-abcd0,GPU-abcd1
# run on two cuda devices, independently managed
iree-run-module ... --device=cuda://GPU-abcd0 --device=cuda://GPU-abcd1
# run on a particular vulkan device:
iree-run-module ... --device=vulkan://uuid/754d9ae2-8df5-f8e3-3502-182434a12876
# or pci info, whatever:
iree-run-module ... --device=vulkan://pci/VEN_10DE&DEV_1E07&CC_0300
# heterogenously run on cpu and vulkan:
iree-run-module ... --device=local-task --device=vulkan
Each driver can have whatever kind of handling it wants and we can extend it in one place to get device selection/configuration. Python layers as in #9330 could have nice pythonic ways of expressing things that bottom out on the same APIs; so you could pass around the canonical strings or have dicts and such like create_device("cuda", "GPU-abcd0", {"some_config": "value"}).
This intersects well with #5724 - the user/host provided device list is taken as an availability list and the compiled modules use that list to select vs needing to query for availability. Saying --device=cuda --device=local-task would let the module choose cuda (first in the list) if it supported it and fall back to the local task executor and if the module wasn't compiled for cuda it'd just ignore it. More to work through there but I think the first part is getting a push-style description of devices as here.
This also intersects with #4298 and #9336: we need a way to select things like executable loaders in order to have fat builds that are still testable without requiring a lot of goo. What is today driver=vmvx-sync would become --device=local-inline://?loaders=vmvx (which we could have a nice helper for) for tests/benchmarks/etc, but for 99% of users it'd be --device=local-inline and then use whatever loaders are compiled in.
Metadata
Metadata
Assignees
Type
Projects
- StatusShow more project fieldsDone
Activity
benvanik commentedon Jun 6, 2022
To make transition easier having the tools map
--driverflags into the new--devicevariants would be easy and we could unwind the spidering flags from tests/benchmarks/etc independently. We could also use flagfiles to select devices; tests and such could pass--flagfile=suite_device_flags.txtand have it contain all the configuration instead of needing to pass the expanded flags everywhere.Renaming file_path to path and adding some basic URI utils.
Renaming file_path to path and adding some basic URI utils. (#9384)
Removing iree_hal_driver_id_t in favor of just string names.
5 remaining items
Adding a device_util helper for tooling. (#9415)
Adding --list_drivers, --list_devices, and --dump_devices flags.
Adding a --device flag to replace --driver.
Adding --list_drivers, --list_devices, and --dump_devices flags.
Adding a --device flag to replace --driver.
Renaming file_path to path and adding some basic URI utils. (iree-org…
Removing iree_hal_driver_id_t in favor of just string names. (iree-or…
Adding iree_hal_driver_create_device_by_path & co. (iree-org#9413)
Adding a device_util helper for tooling. (iree-org#9415)
benvanik commentedon Jun 10, 2022
Calling this done for now as of #9443. There's now a
--device=flag, driver registry/driver APIs for manipulating device URIs, and helpers for querying device information. Each driver can be extended from this point to support more URI behaviors, parameters, diagnostic information, etc.