Skip to content

Add --iree-hal-list-target-backends flag. - #10629

Merged
ScottTodd merged 3 commits into
iree-org:mainfrom
ScottTodd:list-hal-targets-cli
Oct 3, 2022
Merged

ScottTodd merged 3 commits into
iree-org:mainfrom
ScottTodd:list-hal-targets-cli

Conversation

@ScottTodd

@ScottTodd ScottTodd commented Oct 3, 2022 •

Copy link
Copy Markdown
Member

The HAL target backends are registered outside of the typical flags system, so --help output just appears as

--iree-hal-target-backends=<string>                          - Target backends for executable compilation.

This adds a new flag with sample usage:

λ iree-compile.exe --iree-hal-list-target-backends
Registered target backends:
  cuda
  llvm-cpu
  metal
  metal-spirv
  vmvx
  vmvx-inline
  vulkan
  vulkan-spirv
  webgpu
  webgpu-wgsl

Part of addressing #10432


I think we should also plumb something similar through to the Python bindings. This is what we have today:

# Omit `target_backends`:
_ = compile_str(asm)

ValueError: Expected a non-empty list for 'target_backends'

# Try a backend that does not exist:
_ = compile_str(asm, target_backends=["unknown"])

CompilerToolError: Error invoking IREE compiler tool iree-compile
Diagnostics:
<stdin>:2:3: error: target backend 'unknown' not registered; registered backends: cuda, llvm-cpu, metal, metal, vmvx, vmvx-inline, vulkan, vulkan
  module @arithmetic {
  ^
compilation failed

# See a runtime helper method that we could model this after:
ireert.query_available_drivers()

['cuda', 'local-sync', 'local-task', 'vulkan']

Sample usage (note the awkward required positional arg, similar to `--iree-llvm-list-targets`):

```
λ iree-compile.exe --iree-hal-list-target-backends /dev/null
Registered target backends:
  cuda
  llvm-cpu
  metal
  metal-spirv
  vmvx
  vmvx-inline
  vulkan
  vulkan-spirv
  webgpu
  webgpu-wgsl

λ iree-compile.exe --iree-hal-list-target-backends
iree-compile.exe: Not enough positional command line arguments specified!
Must specify at least 1 positional argument: See: ..\iree-build\tools\iree-compile.exe --help
```
@ScottTodd ScottTodd added the compiler/tools IREE's compiler tooling (iree-compile, iree-opt, etc) label Oct 3, 2022

@benvanik benvanik left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspect there's a better way to do this but I can't immediately find it - maybe llvm::cl::callback that prints out the list and then calls exit(0)? this would prevent the need to pass in a source file or get a bunch of random garbage output. something like:

 cl::callback([](const bool &) {
   // do the printing here
   exit(0);
 }

looks like you can also add this (this is what llvm does for its own list flags):
cl::ValueDisallowed,

@ScottTodd

Copy link
Copy Markdown
Member Author

I suspect there's a better way to do this but I can't immediately find it

Yeah, I'd like to find an elegant solution for this (especially if the list can just appear in the --help output, without needing to add a new flag). Same for --iree-llvm-list-targets. I figure that this might be good enough for now - I'd rather have an awkward way to get the information that no way at all, and I'm not sure how long it would take to figure out a better way (your ideas seem to be on the right track).

@benvanik

benvanik commented Oct 3, 2022

Copy link
Copy Markdown
Collaborator

I think at least giving the callback + exit a shot would be worth it - needing documentation on how to use a help flag is pretty self-defeating :P

llvm::cl::desc(
"Lists all registered target backends for executable compilation."),
llvm::cl::init(false), llvm::cl::ValueDisallowed,
llvm::cl::callback([&](const bool &) {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sweet, this works!

Comment on lines +164 to +167
llvm::cl::opt<bool> listHalTargets(
"iree-hal-list-target-backends",
llvm::cl::desc(
"Lists all registered target backends for executable compilation."),

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I considered adding this flag to TargetRegistry.cpp or TargetBackend.cpp, but it didn't quite fit in, without a bit of refactoring. Is this location (iree_compile_lib.cc) okay?

@ScottTodd
ScottTodd requested a review from benvanik October 3, 2022 19:55
@ScottTodd
ScottTodd marked this pull request as ready for review October 3, 2022 20:13
@ScottTodd
ScottTodd merged commit c3169c6 into iree-org:main Oct 3, 2022
@ScottTodd
ScottTodd deleted the list-hal-targets-cli branch October 3, 2022 21:49
PhaneeshB pushed a commit to PhaneeshB/iree that referenced this pull request Oct 31, 2022
The HAL target backends are registered outside of the typical flags
system, so `--help` output just appears as
```
--iree-hal-target-backends=<string>                          - Target backends for executable compilation.
```

This adds a new flag with sample usage:

```
λ iree-compile.exe --iree-hal-list-target-backends
Registered target backends:
  cuda
  llvm-cpu
  metal
  metal-spirv
  vmvx
  vmvx-inline
  vulkan
  vulkan-spirv
  webgpu
  webgpu-wgsl
```

Part of addressing iree-org#10432

---

I think we should also plumb something similar through to the Python
bindings. This is what we have today:

```python
# Omit `target_backends`:
_ = compile_str(asm)

ValueError: Expected a non-empty list for 'target_backends'

# Try a backend that does not exist:
_ = compile_str(asm, target_backends=["unknown"])

CompilerToolError: Error invoking IREE compiler tool iree-compile
Diagnostics:
<stdin>:2:3: error: target backend 'unknown' not registered; registered backends: cuda, llvm-cpu, metal, metal, vmvx, vmvx-inline, vulkan, vulkan
  module @Arithmetic {
  ^
compilation failed

# See a runtime helper method that we could model this after:
ireert.query_available_drivers()

['cuda', 'local-sync', 'local-task', 'vulkan']
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

compiler/tools IREE's compiler tooling (iree-compile, iree-opt, etc)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants