-
Notifications
You must be signed in to change notification settings - Fork 668
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
[WIP] Add umbrella optimization flags #20047
base: main
Are you sure you want to change the base?
Changes from 3 commits
e25afda
a9147ad
11d6258
882ee69
1f8ae49
a9c362b
1a96192
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,16 +5,29 @@ | |
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
||
#include "iree/compiler/Pipelines/Options.h" | ||
#include "llvm/Passes/OptimizationLevel.h" | ||
|
||
IREE_DEFINE_COMPILER_OPTION_FLAGS(mlir::iree_compiler::BindingOptions); | ||
IREE_DEFINE_COMPILER_OPTION_FLAGS(mlir::iree_compiler::InputDialectOptions); | ||
IREE_DEFINE_COMPILER_OPTION_FLAGS( | ||
mlir::iree_compiler::GlobalOptimizationOptions); | ||
IREE_DEFINE_COMPILER_OPTION_FLAGS(mlir::iree_compiler::SchedulingOptions); | ||
IREE_DEFINE_COMPILER_OPTION_FLAGS(mlir::iree_compiler::PreprocessingOptions); | ||
IREE_DEFINE_COMPILER_OPTION_FLAGS(mlir::iree_compiler::GlobalPipelineOptions); | ||
|
||
namespace mlir::iree_compiler { | ||
|
||
void GlobalPipelineOptions::bindOptions(OptionsBinder &binder) { | ||
static llvm::cl::OptionCategory category( | ||
"IREE global pipeline options controlling the entire compilation flow."); | ||
|
||
binder.opt<llvm::OptimizationLevel>( | ||
"iree-opt-level", optLevel, | ||
llvm::cl::desc("Global optimization level to apply to the entire " | ||
"compilation flow."), | ||
llvm::cl::cat(category)); | ||
} | ||
|
||
void BindingOptions::bindOptions(OptionsBinder &binder) { | ||
static llvm::cl::OptionCategory category( | ||
"IREE translation binding support options."); | ||
|
@@ -119,9 +132,24 @@ void PreprocessingOptions::bindOptions(OptionsBinder &binder) { | |
llvm::cl::cat(category)); | ||
} | ||
|
||
void GlobalOptimizationOptions::applyOptimization( | ||
const OptionsBinder &binder, const GlobalPipelineOptions &globalLevel) { | ||
binder.overrideDefault("iree-global-optimization-opt-level", optLevel, | ||
globalLevel.optLevel); | ||
|
||
if (optLevel != llvm::OptimizationLevel::O0) { | ||
binder.overrideDefault("iree-opt-strip-assertions", stripAssertions, true); | ||
llvm::dbgs() << "stripAssertions " << stripAssertions << '\n'; | ||
} | ||
}; | ||
|
||
void GlobalOptimizationOptions::bindOptions(OptionsBinder &binder) { | ||
static llvm::cl::OptionCategory category( | ||
"IREE options for controlling global optimizations."); | ||
binder.opt<llvm::OptimizationLevel>( | ||
"iree-global-optimization-opt-level", optLevel, | ||
llvm::cl::desc("Optimization level for the this pipeline"), | ||
llvm::cl::cat(category)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @benvanik I attempted to do similar to what you suggested but I've run into some problems. As an example binder.opt<bool>(
"iree-opt-strip-assertions",
stripAssertions,
init_at_opt_level(O3, true)); The problem I'm having is that There is a secondary problem, too. As you mentioned, the options shouldn't be directly set but rather a copy should be made. This is needed because we don't want setting optimization levels to affect the other flags for a session. This makes it hard (impossible?) to to make it so that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a real good start! There's a few super magic ways we could do things, but for v0 I'd have your applyOptimization above walk through the options registered on a binder and if there are registered init_at_opt_level entries perform the override. It's a bit of boilerplate we could remove with template magic but copy/pasting for now is fine. something like:
The fancier automatic way would be to have the pipeline opt level option be stashed by the binder - instead of |
||
binder.opt<bool>( | ||
"iree-opt-aggressively-propagate-transposes", | ||
aggressiveTransposePropagation, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just dropping a reminder here: we have some existing docs for "optimization options" that are due to a rework, especially after these changes land: https://iree.dev/reference/optimization-options/
We could even add a snippet that we include on each page like https://iree.dev/guides/deployment-configurations/cpu/#compile-and-run-a-program and https://iree.dev/guides/deployment-configurations/gpu-vulkan/#compile-and-run-a-program that explains what to expect out of the box and how to optimize / tune / configure from there (linking to the optimization options reference page).