Long compile for OpenCV3 dls.cpp when targeting cortex-a53
| Bugzilla Link | 25794 |
| Resolution | FIXED |
| Resolved on | Nov 07, 2018 00:21 |
| Version | trunk |
| OS | Linux |
| Blocks | llvm/llvm-project#21794 |
| Attachments | failing preprocessed source + shell script |
| CC | @Arnaud-de-Grandmaison-ARM,@atrick,@cddouma-arm,@echristo,@hfinkel,@kbeyls,@JonPsson,@pirama-arumuga-nainar,@stephenhines,@vedantk |
Extended Description
When compiling dls.cpp in external/opencv3 (from Android's AOSP tree), we discovered that -mcpu=cortex-a53 caused the compilation to go from ~8 seconds to ~30 minutes! Removing this -mcpu flag or switching to -O1 brings it back to a reasonable compile time.
clang++ -c -fno-exceptions -Wno-multichar -fno-strict-aliasing -fstack-protector -ffunction-sections -fdata-sections -funwind-tables -Werror=format-security -D_FORTIFY_SOURCE=2 -fno-short-enums -no-canonical-prefixes -Werror=pointer-to-int-cast -Werror=int-to-pointer-cast -Werror=implicit-function-declaration -DANDROID -fmessage-length=0 -W -Wall -Wno-unused -Winit-self -Wpointer-arith -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -DNDEBUG -O2 -g -Wstrict-aliasing=2 -DNDEBUG -UDEBUG -D__compiler_offsetof=__builtin_offsetof -Werror=int-conversion -Wno-reserved-id-macro -Wno-format-pedantic -Wno-unused-command-line-argument -fcolor-diagnostics -nostdlibinc -target aarch64-linux-android -Bprebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/aarch64-linux-android/bin -fvisibility-inlines-hidden -Wsign-promo -Wno-inconsistent-missing-override -nostdlibinc -frtti -fexceptions -D__OPENCV_BUILD=1 -DCVAPI_EXPORTS -fPIC -Werror=int-to-pointer-cast -Werror=pointer-to-int-cast -Werror=address-of-temporary -Werror=null-dereference -Werror=return-type -MD dls.ii -mcpu=cortex-a53
Verified that dls.cpp compiles reasonably quickly (< 1 minute) after the fix.
Any updates here? This code is still taking a long time to compile even with my update to r256229.
Hi Stephen.
I was running a set of independent load-stores through LLVM with the patch of Jonas applied (http://reviews.llvm.org/D8705). But I quickly ran the reduced IR testcase as well. The results look promising and his patch was recently approved. I assume it will be committed soon.
To give some numbers I've got:
- The reduced IR testcase took 2m18s on my machine when the D8705 patch was applied. A lot better than the previous 30m.
- On 5000 independent load-store pairs I see a 2.9x reduction in compile time and the rate at which the compile time grows is around 3.7x lower than LLVM trunk.
Any updates here? This code is still taking a long time to compile even with my update to r256229.
Thanks for the work on the Machine Scheduler.
I will try to check what it gives in terms of generated code performances on a few of our cores and let you know my findings.
I found that PostRAScheduler is dealing with a block containing 11800 memory accesses, and is therefore very slow.
I am however hopefully about to commit a new way of dealing with memory accesses in buildSchedGraph() - the function that builds the DAG prior to scheduling. I compiled it with my patch, and the compile time was reduced considerably, however still around 2 minutes on my machine (compared to 30?).
(My patch is not fully tested / tuned. It has an algorithm for dealing with huge regions such as this one. There are two options that controls this. By default, -dag-maps-huge-region has a value of 1000, which is the number of nodes before reduction takes place. For this test case I used a value of 50. (With 1000 it was around 4-5 minutes I think).
It would be great if you would try out my patch and help tune it by experimenting with the options. The smaller the value of this option, the higher the risk to decrease output quality, but the faster it goes. We probably want to use a value smaller than 1000, considering this example.
See http://reviews.llvm.org/D8705
It is of course possible to ask if the scheduler input (that many memory accesss) is something that could be avoided. 2 minutes is much less than 30, but still a very long compile time. There are probably ways to avoid this if wanted. If the code should look that way with all those memory accesses, then one could do further handling of huge regions in scheduler. Perhaps one could split such regions before building the DAG at a limit, or one could dynamically set the -dag-maps-huge-region to smaller values the bigger the region.
Reduced IR testcase. The attached .ll file is a "reduced" testcase. The compile time issue can be reproduced with a simple "llc dls.ll".
The problem is with the entry BB in funtion @ZN3dls11cayley_LS_MERKSt6vectorIdSaIdEES4_S4_S4. This is a big basic block, with about 25k instructions (10k loads, 2k stores), and the Machine PostRa scheduler exhibits some quadratic behaviour when trying to compute dependencies between the load & stores.
According to -ftime-report, clang spends 97.6% of its wall time in PostRA Machine Instruction Schedule, 2.3% in Debug Variable Analysis, and the rest is noise.
I can reproduce the long compilation time with -mcpu=cortex-a53 or -mcpu=cortex-a57. Removing the -mcpu flag brings back reasonable compilation time.