Repository navigation
Add tool to collect compilation statistics - #9227
Conversation
55ac611 to
c80a276
Compare
88bb279 to
cf1c7c6
Compare
Abbreviated x86_64 Benchmark Summary (experimental)@ commit 13dfb05c84a7ed3a2eab3346740797bf23fdbdce (vs. base f90a3a13807b312407d08a20965a6b5774e3371b) Regressed Benchmarks 🚩
For more information: |
| if identified_names != set(size_map.keys()): | ||
| raise AssertionError( | ||
| f"Unrecognized components in the module: {size_map.keys()}.") |
There was a problem hiding this comment.
This shouldn't be an assertion error, since it comes from parsing external input.
There was a problem hiding this comment.
Changed to RuntimeException.
| if not module_path: | ||
| raise AssertionError( | ||
| f"Can't find the module file in the flagfile: {flagfile_path}") |
There was a problem hiding this comment.
Same. This should not be an AssertionError. Also the AssertionError in main below
There was a problem hiding this comment.
I didn't find a good built-in exception, use the generic RuntimeException instead.
| return { | ||
| "model_name": self.model_name, | ||
| "model_tags": self.model_tags, | ||
| "model_source": self.model_source, | ||
| "target_arch": self.target_arch, | ||
| "bench_mode": self.bench_mode, | ||
| } |
There was a problem hiding this comment.
I think you can use asdict, which will also work for recursive dataclasses. I think ultimately the right way to do this is to use a custom json encoder/decoder rather than having extra methods on each dataclass
| return { | |
| "model_name": self.model_name, | |
| "model_tags": self.model_tags, | |
| "model_source": self.model_source, | |
| "target_arch": self.target_arch, | |
| "bench_mode": self.bench_mode, | |
| } | |
| return self.asdict() |
Again, with this replacement, it's not clear that the extra method is really worth it.
There was a problem hiding this comment.
asdict() can recursively serialize the dataclass. So I removed all to_json_object() methods and just let caller to serialize it.
|
Kindly ping : ) |
|
I don't think I can help much here. I'll leave it to @GMNGeoffrey and @antiagainst :) |
| with zipfile.ZipFile(module) as module_zipfile: | ||
| size_map = dict( | ||
| (info.filename, info.file_size) for info in module_zipfile.infolist()) |
There was a problem hiding this comment.
The file size of binaries often has surprisingly coarse granularity and tracking just that may fail to observe incremental code size increase, until some threshold is reached and the file size finally bumps. In my experience (and that is what we have converged on in internal google CI for code size regression tests), something that works reasonably well is size -A <thefile>, and then look at the last line, Total. Here is an example. Consider these two small C++ shared libraries, foo and bar:
benoitjacob@desk:~$ cat foo.cc
#include <unordered_map>
int foo(int a, int b) {
std::unordered_map<int, int> m;
m[a] = b;
m[b] = a;
return m[a] + m[b];
}
benoitjacob@desk:~$ cat bar.cc
#include <unordered_map>
int foo(int a, int b) {
std::unordered_map<int, int> m;
m[a] = b;
m[b] = a;
m[a + b] = a - b;
m[a - b] = a + b;
if (m.count(123)) return 456;
return m[a] + m[b];
}
benoitjacob@desk:~$ clang++ foo.cc -g0 -O2 -shared -fPIC -o /tmp/foo.so
benoitjacob@desk:~$ clang++ bar.cc -g0 -O2 -shared -fPIC -o /tmp/bar.so
benoitjacob@desk:~$ ls -l /tmp/{foo,bar}.so
-rwxr-xr-x 1 benoitjacob primarygroup 17232 Jun 10 10:11 /tmp/bar.so
-rwxr-xr-x 1 benoitjacob primarygroup 17232 Jun 10 10:11 /tmp/foo.soSo both libraries, foo.so and bar.so, have the same file size, 17232 bytes, despite bar doing a bit more work.
Fortunately, size can see the difference:
benoitjacob@desk:~$ size -A /tmp/foo.so | grep Total
Total 5966
benoitjacob@desk:~$ size -A /tmp/bar.so | grep Total
Total 6602This is a > 10% code size increase!
There was a problem hiding this comment.
Thanks! @bjacob , sorry I didn't pay enough attention to it.
I was thinking that we might also have similar issues on other payloads (E.g., SPIR-V flatbuffer), so I preferred not to do ad-hoc things for dynamic libraries first. I'll spend some time checking the better ways to do this #9436.
Just tried to think about the cause of the difference, I guess that might be due to the alignment of the ELF section, so each section is padded to the page size.
There was a problem hiding this comment.
👍
agree it looks like some kind of alignment. but in my experience, it's often more than page size. i seem to remember it was 64k in internal google android aarch64 builds of TFlite. It might depend on things like relocations, which can create a use for having some extra space in the file (presumably the reason why the file itself matters is that it gets memory-mapped when the binary is loaded, so the file layout becomes the memory layout, and then the binary loader still needs to perform relocations on that). If it really is relocations that are the issue, then IREE should be less affected than TFLite, though.
Inspired by #9167, this tool parses the zip info of vmfb and the ninja build log to get the binary size (dispatch libraries) and the module compilation time.
There are 4 sizes to be retrieved:
The class
BenchmarkCasenow also parses the model name into the name and tags.