Skip to content

Add support for external HAL modules #9336

Closed

Description

@powderluv

Having added about 6 variations of private IREE HALs including the public ROCM HAL it would be good to support out of tree HALs. We have a few more HALs that require carry forks that we would rather have built out of tree.

There is no need for binary compatibility etc in this ask -- all sources will be built together but we would like IREE HAL to look for "external" modules in some CMAKE specified path.

Activity

  1. added
    enhancement ➕
    hal/api
    on Jun 6, 2022
  2. benvanik commented on Jun 6, 2022

    @benvanik
    Collaborator

    I’ll add a cmake list var to supersede what we have in iree/hal/drivers/ - you’ll then ensure you have a static library with the right name and a function that registers the driver and it’ll get linked and called by any iree tool using the driver registry. You can still manually register things in your own binaries if you want smaller binary sizes/deps but I suspect what you’re asking for here is for them to appear in iree-benchmark-module and such.

  3. added this to the Infrastructure Fixit milestone on Jun 6, 2022
  4. benvanik commented on Jun 6, 2022

    @benvanik
    Collaborator

    Rough idea is that we add an IREE_EXTERNAL_HAL_DRIVERS cmake var similar to LLVM_EXTERNAL_PROJECTS - you'd then declare your driver:

    ROCM_HAL_DRIVER_SOURCE_DIR=experimental/rocm/
    ROCM_HAL_DRIVER_TARGET=experimental_rocm_driver
    list(APPEND IREE_EXTERNAL_HAL_DRIVERS "rocm")
    

    then have a file with the registration function in it:

    iree_status_t rocm_hal_driver_register(iree_hal_driver_registry_t* registry) {
      // do registration stuff here
    }

    and in iree/hal/drivers/ we'd include it:

    foreach(driver ${IREE_EXTERNAL_HAL_DRIVERS})
      # include cmakelists that contains the library and fetches/finds/etc deps
      get_external_hal_driver_var(source_dir ${driver} SOURCE_DIR)
      add_subdirectory(${source_dir})
      # allow the external cmakelists to decide whether it's actually enabled (find_package success, etc)
      get_external_hal_driver_var(driver_usable ${driver} FOUND)
      if(${driver_usable})
        # add dep on the target so that it gets pulled into the build
        get_external_hal_driver_var(target ${driver} TARGET)
        list(APPEND IREE_HAL_DRIVER_MODULES ${target})
        # add the registration call to the list
        list(APPEND IREE_HAL_DRIVER_REGISTRATION_CALLS "${driver}_register")
      endif()
    endforeach()
    ...
    # produce an init_external.c with calls to each of the IREE_HAL_DRIVER_REGISTRATION_CALLS
    configure_file(init_external.c.in init_external.c)
    ...
    iree_cc_library(
      drivers ... 
      SRCS "init.c" "init_external.c"
      DEPS ${IREE_HAL_DRIVER_MODULES}
      COPTS "-DIREE_HAL_EXTERNAL_DRIVER_REGISTRATION=1"
    

    then in the init.c we do:

    extern void iree_hal_register_external_drivers(iree_hal_driver_registry_t* registry);
    iree_hal_register_all_available_drivers(iree_hal_driver_registry_t* registry) {
      iree_hal_register_external_drivers(registry);
    }

    Or something like this with the cmake goo resolved.
    For bazel we could check in a file with the backends or genrule a templated one, but the cmake stuff should be this straightforward and make it possible to include external drivers without changing any IREE code.

    I think it would also be possible to do all the built-in HAL drivers like this as well, which would help solve for things like vulkan sdk deps/webgpu stuff/etc.

    /cc @ScottTodd

  5. powderluv commented on Jun 6, 2022

    @powderluv
    ContributorAuthor

    Nice this is exactly what we want on the CMake side. We haven't had to use bazel with externals so whatever is best on bazel side we are ok.

  6. benvanik commented on Jun 6, 2022

    @benvanik
    Collaborator

    We may want something similar for executable loaders - that'd let us solve the #4298 issue by having vmvx/dylib/etc optional alongside static libraries and bigger deps (wasm/jits/etc).

  7. benvanik commented on Jun 7, 2022

    @benvanik
    Collaborator

    A gotcha here will be that the benchmark infra is not setup to handle external drivers; it currently relies on knowing about the drivers in python instead of relying on what's available in cmake (what we can easily extend). There will need to be some work to remove all references to driver names in the code if we care about letting people use the benchmark infra (which would be really nice); basically the only place that should know about compilation targets/driver names/etc should be the definition of the benchmark suite and then those should be passed unmodified down to the lower level tooling (iree-compile/iree-benchmark-module/etc).

  8. Repository owner moved this from In Progress to Done in IREE - ARCHIVED (do not update)on Jun 8, 2022
  9. powderluv commented on Jun 8, 2022

    @powderluv
    ContributorAuthor

    Thanks thanks

  10. moved this to Done in IREEon Jun 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

enhancement ➕hal/api

Type

No type

Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions