Skip to content

Generate a file containing command-line options for translation - #8181

Merged
antiagainst merged 4 commits into
iree-org:mainfrom
antiagainst:print-compilation-options
Feb 2, 2022
Merged

antiagainst merged 4 commits into
iree-org:mainfrom
antiagainst:print-compilation-options

Conversation

@antiagainst

Copy link
Copy Markdown
Member

This will make reproducing the compilation easier, e.g., when debugging.

This will make reproducing the compilation artifact easier, e.g.,
when debugging.
@antiagainst antiagainst added infrastructure/benchmark Relating to benchmarking infrastructure buildkite:benchmark labels Jan 25, 2022
@iree-github-actions-bot

iree-github-actions-bot commented Jan 25, 2022 •

Copy link
Copy Markdown
Contributor

Abbreviated Benchmark Summary

@ commit b1f9f7bc527a3e9ca78228fbe8ad8c5c5cde4323 (vs. base 769036f0e2c501500d3901d2c5059598912a8b4d)

Regressed Benchmarks 🚩

Benchmark Name Average Latency (ms) Median Latency (ms) Latency Standard Deviation (ms)
MobileSSD [fp32] (TFLite) 4-thread,big-core,full-inference,default-flags with IREE-Dylib @ Pixel-6-Pro (CPU-ARMv8.2-A) 121 (vs. 113, 7.08%↑) 121 5

Improved Benchmarks 🎉

Benchmark Name Average Latency (ms) Median Latency (ms) Latency Standard Deviation (ms)
MobileNetV3Small [fp32,imagenet] (TFLite) 4-thread,big-core,full-inference,experimental-flags with IREE-Dylib @ Pixel-4 (CPU-ARMv8.2-A) 10 (vs. 11, 9.09%↓) 10 0
MobileBertSquad [fp32] (TFLite) big-core,full-inference,default-flags with IREE-Dylib-Sync @ Pixel-6-Pro (CPU-ARMv8.2-A) 464 (vs. 494, 6.07%↓) 465 4
MobileNetV3Small [fp32,imagenet] (TFLite) 4-thread,big-core,full-inference,default-flags with IREE-Dylib @ Pixel-4 (CPU-ARMv8.2-A) 16 (vs. 17, 5.88%↓) 16 0

For more information:

@antiagainst
antiagainst marked this pull request as ready for review January 25, 2022 21:32
set(_COMPOPT_FILE "${_RUN_SPEC_DIR}/compilation_flagfile")
add_custom_command(
OUTPUT "${_COMPOPT_FILE}"
COMMAND

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't find an easier way to dump multiple lines into a file, so using an extra Python script. Any other ideas?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Yes I've run into these two before. Here we don't have key/value pairs like normal compiler defines and there are unknown number of different kinds of option strings to be emitted. So using configure_file would mean shorehorning for this specific case. For file, I didn't find a good way to wire it up with custom commands and targets. So not sure they are better than the current way..

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm I think configure_file you can just sub in a list. The documentation mostly talks about cmakedefine, but it will replace @VAR@ or ${VAR} also. It seems like you should also be able to do something with cmake command mode:

add_custom_command(OUTPUT | TARGET ...
    COMMAND ${CMAKE_COMMAND} -E echo "<content-of-the-file>" > "</path/to/file>"
    )

but maybe the shell redirect would make it dependent on bash and mess things up on windows? Ugh it really seems like a python script shouldn't be necessary here, but maybe it's the least bad option

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't looked at the details here, but I don't think we should need a 1 line python file (with 40 lines of supporting flag parsing) to generate a file :P

That would also place yet another fringe dep on python in the build system...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that's my feeling as well :-D Also, is it important that this happen at build time instead of configure time? It seems like using file(WRITE and have it happen at configure time should be fine since it's all based on configure-time information

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The difficulty with cmake -E echo is that it cannot handle newlines. Giving it a string containing \n will cause it generate broken build.ninja file. :)

On a second thought, I actually don't strictly need to use newline as separators. The compilation tools we have does not support --flagfile like the runtime tools we have anyway. So concatenating with " " is fine for now at least. Helps to kick the can down the road a bit. Changed.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LLVM CL parsing supports flagfiles (by a different name), actually: https://llvm.org/docs/CommandLine.html#response-files. Also, you can make configure_file sub in a variable with newlines. It's what LLVM does for some enumeration of macros. See https://github.com/llvm/llvm-project/blob/dbf278b984eebf17a8977e79b67cdb960e9af5db/llvm/CMakeLists.txt#L788 and https://github.com/llvm/llvm-project/blob/main/llvm/include/llvm/Config/AsmPrinters.def.in, for instance. I think that would be better. Then we can actually use the flagfile in the build, also, instead of only putting it somewhere for human reference.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting. Didn't know that you can do @file to inject command-line options for LLVM binaries.. Okay that makes sense then. I switched to use configure_file. Thanks for the suggestion!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, part of my suggestion was to use the flagfile in the actual cmake COMMAND as well. It seems a bit weird to generate it and then not use it in the actual build system

@antiagainst

Copy link
Copy Markdown
Member Author

This is ready for reviews now @GMNGeoffrey @ScottTodd, PTAL. :)

set(_COMPOPT_FILE "${_RUN_SPEC_DIR}/compilation_flagfile")
add_custom_command(
OUTPUT "${_COMPOPT_FILE}"
COMMAND

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LLVM CL parsing supports flagfiles (by a different name), actually: https://llvm.org/docs/CommandLine.html#response-files. Also, you can make configure_file sub in a variable with newlines. It's what LLVM does for some enumeration of macros. See https://github.com/llvm/llvm-project/blob/dbf278b984eebf17a8977e79b67cdb960e9af5db/llvm/CMakeLists.txt#L788 and https://github.com/llvm/llvm-project/blob/main/llvm/include/llvm/Config/AsmPrinters.def.in, for instance. I think that would be better. Then we can actually use the flagfile in the build, also, instead of only putting it somewhere for human reference.

@GMNGeoffrey

Copy link
Copy Markdown
Member

I didn't hit send on my review yesterday, whoops :-/ I think this can be done with configure_file and flagfiles (called response files in LLVM for whatever reason) such that we actually use it in the build and it's a single command for someone to use it

@antiagainst
antiagainst enabled auto-merge (squash) February 2, 2022 17:17
@antiagainst
antiagainst disabled auto-merge February 2, 2022 17:26
@antiagainst
antiagainst merged commit 71ecc2b into iree-org:main Feb 2, 2022
@antiagainst
antiagainst deleted the print-compilation-options branch February 2, 2022 17:27
@GMNGeoffrey GMNGeoffrey added the infrastructure Relating to build systems, CI, or testing label Jul 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

infrastructure/benchmark Relating to benchmarking infrastructure infrastructure Relating to build systems, CI, or testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants