Repository navigation
Add EmitC support for f32 arithmetic ops - #5872
Conversation
416239b to
769785d
Compare
|
Rebased and added support for |
769785d to
e108b5d
Compare
| // ExtF32: Native floating-point arithmetic | ||
| patterns.insert<CallOpConversion<IREE::VM::AddF32Op>>(context, "vm_add_f32"); | ||
| patterns.insert<CallOpConversion<IREE::VM::SubF32Op>>(context, "vm_sub_f32"); | ||
| patterns.insert<CallOpConversion<IREE::VM::MulF32Op>>(context, "vm_mul_f32"); |
There was a problem hiding this comment.
200 lines of boilerplate code... this could be generated or assisted with a macro. WDYT?
(fine to land as-is, just wondering how we could make this easier to work on in the future)
There was a problem hiding this comment.
Definitely worth to think about a better solution. I think it could be possible to send a follow up where we have a single patterns.intert<> call. However, we still need to pass all the VM ops that can be converted to EmitC via the pattern. So I don't know if this removes the boilerplate much, which we also have in other places. For example see https://github.com/google/iree/blob/739a596b52226cd0539752ffa7bcce514234afa1/iree/compiler/Dialect/VM/Conversion/StandardToVM/ConvertStandardToVM.cpp#L778-L798
There was a problem hiding this comment.
We discussed this internally and it should be indeed doable to have a single patterns.insert call. The C functions name to call could be either generated via tablegen or one could move the mapping into the CallOpConversion. However, this somehow moves the boilerplate, but does not really reduce it. Your thoughts @ScottTodd?
There was a problem hiding this comment.
I don't really have much of an opinion on how the code is set up other than
- modifying this set of conversions should be easy (the current structure is easy to edit but risks missing conversions)
- if the set of conversions is 1:1 with no special cases then it could be fully generated, which would make it impossible to miss conversions
We have many other conversion patterns in the project, but these look particularly mechanical.
There was a problem hiding this comment.
I don't really have much of an opinion on how the code is set up other than
* modifying this set of conversions should be easy (the current structure is easy to edit but risks missing conversions)
That is true, but ...
* if the set of conversions is 1:1 with no special cases then it could be fully generated, which would make it impossible to miss conversions
... unfortunately, this is not a full 1:1 set. E.g. constants
https://github.com/google/iree/blob/5de65494a0edea0db932ac5f16a883c1bb8e8cb9/iree/compiler/Dialect/VM/Conversion/VMToEmitC/ConvertVMToEmitC.cpp#L652-L654
are not converted via a CallOpConversion and also lists vm.listas well as other ops need different conversions. For those we do not call functions in iree/vm/ops.h and generate more complex code instead. An (old) example showing the vm.listallocation is vizualized on slide 17 - 20 in the EmitC slides presented at the ODM last month. So at least for now I think we should land as is.
There was a problem hiding this comment.
An idea for the straightforward ones is as mentioned use tablegen - we already have a custom tblgen for handling the bytecode encoding, and could extend that to also support the c functions. This makes things declarative in all cases but those requiring extra lowering work. I'm not sure it's the most scalable solution though (especially if we add direct LLVM lowering, or something like an emitc# output, etc), so it may not be worth doing.
In general though I'm fine with having lots of one line pattern instantiations like this - it makes it really easy to find/replace them in the code, easy to add new ones (no ambiguity over whether to do it in tablegen or as a pattern or as an instantiation of a templated pattern), and scales linearly with the number of ops (which is fairly bounded).
| // ExtF32: Native floating-point arithmetic | ||
| patterns.insert<CallOpConversion<IREE::VM::AddF32Op>>(context, "vm_add_f32"); | ||
| patterns.insert<CallOpConversion<IREE::VM::SubF32Op>>(context, "vm_sub_f32"); | ||
| patterns.insert<CallOpConversion<IREE::VM::MulF32Op>>(context, "vm_mul_f32"); |
There was a problem hiding this comment.
I don't really have much of an opinion on how the code is set up other than
- modifying this set of conversions should be easy (the current structure is easy to edit but risks missing conversions)
- if the set of conversions is 1:1 with no special cases then it could be fully generated, which would make it impossible to miss conversions
We have many other conversion patterns in the project, but these look particularly mechanical.
No description provided.