Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include default tuning specs with the compiler #19214

Closed
7 of 8 tasks
kuhar opened this issue Nov 19, 2024 · 5 comments
Closed
7 of 8 tasks

Include default tuning specs with the compiler #19214

kuhar opened this issue Nov 19, 2024 · 5 comments
Assignees
Labels
codegen Shared code generation infrastructure and dialects enhancement ➕ New feature or request performance ⚡ Performance/optimization related work across the compiler and runtime tuner

Comments

@kuhar
Copy link
Member

kuhar commented Nov 19, 2024

We want to be able to ship a library of default tuning specs with IREE, so that users can get good performance out of the box on known key operations. This is applied after dispatch formation and realized around the time we run the MaterializeUserConfigs pass. Currently, there's not default spec provided, but the users can supply their own transform dialect libraries.

I propose the following solutions, which bears similarity with how we plan to handle ukernels. There are a lot of things that still need to be worked out, but this is roughly the brake-down of of key requirements/properties:

Spec maintanance policy:

  1. New tests will make sure that the default tuning specs are up-to-date and in a working state.
  2. In case of minor syntactic changes, it will be the responsibility of the patch author to update the specs.
  3. In case of substantial upstream mlir dialect changes, the author of the mlir change will be responsible for the upgrade. If that person is not an IREE contributor, the responsibility would then fall on the author of the tuning spec.
@kuhar kuhar added codegen Shared code generation infrastructure and dialects performance ⚡ Performance/optimization related work across the compiler and runtime labels Nov 19, 2024
@kuhar kuhar self-assigned this Nov 19, 2024
@kuhar
Copy link
Member Author

kuhar commented Nov 19, 2024

@MaheshRavishankar
Copy link
Contributor

Thanks Jakub. This is a great summary and description. Few comments below.

  • During IREE build, these tuning specs will be given to iree-opt, verified, and saved as mlir bytecode files. These bytecode files will be embedded into the final iree compiler binary. At runtime, the compiler will be able to access them as memory buffers.

I dont think they should be included as part of the final iree compiler binary. I think we should be able to put in a location that iree-compile can access it from? We also need to be able to provide/append a way for user to override the tuning spec picked up

  • Just before MaterializeUserConfigs, we will load the compatible tuning spec, if any, and the user-provided transform libraries.
  • We will put both transform dialect libraries in the same module, so that there's only one library to handle.

Nice. Thanks for incorporating this. We should build this is a separate utility/tool that can be tested independently (and maybe invoked from within the compiler to be able to append to existing tuning).

Rest of the stuff looks good to me.

cc @erman-gurses @bangtianliu @nithinsubbiah

@ScottTodd
Copy link
Member

  • During IREE build, these tuning specs will be given to iree-opt, verified, and saved as mlir bytecode files. These bytecode files will be embedded into the final iree compiler binary. At runtime, the compiler will be able to access them as memory buffers.

I dont think they should be included as part of the final iree compiler binary. I think we should be able to put in a location that iree-compile can access it from? We also need to be able to provide/append a way for user to override the tuning spec picked up

I think we can figure these details out partway through the implementation work, but starting with brainstorming and design work now is a good idea. Once we have the basic mechanism in place to use tuning specs, how those specs are provided will matter more.

We can survey other similar projects to see what they do and what users will expect. Bundling the files as part of the compiler distribution (either embedded directly in the libIREECompiler.so or in separate files that we package together) will certainly be nice for a self-contained / hermetic compiler. I could see users wanting to maintain their own spec libraries to be shared between multiple developers, in which case we'd want a way to load those libraries from a local file path or even a remote URL. That could get complex with priority loading / ordering if there are multiple matching specs, generic specs that can act as a fallback if no more specific spec matches, etc.

@kuhar
Copy link
Member Author

kuhar commented Nov 20, 2024

  • During IREE build, these tuning specs will be given to iree-opt, verified, and saved as mlir bytecode files. These bytecode files will be embedded into the final iree compiler binary. At runtime, the compiler will be able to access them as memory buffers.

I dont think they should be included as part of the final iree compiler binary. I think we should be able to put in a location that iree-compile can access it from?

IIUC, ukernels are also stored in the compiler binary and this part mirrors that solution. This makes distribution easier because you don't have to carry an additional directory with tuning specs and worry about installing it somewhere relative to the compiler.

We also need to be able to provide/append a way for user to override the tuning spec picked up

My plan is to append all specs (both the default arch-specific one and user-provided one) into one transform library module, and have that embedded in an opaque attribute. I attempted to describe it the bullet points towards the middle.

kuhar added a commit that referenced this issue Nov 25, 2024
This pass is meant for combining multiple tuning specs (e.g., a
user-provided one and a default one).
We expect the input module to have nested sub-modules with named
sequences marked with the `iree_codegen.tuning_spec_entrypoint` unit
attributes.

The pass collects all such tuning specs and introduce a new named
sequence that includes all the other tuning spec entry points. The order
of inclusion is the same as the in which these nested tuning specs
appear in the IR.

Issue: #19214
kuhar added a commit that referenced this issue Nov 27, 2024
…19313)

Hoist the library loading logic out of the loop that configures
functions.

This is in preparation for adding tuning spec loading from a new module
attr.

Issue: #19214
Groverkss pushed a commit to Groverkss/iree that referenced this issue Dec 1, 2024
This pass is meant for combining multiple tuning specs (e.g., a
user-provided one and a default one).
We expect the input module to have nested sub-modules with named
sequences marked with the `iree_codegen.tuning_spec_entrypoint` unit
attributes.

The pass collects all such tuning specs and introduce a new named
sequence that includes all the other tuning spec entry points. The order
of inclusion is the same as the in which these nested tuning specs
appear in the IR.

Issue: iree-org#19214
Groverkss pushed a commit to Groverkss/iree that referenced this issue Dec 1, 2024
…ree-org#19313)

Hoist the library loading logic out of the loop that configures
functions.

This is in preparation for adding tuning spec loading from a new module
attr.

Issue: iree-org#19214
kuhar added a commit that referenced this issue Dec 1, 2024
... and update 'Materialize User Configs' to pick up those tuning specs.

The overall flow is as follows:
* We pick up any user-specified tuning specs in `materialize tuning
specs` and link them into a single transform dialect library module.
* We serialize that linked tuning spec as MLIR bytecode.
* We embed this MLIR bytecode as a module attribute. This is so that
none of the subsequent passes will accidentally `walk` or otherwise
modify it.
* In `materialize user configs`, we first check if there are any
transform libraries provided. If not, then we check if the tuning spec
is present.
* We deserialize the tuning spec attribute into a transform dialect
library module and execute it.
* We remove the serialized tuning spec from the module, as it's no
longer needed.

I also modified `getOrLoadTransformLibraryModule` so that it doesn't use
the `transform::detail::assembleTransformLibraryFromPaths` function,
because it has some logic to perform library merging that would
overwrite module symbol names. There's no need to call it anyway, since
we are loading a single library at a time.

This is not added to any codegen pipeline yet -- I will do that in a
future PR.

Issue: #19214
giacs-epic pushed a commit to giacs-epic/iree that referenced this issue Dec 4, 2024
This pass is meant for combining multiple tuning specs (e.g., a
user-provided one and a default one).
We expect the input module to have nested sub-modules with named
sequences marked with the `iree_codegen.tuning_spec_entrypoint` unit
attributes.

The pass collects all such tuning specs and introduce a new named
sequence that includes all the other tuning spec entry points. The order
of inclusion is the same as the in which these nested tuning specs
appear in the IR.

Issue: iree-org#19214
Signed-off-by: Giacomo Serafini <179146510+giacs-epic@users.noreply.github.com>
giacs-epic pushed a commit to giacs-epic/iree that referenced this issue Dec 4, 2024
…ree-org#19313)

Hoist the library loading logic out of the loop that configures
functions.

This is in preparation for adding tuning spec loading from a new module
attr.

Issue: iree-org#19214
Signed-off-by: Giacomo Serafini <179146510+giacs-epic@users.noreply.github.com>
giacs-epic pushed a commit to giacs-epic/iree that referenced this issue Dec 4, 2024
... and update 'Materialize User Configs' to pick up those tuning specs.

The overall flow is as follows:
* We pick up any user-specified tuning specs in `materialize tuning
specs` and link them into a single transform dialect library module.
* We serialize that linked tuning spec as MLIR bytecode.
* We embed this MLIR bytecode as a module attribute. This is so that
none of the subsequent passes will accidentally `walk` or otherwise
modify it.
* In `materialize user configs`, we first check if there are any
transform libraries provided. If not, then we check if the tuning spec
is present.
* We deserialize the tuning spec attribute into a transform dialect
library module and execute it.
* We remove the serialized tuning spec from the module, as it's no
longer needed.

I also modified `getOrLoadTransformLibraryModule` so that it doesn't use
the `transform::detail::assembleTransformLibraryFromPaths` function,
because it has some logic to perform library merging that would
overwrite module symbol names. There's no need to call it anyway, since
we are loading a single library at a time.

This is not added to any codegen pipeline yet -- I will do that in a
future PR.

Issue: iree-org#19214
Signed-off-by: Giacomo Serafini <179146510+giacs-epic@users.noreply.github.com>
@kuhar kuhar added the tuner label Dec 4, 2024
kuhar added a commit that referenced this issue Dec 9, 2024
These default specs are target architecture-specific and will be shipped
with the compiler.

* Default specs belong to target plugins and get embedded in
`libIREECompiler.so`, just like ukernels.
* Plugins then register their default tuning specs with the default
embedded directory.
* We store them as mlir text. We can't easily assemble them as mlir
bytecode without taking a circular dependency on iree-opt. We can
revisit this in the future and add a new tool `iree-as` that will only
link with dialects.
* After the initial loading, we cache the default specs in the IREE
codegen dialect transform library manager.
* Add a placeholder spec for gfx942.
* Document and test the inclusion order. User specs come before default
specs.

Issue: #19214
kuhar added a commit to kuhar/iree that referenced this issue Dec 11, 2024
This is a fixup to the tuning spec materialization that makes default
and user-provided specs work e2e. As an example, a working spec for
`linalg.matmul_transpose_b` is provided for gfx942.

* Allow for tuning spec entry points that consume their argument op.
  This is so that tuning specs can use `transform.foreach_match`.
* Require all tuning spec entry points to return `any_op`, so that we
  can chain includes. This works for both consumed and readonly args.
* Add a test to show that user-provided tuning specs take precedence
  over default ones.
* Work around a transform interpreter bug when multiple named sequenced
  across different modules share the same symbol name.

Issue: iree-org#19214

Signed-off-by: Jakub Kuderski <jakub@nod-labs.com>
kuhar added a commit to kuhar/iree that referenced this issue Dec 11, 2024
This is a fixup to the tuning spec materialization that makes default
and user-provided specs work e2e. As an example, a working spec for
`linalg.matmul_transpose_b` is provided for gfx942.

* Allow for tuning spec entry points that consume their argument op.
  This is so that tuning specs can use `transform.foreach_match`.
* Require all tuning spec entry points to return `any_op`, so that we
  can chain includes. This works for both consumed and readonly args.
* Add a test to show that user-provided tuning specs take precedence
  over default ones.
* Work around a transform interpreter bug when multiple named sequenced
  across different modules share the same symbol name.

Issue: iree-org#19214

Signed-off-by: Jakub Kuderski <jakub@nod-labs.com>
ScottTodd added a commit that referenced this issue Dec 11, 2024
This is a fixup to the tuning spec materialization that makes default
and user-provided specs work e2e. As an example, a working spec for
`linalg.matmul_transpose_b` is provided for gfx942.

* Allow for tuning spec entry points that consume their argument op.
This is so that tuning specs can use `transform.foreach_match`.
* Require all tuning spec entry points to return `any_op`, so that we
can chain includes. This works for both consumed and readonly args.
* Add a test to show that user-provided tuning specs take precedence
over default ones.
* Work around a transform interpreter bug when multiple named sequenced
across different modules share the same symbol name.

Issue: #19214

---------

Signed-off-by: Jakub Kuderski <jakub@nod-labs.com>
kuhar added a commit that referenced this issue Dec 11, 2024
General intro, list the main flags, show an example.

Issue: #19214
bangtianliu added a commit that referenced this issue Dec 18, 2024
This PR is relevant to task in
#19214: add [a discardable attr
verifier](https://mlir.llvm.org/docs/DefiningDialects/#discardable-attribute-verification)
for entry points iree_codegen.tuning_spec_entrypoint

---------

Signed-off-by: Bangtian Liu <liubangtian@gmail.com>
bangtianliu added a commit that referenced this issue Jan 3, 2025
This PR adds the unit attribute`
iree_codegen.tuning_spec_with_default_entrypoint` to indicate the
default tuning spec (typically or user-provided tuning spec but can work
in the same manner) must contain one named sequence operation marked
with `__kernel_config`, also add the corresponding verification in
`verifyOperationAttribute` function.

This PR is relevant to task in
#19214: add [a discardable attr
verifier](https://mlir.llvm.org/docs/DefiningDialects/#discardable-attribute-verification)
for entry points iree_codegen.tuning_spec_entrypoint

Context:
Jakub proposed two approaches for verifying the default tuning
specification:
1. Implement a dedicated pass for verification.
2. Add a new attribute and update the verifyOperationAttribute function
accordingly.

After careful consideration, we agreed on the second approach to avoid
introducing an additional pass, ensuring a simple implementation.

---------

Signed-off-by: Bangtian Liu <liubangtian@gmail.com>
@kuhar
Copy link
Member Author

kuhar commented Jan 3, 2025

I'm going to close this as completed because all of the pieces are in place now and the remaining work is to grow the set of default tuning specs included with the compiler.

@kuhar kuhar closed this as completed Jan 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
codegen Shared code generation infrastructure and dialects enhancement ➕ New feature or request performance ⚡ Performance/optimization related work across the compiler and runtime tuner
Projects
None yet
Development

No branches or pull requests

3 participants