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
Support specialization constants on the HAL API and replace usage of flatbuffers with them. #5662
Instead we can add specialization constants to the HAL API such that the compiler can send down anything it wants. Special values for workgroup size/threadgroup size/block size can satisfy that use case.
Entry point names - the other thing in the flatbuffers - can be replaced with deterministic values (entry point 0 = "entry_0") such that we don't need to side-channel them.
#8436 adds the plumbing on the CPU side for executables to receive spec constants. The next step is to plumb the constants through the iree_hal_executable_spec_t and up through the HAL module into the compiler.
The constants are per-executable matching per-pipeline in underlying APIs (and what we have today with the CUDA block sizes/SPIR-V flatbuffer). It's valid for a module to create multiple of the same executable with differing spec constants though we want to avoid that for resource reasons. Executables across backends don't need to agree on the constants; this allows us to plumb through block sizes in CUDA independent from local workgroup sizes in SPIR-V and whatever else we decide to add. Note that the constants are per-executable and that in some implementations like SPIR-V there may be multiple shader modules per executable - today we aren't doing this properly but that also needs to be fixed in #7824.
Next steps:
Add constants to executable spec & plumb through to HAL impls
Add constants to hal.executable.create in IR and HAL VM module
Add hal.executable.* ops and optimization for defining constants
It's up to the target backend to add the initializer with as many constants as it wants and load them. When materializing the host-side executable resources the initializer will be inlined and evaluated to pass the values to hal.executable.create which gets passed to the runtime. Since the initializer is per variant each target can have different constants.
I have an implementation mostly done of this but unfortunately ran into a hairy issue with linking: because we perform linking after translation we lose the ability to rebase the constant ordinals when merging modules in a generic way. Linking needs to be reworked for things like #7824 anyway and maybe this finally causes it.
Thought would be to have a TargetBacked::buildLinkingPassPipeline to replace the current linkExecutables call, and each backend can have its own pass pipeline (as it does its own translation pipeline) to perform the linking. This way we could have translation leave things symbolic in whatever backend-specific form things need to be (as it'll be LLVM dialect, SPIR-V dialect, etc) and during linking do fixups before finally combining things. A default pass that does this could be provided for targets that are ok with some out-of-dialect ops remaining in them after translation (hal.executable.constant.lookup or something that returns an i32 that's later resolved). It's effectively like declaring externs that are resolved during linking.
A complication would be dialects that need the constant ordinals as attributes and such (thinking SPIR-V specialization constants). In those cases the backend would have to perform the rebasing with awareness of the ops that need to be updated. Most (LLVMCPU/LLVMGPU/VMVX) are probably ok but the higher-level targets are going to need special cases.
So before this can land I need to:
Add the buildLinkingPassPipeline method and move the existing linking setup to use it
Add a placeholder op for extern constant references
Add generic passes that do module merging (what mergeModuleInto does today) and constant rebasing based on the placeholder ops
Leave SPIRV/etc TBD, as they aren't linking yet anyway
This will also improve testability of linking which today is woefully undertested.
Activity
benvanik commentedon Mar 2, 2022
#8436 adds the plumbing on the CPU side for executables to receive spec constants. The next step is to plumb the constants through the
iree_hal_executable_spec_tand up through the HAL module into the compiler.The constants are per-executable matching per-pipeline in underlying APIs (and what we have today with the CUDA block sizes/SPIR-V flatbuffer). It's valid for a module to create multiple of the same executable with differing spec constants though we want to avoid that for resource reasons. Executables across backends don't need to agree on the constants; this allows us to plumb through block sizes in CUDA independent from local workgroup sizes in SPIR-V and whatever else we decide to add. Note that the constants are per-executable and that in some implementations like SPIR-V there may be multiple shader modules per executable - today we aren't doing this properly but that also needs to be fixed in #7824.
Next steps:
hal.executable.createin IR and HAL VM modulehal.executable.*ops and optimization for defining constants__set_constantshelperantiagainst commentedon Mar 2, 2022
Related to device characteristics query, here is the list of features/capabilities/limits we found useful for Vulkan side:
https://github.com/google/iree/blob/main/iree/compiler/Dialect/Vulkan/IR/VulkanAttributes.td
The GPU vendor and product ID are useful too.
benvanik commentedon Apr 18, 2022
Planning to add something like:
It's up to the target backend to add the initializer with as many constants as it wants and load them. When materializing the host-side executable resources the initializer will be inlined and evaluated to pass the values to
hal.executable.createwhich gets passed to the runtime. Since the initializer is per variant each target can have different constants.benvanik commentedon Jun 23, 2022
I have an implementation mostly done of this but unfortunately ran into a hairy issue with linking: because we perform linking after translation we lose the ability to rebase the constant ordinals when merging modules in a generic way. Linking needs to be reworked for things like #7824 anyway and maybe this finally causes it.
Thought would be to have a
TargetBacked::buildLinkingPassPipelineto replace the currentlinkExecutablescall, and each backend can have its own pass pipeline (as it does its own translation pipeline) to perform the linking. This way we could have translation leave things symbolic in whatever backend-specific form things need to be (as it'll be LLVM dialect, SPIR-V dialect, etc) and during linking do fixups before finally combining things. A default pass that does this could be provided for targets that are ok with some out-of-dialect ops remaining in them after translation (hal.executable.constant.lookupor something that returns an i32 that's later resolved). It's effectively like declaring externs that are resolved during linking.A complication would be dialects that need the constant ordinals as attributes and such (thinking SPIR-V specialization constants). In those cases the backend would have to perform the rebasing with awareness of the ops that need to be updated. Most (LLVMCPU/LLVMGPU/VMVX) are probably ok but the higher-level targets are going to need special cases.
So before this can land I need to:
buildLinkingPassPipelinemethod and move the existing linking setup to use itmergeModuleIntodoes today) and constant rebasing based on the placeholder opsThis will also improve testability of linking which today is woefully undertested.
benvanik commentedon Jun 30, 2022
This just won't work :/
Needs a redesign.
NFC cleanup to HAL dialects cherry picked from #5662 branch.
NFC cleanup to HAL dialects cherry picked from #5662 branch. (#9673)
benvanik commentedon Oct 24, 2022
Landed in #10607 (CPU/VMVX only).