Skip to content

Adding a minimal flag parser. - #5602

Merged
benvanik merged 6 commits into
mainfrom
benvanik-flags
Apr 28, 2021
Merged

benvanik merged 6 commits into
mainfrom
benvanik-flags

Conversation

@benvanik

@benvanik benvanik commented Apr 24, 2021 •

Copy link
Copy Markdown
Collaborator

It does most of what we want without any C++ in 3 modes:

  • entirely disabled (turned into some static variables)
  • argc/argv parser only for main()
  • flagfile parsing that uses fopen/fread

It also has the nifty property of a round-tripping mode that lets you
get all the current flag values and pipe them to a file to then load
back in a flagfile, which should make it easier to reproduce
flag-dependent configurations.

Likely lots of little tweaks remaining (there always are), but this is
enough to start replacing our existing usage of the abseil flags.
Callback flags allow us to support lists (multiple instances of a flag
on the command line) and actions, which aren't great in abseil flags.
This let us change --function_inputs= into just repeated
--function_input= lines which is much easier to deal with for humans
and tools.

Future improvements will be to centralize flag handling for common
tool uses (like specifying entry point/function inputs/etc), adding flags
where previously they were avoided due to the abseil dep (various HAL and
task system stuff), and supporting flagfile when CLI is disabled.

This is now fully traced and we can see all flags parsed in traces:
image

Fixes #3814.

@benvanik benvanik added cleanup 🧹 platform/generic 🔩 Bare metal/generic target build, execution, benchmarking, and deployment labels Apr 24, 2021
@google-cla google-cla Bot added the cla: yes label Apr 24, 2021
@benvanik
benvanik force-pushed the benvanik-flags branch 4 times, most recently from 866dae5 to a5c987c Compare April 24, 2021 17:55
@benvanik

benvanik commented Apr 24, 2021 •

Copy link
Copy Markdown
Collaborator Author

I don't understand the bazel failures - @GMNGeoffrey / @ScottTodd do you recall anything about lit tests and binaries? cmake works by referencing the flags demo as testdata in iree/base/internal/CMakeLists.txt and I copied what's being done in iree/tools/ on the bazel side but it still seems unhappy finding the binary - is there anything I'm missing to wire it up?

@benvanik
benvanik marked this pull request as ready for review April 24, 2021 19:22
@benvanik

Copy link
Copy Markdown
Collaborator Author

the failure on cmake is from a different thing, which is annoying but not the same as the executable not found issue bazel has

@GMNGeoffrey

GMNGeoffrey commented Apr 24, 2021 via email

Copy link
Copy Markdown
Member

@benvanik

Copy link
Copy Markdown
Collaborator Author

In cmake it's iree_base_internal_flags_demo - but maybe that's because it's a test - I'll try changing it to cc_binary instead. I was using cc_test because I want the binary to be run under CI independently (as if a user was running it on the command line, not our test) - if I make it a cc_binary it won't be run. I'd rather have it work, though :)

@benvanik

Copy link
Copy Markdown
Collaborator Author

I made it a cc_binary and it worked - looks like cc_test was missing an output name override so I fixed that anyway.
Now I just need to finally fix the spaces-in-flags issues that has always prevented flags with spaces from working on Windows: this now works on Windows but not on linux ;(

@benvanik

Copy link
Copy Markdown
Collaborator Author

Gave up on fixing spaces for now - the repro for the future is changing // RUN: ( flags_demo --test_string="with some space" to // RUN: ( flags_demo --test_string=\"with some space\" - the former will fail on Windows and pass on Linux, while the latter will pass on Windows and fail on Linux. I suspect it's something with run_test.ps1, run_lit.bat, or something else in that chain of doom.

Future changes will also start to break out api.h.
Comment thread iree/base/internal/flags.h Resolved
Comment thread iree/base/internal/flags.h Resolved
Comment thread iree/base/internal/flags.c Resolved
Comment thread iree/base/internal/flags.c Resolved
Comment thread build_tools/cmake/iree_cc_test.cmake Resolved
Comment thread docs/design_docs/cuda_backend.md Resolved
Comment thread iree/base/BUILD Resolved
Comment thread iree/base/internal/flags.c Resolved
Comment thread iree/base/internal/flags.c Resolved
Comment thread iree/base/internal/flags.h Resolved
Comment thread iree/base/internal/flags.h Resolved
Comment thread iree/base/internal/flags_test.txt Resolved
Comment thread iree/base/internal/flags_test.txt Resolved
Comment thread iree/base/internal/flags_test.txt Resolved
Comment thread iree/base/internal/BUILD Resolved
@GMNGeoffrey
GMNGeoffrey requested a review from bjacob April 28, 2021 17:20
@benvanik
benvanik merged commit db7f611 into main Apr 28, 2021
@benvanik
benvanik deleted the benvanik-flags branch April 28, 2021 17:41
@bjacob
bjacob removed their request for review April 28, 2021 17:42
@ThomasRaoux

Copy link
Copy Markdown
Contributor

This seem to break Android. @benvanik is this expected?

https://buildkite.com/iree/iree-android-arm64-v8a/builds/4090#54694e40-157a-484e-97b7-b3a874676ee5

+ '[' -n '' ']'
--
  | + '[' -n /data/local/tmp/iree/base/string_view_test/test_tmpdir ']'
  | + adb shell 'mkdir -p /data/local/tmp/iree/base/string_view_test/test_tmpdir'
  | + tmpdir=TEST_TMPDIR=/data/local/tmp/iree/base/string_view_test/test_tmpdir
  | + adb shell 'cd /data/local/tmp && LD_LIBRARY_PATH=/data/local/tmp TEST_TMPDIR=/data/local/tmp/iree/base/string_view_test/test_tmpdir iree/base/string_view_test/iree_base_string_view_test'
  | /system/bin/sh: iree/base/string_view_test/iree_base_string_view_test: inaccessible or not found

 

@benvanik

benvanik commented Apr 28, 2021 •

Copy link
Copy Markdown
Collaborator Author

ah this is from the cmake executable name change - the executables are now matching the bazel names, so here it would be string_view_test not iree_base_string_view_test - is this a script that is calling that with that name?

@benvanik

Copy link
Copy Markdown
Collaborator Author

it looks like the file makes it to the device with the right name but then gets run with the wrong old one:
image
I'm not sure how any of this infra works - I'll try to dig in a bit

@benvanik

Copy link
Copy Markdown
Collaborator Author

Possible fix here #5660 - will kick off a benchmark run to test (though it concerns me that our cmake_android_arm64-v8a kokoro build did not find this - does it not run anything?)

@GMNGeoffrey

Copy link
Copy Markdown
Member

will kick off a benchmark run to test

Should just need the android correctness testing. No need to benchmark (and I don't think benchmarking should be running that test)

though it concerns me that our cmake_android_arm64-v8a kokoro build did not find this - does it not run anything?

It just builds, doesn't run any tests, since testing currently requires a real android device. Ahmed is working on an emulator build.

@benvanik

Copy link
Copy Markdown
Collaborator Author

(ah yeah meant "buildkite")
Fix in #5660 seems to be good and is merged now!

copybara-service Bot pushed a commit that referenced this pull request Apr 29, 2021
* 36522d9 Rotating instead of shifting to deal with overflow. (#5674)
* e130e79 Merge pull request #5671 from ThomasRaoux/handle_vectorization
* 011ffe0 Merge google -> main (#5663)
* 6e16e38 Add vector transfer canonicalization patterns (#5664)
* 95b3030 Add mobilenet_v3 to slim_vision_model_test.py (#5650)
* 0c30c12 Fixing iree_cc_test android goo to use the proper executable name. (#5660)
* cb54341 Adding initial executable benchmarking tool. (#5604)
* 1de68ee Adding iree_task_executor_create_from_flags. (#5616)
* db7f611 Merge pull request #5602 from google/benvanik-flags

COPYBARA_INTEGRATE_REVIEW=#5673 from ThomasRaoux:main-to-google c08d5bd
PiperOrigin-RevId: 371123718
iree-github-actions-bot pushed a commit that referenced this pull request Apr 29, 2021
* 36522d9 Rotating instead of shifting to deal with overflow. (#5674)
* e130e79 Merge pull request #5671 from ThomasRaoux/handle_vectorization
* 011ffe0 Merge google -> main (#5663)
* 6e16e38 Add vector transfer canonicalization patterns (#5664)
* 95b3030 Add mobilenet_v3 to slim_vision_model_test.py (#5650)
* 0c30c12 Fixing iree_cc_test android goo to use the proper executable name. (#5660)
* cb54341 Adding initial executable benchmarking tool. (#5604)
* 1de68ee Adding iree_task_executor_create_from_flags. (#5616)
* db7f611 Merge pull request #5602 from google/benvanik-flags

PiperOrigin-RevId: 371123718
@ThomasRaoux

Copy link
Copy Markdown
Contributor

@benvanik Android benchmark as still crashing, did you expect such problem?

subprocess.CalledProcessError: Command '['adb', 'shell', 'LD_LIBRARY_PATH=/data/local/tmp', 'taskset', '80', '/data/local/tmp/benchmark_tmpdir/iree-benchmark-module', '--flagfile=/data/local/tmp/benchmark_tmpdir/mobile-bert_flagfile', '--module_file=/data/local/tmp/benchmark_tmpdir/mobile-bert_Pixel4_vmla.vmfb', '--driver=vmla', '--benchmark_repetitions=10']' returned non-zero exit status 1.
``` 

https://buildkite.com/iree/iree-android-benchmark/builds/2413#66b1f382-b410-4518-a02e-e23c4f4f2169

@benvanik

Copy link
Copy Markdown
Collaborator Author

I don't know what the benchmarks are doing, would have to look into that. Android buildkite passed though (https://buildkite.com/iree/iree-android-arm64-v8a/builds/4093) so it's probably something with the flags that are being generated for benchmarks. It'd be really nice if the benchmark script reported stdout/stderr instead of swallowing it - hard to tell what to fix :/

@benvanik

Copy link
Copy Markdown
Collaborator Author

oh, they are still using --function_inputs, which is gone now.

@benvanik

Copy link
Copy Markdown
Collaborator Author

I don't see anything in the repo using --function_inputs, so this must be something outside of the repo. I think @hanhanW will need to take a look.

@benvanik

Copy link
Copy Markdown
Collaborator Author

specifically, the flagfile being passed to android is:

--module_file=/tmp/iree/modules/MobileBertSquad/iree_vmla/compiled.vmfb
--driver=vmla
--function_inputs=1x384xi32=[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0], 1x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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
--entry_function=serving_default

I don't know where that comes from, but it needs to be updated to have multiple --function_input=s instead of one --function_inputs=.

@ThomasRaoux

Copy link
Copy Markdown
Contributor

Ha makes sense, I think those are on google drive. @antiagainst do you know?

@antiagainst

Copy link
Copy Markdown
Member

Yeah, it's hosted on Google Storage Bucket.. I can point you to the internal links.

@ThomasRaoux

Copy link
Copy Markdown
Contributor

Yeah, it's hosted on Google Storage Bucket.. I can point you to the internal links.

I'll update those to see if it solves it.

sleffler pushed a commit to AmbiML/sparrow-scripts-full that referenced this pull request Oct 11, 2022
iree-run-module changes flag mechanism in
iree-org/iree#5602. Update the script accordingly.

Change-Id: If2af370b06055055fc8e6eaec50fdc9b235e1eac
GitOrigin-RevId: a12f7da14acb29d3ee2f317d9ca5704f589d9e07
KevinZJX pushed a commit to KevinZJX/fork_opensecura_scripts that referenced this pull request Feb 23, 2026
iree-run-module changes flag mechanism in
iree-org/iree#5602. Update the script accordingly.

Change-Id: If2af370b06055055fc8e6eaec50fdc9b235e1eac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cleanup 🧹 platform/generic 🔩 Bare metal/generic target build, execution, benchmarking, and deployment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Replace usage of abseil flags in runtime binaries with something reasonable

6 participants