Use jemalloc where available for ~6% performance improvement - #3514
Use jemalloc where available for ~6% performance improvement#3514Majora320 wants to merge 2 commits into
Conversation
We're trying our best :'( Although I gotta say the last time anyone checked, VtR was actually ~30% faster than Quartus. FPGA CAD is just that hard. I personally like the implementation here, not super intrusive and nothing bad happens if jemalloc is not installed on user machines. Approved the CI tests to see if everything works as expected. Can you test the whole Titan benchmark suite to see gains on a more diverse set of circuits? You can run them using:
The run_vtr_task script outputs a file in vtr_flow/tasks/regression_tests/vtr_reg_nightly_test2/titan_quick_qor/run[num] called parse_results.txt or something. You can copy that into google sheets to get all the relevant numbers. Please also check memory usage. I don't expect meaningful changes in large circuits, but the new allocator probably gets memory pages from the OS in a different way and I'm seeing some CI failures in smaller tests because of higher memory usage. They do take a while to run (sorry!) and I would probably not put in -j8 because of memory usage. I think dividing your RAM by 8 would give you a fairly safe number of benchmarks you can run at the same time. |
|
Looks like one testcase uses more memory and is causing a QoR failure: We put bounds on our QoR metrics to keep noise down, so it is possible that this is overall good for memory usage and runtime, and this one case is a fluke. I agree with @AmirhosseinPoolad here that we need to see the results on more testcases to bring something like this in. |
|
I proposed something like this in #3189. I continued down this road a bit further but never finished the project at that time. I wanted to note that, when expanding testing to different test cases, you should be sure to test different VTR modes. I found large runtime improvements when no routing channel size was specified and VTR searched for it automatically. However, when I set a fixed channel size and it ran one complete flow, the runtime improvements were greatly diminished. This is obvious in hindsight, since VTR is basically relaunching parts of the flow over and over again with some kind of reallocation each time. But I tripped over obvious things like this when I first went down this path. I also was not sure if there is a clear tradeoff between runtime and memory usage that the VTR developers would prefer. For example, how much memory overhead is acceptable for a given runtime speedup? I assumed that runtime improvements far outweigh any memory overhead, but I have not used VTR in any industrial use cases where even the baseline memory usage is quite large. Any insight into this would definitely be interesting. |
|
The two regtest failures are not a real concern; they are small QoR changes (memory footprint) on the same tiny design. They can be resolved by updating the golden results. They key thing we'd need to merge this would be a full QoR run as @AmirhosseinPoolad noted. If you don't have a machine that can run that, perhaps Ayan could help. |
vaughnbetz
left a comment
There was a problem hiding this comment.
The code changes look minimally intrusive and hence fine.
A quick web search shows jemalloc isn't supposed to support valgrind; not sure how you've worked around this (turned off jemalloc for some builds?) as we do use valgrind, and wouldn't want to lose it. If this implicitly makes valgrind not work, we'd need to figure out a solution to that too.
So outstanding list is:
- Bigger QoR experiment
- valgrind status / interaction
- update golden results on the two failing tests
|
We should also disable jemalloc when VTR_ENABLE_SANITIZE is set, as ASan also replaces malloc |
|
I ran valgrind on the jemalloc build and did not run into any issues; all the information seems to have been preserved. I'd need a +1 on this, though, since I've used ASan more than I've used valgrind... |

Description
jemalloc is an alternative allocator that provides better performance than the default glibc malloc in most situations, especially for memory-heavy applications. This PR uses jemalloc by default when available and adds it to the default install lists.
Motivation and Context
vtr is slow. Anything that shaves a few seconds off each iteration is useful.
How Has This Been Tested?
I tested jemalloc locally on a 7800X3D along with tcmalloc and micalloc, two other popular allocator options. The following command was used:
Here is a table of times and relative improvements.
time)As you can see, jemalloc shaves about 6% off of total execution time and reduces peak memory usage by about 4%.
Please let me know if any documentation changes are required as a result of this change. Thanks :)
Types of changes
Checklist: