Repository navigation
Boolean constant support - #3066
Conversation
|
not llvm related? |
benvanik
left a comment
There was a problem hiding this comment.
This isn't valid - you shouldn't have any i1 types by the time you are serializing to bytecode - it indicates you are missing an i1->i8 expansion earlier on
I wanted to highlight that both VMLA and the LLVMJit were now working given its a HAL/VM change (waiting on vulkan changes). Updated comment. |
I updated to occur at the HAL to VM lowering. I can also place it at the std.const to HAL lowering but it felt a little strange to change the type at that point. Either works but went with the HAL to VM lowering. |
rsuderman
left a comment
There was a problem hiding this comment.
Implemented in follow up
|
|
||
| // VM supports a minimum of 8-bit elements. Round 1-bit bools to 8-bits. | ||
| auto value = op.value().cast<ElementsAttr>(); | ||
| if (value.getType().getElementType().isInteger(1)) { |
There was a problem hiding this comment.
I'm not that familiar with the complete list of steps in IREE's conversion pipelines. Is there an earlier place where a cast from bool to i8 would be sufficient? By the time we're here in the HAL dialect (HALToVM), I'd expect us to be missing some higher level context that would help us understand where such a conversion makes the most sense. This could benefit from an expanded comment here, or a section within a more holistic design doc (similar to https://google.github.io/iree/design-docs/codegen-passes).
There was a problem hiding this comment.
Yeah this is still too low-level - the HAL cannot support 1 bit data types either.
benvanik
left a comment
There was a problem hiding this comment.
You made it one level higher, but it needs to be one level higher still :)
The HAL and the VM have machine-level semantics. Just as you can't malloc 1-bit or memset 1-bit you cannot create a HAL buffer of 1-bit. The conversion you're doing needs to happen between flow (where things are tensors) and hal (where things are buffers).
This could probably happen in iree\compiler\Dialect\HAL\Conversion\TypeConverter.cpp. As Scott mentions though it is probably worth more exhaustively testing that such a conversion is valid (tests that perform operations on the bool tensors, etc) or what alternatives are. For example, the intent is that an 8/16/32-bit aligned 1-bit tensor could be widened to work on the byte-aligned types if the operations performed on it are compatible (bitwise op, usually). So tensor<8x32xi1> -> tensor<8xi32>. This wastes no memory (vs always expanding) and the HAL doesn't care about what the bits represent so it should pass right through (as 32 i1's and 1 i32 are the same buffer).
Yeah this was the clarification I was hoping for. We should probably define the expected types at
For now its probably best to stick to i8 expansion as this is what we assume for VMLA. I don't think Overall its updated to handle the conversion at the lowering to HAL. Important note - notice |
Support boolean constants in VMLA/LLVM JIT.
Support boolean constants in VMLA/LLVM JIT.
91f192f to
467cd46
Compare
|
I'm still a bit sketched out as this is not consistently applying things. What happens to ops that are acting on these constants? Or values extracted from the constants and used for other purposes? Are there ops that would stop working with the type getting changed? What about constants that are already inlined into dispatch regions and going to other backends like LLVM or SPIR-V? The issue with doing it in the flow->hal conversion is that you are now making a global assertion (that all i1->i8) but only then handling it in one local usage (VMLA constant ops). This indicates that it's too low level: the whole point of having the flow dialect (and whatever frontend dialects that live above it) is that these kind of global transformations can be applied consistently and that subsequent lowerings don't need to know about these implicit semantics. I understand just wanting to land some constant bools, but these kind of changes are really hard to debug later on and can greatly complicate backend implementations (that can no longer rely on consistency across the ABI boundary). It's a lot of work to unwind the existing i64->i32 implicit conversions and I'd really like to avoid adding new things like that.
|
I think this stems from not having a clearly define boolean representation. Operations in
Similar problem to mentioned above - at this point we dont clearly specify the specify
This is understandable, but for boolean operations we need to establish how to handle sub
So the problem with LegalizeInputTypes is that it occurs separately from the lowering to HALBuffers. This means when the i1->i8 conversion occurs any operations that require I1s At this point I think we need to define a clear plan for boolean types going forward. While |
|
To be clear, boolean and low-bit depth values are not at all the same; you don't perform transcendental math on bools. |
|
I filed some longer term notes here: #3102 For this PR, I really just want to see that this is something that is more than just hack 1/N - if you're going to be next week needing another hack as you start to do more with bools that's going to continue compounding the tech debt here in a part of the code that really can't hold any more. This means doing some legwork to get what you actually want to run together in IR form so it can be analyzed - which it sounds like you're close to. If this change with some issues/TODOs tracking it works well for your extended use cases (again, not just defining a const value) then it's ok to land and clean up later, but this limited usage doesn't instill much confidence (spoken from experience having written the other hacks that are now causing much pain :). |
Support boolean constants at the HAL -> VM lowering