iree icon indicating copy to clipboard operation
iree copied to clipboard

[Python API] Fix python api for bytecode

Open maxbartel opened this issue 1 year ago • 1 comments

This fixes an issue seen in https://github.com/iree-org/iree/pull/17278. MLIR bytecode can have a zero as the last byte depending on the IR. If this happens by accident parsing will fail. This PR checks if a buffer begins with the magic number from https://mlir.llvm.org/docs/BytecodeFormat/#magic-number and sets zero-termination to false if it does.

However I could not generate MLIR bytecode that ends with a zero other than the one in the PR. Even if I save the IR used in textual format and parse it again, some additional bytes are appended and it is not zero terminated anymore. I think this is because of some behavior in TF.

Still after reading a bit through https://mlir.llvm.org/docs/BytecodeFormat I think the check implemented in this PR is the correct behavior for bytecode.

maxbartel avatar May 10 '24 14:05 maxbartel

Ugh, that broken llvm API strikes again. Thanks for the fix. Will review in detail soon, since this has been a trouble area and I need to focus on it

stellaraccident avatar May 10 '24 14:05 stellaraccident

Force pushed because of DCO

maxbartel avatar Jun 25 '24 13:06 maxbartel