iree-org / iree

A retargetable MLIR-based machine learning compiler and runtime toolkit.
http://iree.dev/
Apache License 2.0
2.82k stars 609 forks source link

vmvx not support math.roundeven #13488

Closed hcindyl closed 1 year ago

hcindyl commented 1 year ago

What happened?

See iree-org/iree-samples daily regression log https://github.com/iree-org/iree-samples/actions/runs/4927296893/jobs/8804087598

llvm backend has been fixed with https://github.com/llvm/llvm-project/commit/8d2bae9abdc30e104bab00a4dd0f9d39f5bdda6e, however, for iree-compile vmvx backend, it seems the op is explicitly marked as illegal

<unknown>:0: error: loc(callsite("tfl.quantize" at "main")): failed to legalize operation 'math.roundeven' that was explicitly marked illegal

Steps to reproduce your issue

iree-compile /home/runner/work/iree-samples/iree-samples/tflitehub/tmp/mobilebert_tf2_quant_test.py/tosa.mlir --iree-input-type=tosa --iree-vm-bytecode-module-output-format=flatbuffer-binary --iree-hal-target-backends=vmvx -o=/home/runner/work/iree-samples/iree-samples/tflitehub/tmp/mobilebert_tf2_quant_test.py/module.bytecode --iree-llvmcpu-embedded-linker-path=/opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/iree/compiler/tools/../_mlir_libs/iree-lld --mlir-print-debuginfo --mlir-print-op-on-diagnostic=false

Error:

<unknown>:0: error: loc(callsite("tfl.quantize" at "main")): failed to legalize operation 'math.roundeven' that was explicitly marked illegal
<unknown>:0: note: loc("main"): called from
<unknown>:0: error: loc(fused[callsite("model/bert_span_labeler/mobile_bert_encoder/transformer_layer_0/attention/edge_tpu_softmax/add" at "main"), callsite("model/bert_span_labeler/mobile_bert_encoder/self_attention_mask/mul" at "main"), callsite("tfl.quantize" at "main"), callsite("model/bert_span_labeler/Cast" at "main")]): conversion to vm.module failed
<unknown>:0: note: loc("main"): called from
<unknown>:0: error: loc(fused[callsite("model/bert_span_labeler/mobile_bert_encoder/transformer_layer_0/attention/edge_tpu_softmax/add" at "main"), callsite("model/bert_span_labeler/mobile_bert_encoder/self_attention_mask/mul" at "main"), callsite("tfl.quantize" at "main"), callsite("model/bert_span_labeler/Cast" at "main")]): failed to run translation of source executable to target executable for backend #hal.executable.target<"vmvx", "vmvx-bytecode-fb", {ukernels = false}>
<unknown>:0: note: loc("main"): called from
<unknown>:0: error: loc(fused[callsite("model/bert_span_labeler/mobile_bert_encoder/transformer_layer_0/attention/edge_tpu_softmax/add" at "main"), callsite("model/bert_span_labeler/mobile_bert_encoder/self_attention_mask/mul" at "main"), callsite("tfl.quantize" at "main"), callsite("model/bert_span_labeler/Cast" at "main")]): failed to serialize executables
<unknown>:0: note: loc("main"): called from

What component(s) does this issue relate to?

No response

Version information

iree-compiler>=20230503.508

Additional context

No response

hcindyl commented 1 year ago

@jpienaar FYI

jpienaar commented 1 year ago

I think this is due to the expansion of roundevenf is not called along the path it was enabled ( https://github.com/openxla/iree/commit/68439a0e074b6c847d2b74d27193c82d618212e9 - I think moving like 38 to 33 there should do it and there was miscommunication in PR)

hcindyl commented 1 year ago

Thanks, let me try it out.

hcindyl commented 1 year ago

@jpienaar unfortunately move L38 to L33 of https://github.com/openxla/iree/blob/68439a0e074b6c847d2b74d27193c82d618212e9/compiler/src/iree/compiler/Codegen/Common/PolynomialApproximationPass.cpp#L29-L39 does not work

math.roundeven is still illegal with vmvx backend https://gist.github.com/hcindyl/31ff1438d6b4377f4f1fb42e1a00dc41