You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Define executable C API and rework LLVM target to emit it #3580
codegenShared code generation infrastructure and dialectscompiler/dialectsRelating to the IREE compiler dialects (flow, hal, vm)hal/apiIREE's public C hardware abstraction layer APIhal/cpuRuntime Host/CPU-based HAL backendruntimeRelating to the IREE runtime library
With the threading changes I'll be unifying the host-based HAL backends around a common executable API. VMLA, dylib, llvmjit, and in the future emitc/statically linked executables will then all share this API to expose their entry points, exchange library functions, and query information.
The goal is to get down to near-zero bytes consumed that are not in rdata (in the AOT case) and remove the need for the wrapper flatbuffers in cases where they shouldn't need to exist like statically linked executables.
//===----------------------------------------------------------------------===//// Versioning and interface querying//===----------------------------------------------------------------------===//// Known valid version values.enumiree_hal_library_version_e {
// iree_hal_library_v0_t is used as the API communication structure.IREE_HAL_LIBRARY_VERSION_0=0u,
};
typedefuint32_tiree_hal_library_version_t;
// The latest version of the library API; can be used to populate the// iree_hal_library_header_t::version when building libraries.#defineIREE_HAL_LIBRARY_LATEST_VERSION IREE_HAL_LIBRARY_VERSION_0
// A header present at the top of all versions of the library API used by the// runtime to ensure version compatibility.typedefstruct {
// Version of the API this library was built with, which was likely the value// of IREE_HAL_LIBRARY_LATEST_VERSION.iree_hal_library_version_tversion;
// Name used for logging/diagnostics.constchar*name;
} iree_hal_library_header_t;
// Exported function from dynamic libraries for querying library information.// The provided |max_version| is the maximum version the caller supports;// callees must return NULL if their lowest available version is greater// than the max version supported by the caller.typedefconstiree_hal_library_header_t* (*iree_hal_library_query_fn_t)(
iree_hal_library_version_tmax_version);
// Function name exported from dynamic libraries (pass to dlsym).#defineIREE_HAL_LIBRARY_EXPORT_NAME "iree_hal_library_query"
//===----------------------------------------------------------------------===//// IREE_HAL_LIBRARY_VERSION_0//===----------------------------------------------------------------------===//typedefvoid*iree_hal_library_binding_ptr_t;
// Read-only per-dispatch state passed to each tile in a dispatch.typedefstruct {
constuint32_t*push_constants;
constiree_hal_library_binding_ptr_t*bindings;
uint32_tworkgroup_size[3];
uint32_tworkgroup_count[3];
} iree_hal_library_dispatch_state_v0_t;
// Function signature of exported executable entry points.// The same |state| is passed to all tiles in a dispatch, with workgroup_[xyz]// varying per-tile up to the workgroup_count. Each tile represents// workgroup_size invocations in the global grid.typedefvoid (*iree_hal_library_dispatch_v0_t)(
constiree_hal_library_dispatch_state_v0_t*state, uint32_tworkgroup_x,
uint32_tworkgroup_y, uint32_tworkgroup_z);
// Structure used for v0 library interfaces.// The entire structure is designed to be read-only and able to live embedded in// the binary .rdata section.typedefstruct {
// Version/metadata header. Will have a version of IREE_HAL_LIBRARY_VERSION_0.iree_hal_library_header_theader;
// The total number of entry points available in the library. Bounds all of// the tables below.size_tentry_point_count;
// Table of export function entry points matching the ordinals defined during// library generation. The runtime will use this table to map the ordinals to// function pointers for execution.constiree_hal_library_dispatch_v0_t*entry_points;
// Optional table of export function entry point names 1:1 with entry_points.// These names are only used for tracing/debugging and can be omitted to save// binary size.constchar**entry_point_names;
// Optional table of entry point tags that describe the entry point in a// human-readable format useful for verbose logging. The string values, when// present, may be attached to tracing/debugging events related to the entry// point.constchar**entry_point_tags;
} iree_hal_library_v0_t;
this is still easy to build in LLVM IR, and collapses down to effectively just a function pointer table in release builds (the names/tags being optional):
codegenShared code generation infrastructure and dialectscompiler/dialectsRelating to the IREE compiler dialects (flow, hal, vm)hal/apiIREE's public C hardware abstraction layer APIhal/cpuRuntime Host/CPU-based HAL backendruntimeRelating to the IREE runtime library
Activity
benvanik commentedon Oct 23, 2020
Working version:
this is still easy to build in LLVM IR, and collapses down to effectively just a function pointer table in release builds (the names/tags being optional):
I think this is a good enough placeholder for the first version with room to iterate (exposing different entry points based on CPU capabilities, etc).
benvanik commentedon Oct 23, 2020
LLVM IR here for reference: https://godbolt.org/z/GvvhW8
Abstracting out LLVM HAL ABI use to HALDispatchABI utility.
Abstracting out LLVM HAL ABI use to HALDispatchABI utility.
Abstracting out LLVM HAL ABI use to HALDispatchABI utility.
Emitting the new LLVM function signature.
Emitting the new LLVM function signature.
Emitting the new LLVM function signature.
Emitting the new LLVM function signature.
Emitting the new LLVM function signature.
Abstracting out LLVM HAL ABI use to HALDispatchABI utility. (#4790)
Emitting the new LLVM function signature.
Merge pull request #4791 from google/benvanik-llvm-abi-new