iree: Compiling for llvm-cpu without targeting a specific CPU is a bad experience
I’ve seen multiple people falling down this hole: they run iree-compile on their model, targeting CPU. Then they get performance that is 10x-100x off of any reasonable expectation. Then they either go away silently or report back about poor experiences (not always reporting flags and such).
There are good reasons why a compiler like IREE shouldn’t make assumptions about what the CPU target is, but on the other hand, it will almost always produce a a grossly subpar experience to not specify a target CPU, since the generic target (at least on X86) lacks so many features as to be basically useless for any high performance numerics.
I’ve even fallen down this hole recently and had to go remember the incantation to select a specific CPU. In the case I was working on (an f16 CPU LLM), performance was 100x different between not specifying a target CPU and specifying “host”. We need to guide people better than this.
Proposal
As mentioned, there are good reasons for a compiler to not make too many assumptions without being told what to do. But I think we can/should actively warn, possibly with a link to the documentation site when the compiler is invoked without the user specifying a target CPU. Whatever the warning is should be very explicit that the user should pass --iree-llvmcpu-target-cpu=host to target the precise CPU they are running on. We should possibly also accept “generic” or something like that for if the user really wants to target the default and not get the warning. I basically want to guard against the case where the user has not specified anything and the compiler just silently generates 100x too slow of code. In almost all cases, it will be better for the user to say something and we should guide them on a proper choice.
About this issue
- Original URL
- State: open
- Created 2 years ago
- Comments: 35 (22 by maintainers)
Commits related to this issue
- Warn when --iree-llvmcpu-target-cpu defaults to "generic". (#18682) Progress on https://github.com/iree-org/iree/issues/18561. This introduces a warning (which we intend to promote to an error in th... — committed to iree-org/iree by bjacob 2 years ago
- Refresh compile/run examples in deployment configuration guides. (#19920) Progress on https://github.com/iree-org/iree/issues/18174, updating some stale documentation. > [!NOTE] > Demo here: ht... — committed to iree-org/iree by ScottTodd 2 years ago
I’m fine making
--iree-llvmcpu-target-cpu=<something>required. Given the proliferation of things out there, I think that the way to get there may be to first do what I am suggesting: make it issue a warning if not specified and incorrectly/implicitly defaulting to a generic CPU (with a note that this flag will soon be required).Agreed on all of the other points. Need to burn down all of the other flags. I’m just starting with this one.
Yeah mostly about GPU targets (where we have to launch other tools that fully load/initialize drivers and such) - CPU detection in LLVM is free.
Ehhh… we only support the “host” CPU name on x86? https://github.com/iree-org/iree/blob/e19950c4c01b20c329d22e729212d182da9fee76/compiler/plugins/target/LLVMCPU/LLVMTargetOptions.cpp#L50
The https://github.com/llvm/llvm-project/blob/main/llvm/lib/TargetParser/Host.cpp file supports plenty of other architectures though…
That’s insanity - besides the debug flags (dumping statistics/etc) if any of those are required that’s a bug. I think Mahesh has said it before: a feature is not done until it’s on by default and if all of those flags are needed to make the model compile or perform then the engineering was never completed. The only two flags required there should be
--iree-hal-target-device=hip(that’s using the old deprecated flag) and--iree-hip-target=(which could benativeif we wanted to do what clang does and invokeamdgpu-archif it’s present).