-
Notifications
You must be signed in to change notification settings - Fork 557
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Output more friendly to incremental compilation #2140
Comments
I'm curious what sort of speed up you see with inlining off, I wouldn't have expected much improvement, since as you noted any change to the symbol table (inlining or not) recompiles. A caution there's likely bugs hiding as -Oi isn't tested much.
It's an interesting debate as to if there should be any uses of "this". The reason that vlSymsp wasn't used for everything (e.g. remove this and have only vlSymsp) is an attempt of V3Combine to look for code that is used in several instantiations and change that to be relative to the instance. I think there's great opportunities for better combining to help the Icache, which also helps compiling as less to compile. But anyhow, an alternative to "this" would certainly be to build static functions that take two arguments (Syms vlSymsp, module_class __Vthis). If you are willing I'd suggest this as the first experiment, as it will likely help compile time and is likely runtime performance neutral so wouldn't need a switch. Once you do that I think a second-order change we may need would be to improve the csplit and function numbering. As it is now, if an 'early' function gets larger or inserted this can cause not just the file with its implementation, but all of the 'later' functions to be numbered differently and/or land in different files, basically recompiling everything. I think a good algorithm for this would be to hash all function contents, name them based on that. Then determine total size, use csplit to determine number of files, then put each function into those N files based on their hashed name. Now if a function internal changes you have only one or 2 recompilations, the "old" file it was in, and the "new" file it goes into. Verilator once had something like you suggest using pimpl (pointer-to-implementation pointers) in __Syms.h. The problem was every scope reference required a pointer indirection, which was bad for It always seems broken that C/C++ has such a horrible need to have variables in the header, with only pimpl as a workaround. A hack we could experiment with is whereby Verilator determines the size of each symbol table, and use a union to make only certain sections visible when compiling. E.g. 100 variables would be a union of those variables and e.g. 100 bytes. We assert the full variables fit in the 100 bytes. If a C file needs to see inside this structure/module, it uses the full structure variable names. If a C file doesn't need to look inside, it uses ifdefs to see only the 100 byte part of the union. If Verilator always rounds the space needed by the variables up so e.g. 128 bytes are used, a submodule that does not refer to the inner variables will not need to recompile when variables change as long as they don't blow past 128 bytes. The great thing about this is it will be as fast as the existing code as there's still a single vSymsp, but incremental compiles are much better, in theory better than pimpl as we can build the exposure as fine as every unique output file, not just module boundaries.
The ugly part is Verilator needs to be very good at calculating the hidden size, and this needs to include predicting padding. The good thing is this is fairly easy to make optional; we use "hidden[0]" and turn on all EXPOSED ifdefs, none of the consumer code changes at all. Also note issue #1572, which if we got working well would allow you to manually partition large sections of the design for completely independent compilation. BTW for some very large designs this has been being done manually e.g. only a single CPU is Verilated then multiple CPUs manually inserted into an ASIC under SystemC or a manual C++ wrapper. |
@toddstrader who might be interested. |
I once did small experiment to reduce verilating time and C++ compile time for larger design which includes multiple instances of big modules. When I disabled per-instance(per-scope) optimization inf V3Gate, all instances of a module share the C++ function.
I am wondering if the following approach works.
Verilating time and memory consumption is expected to be largely reduced for a repeated design such as multi-core processors. C++ compile time will be also reduced. Even for a design without repetition, ccache is expected to work well because untouched module is expected to be the same C++ code. (BTW I saw a phenomenon that verilated C++ code differs time to time from the same Verilog though the simulation result is identical. |
Disabling inlining is my workaround for what you described as csplit moving things around and hence making ccache useless. ccache then helps during development iterations and brings the build time from 40 minutes on a bad day to 3 minutes if I only change logic.
Agreed, that is what I was trying to get at. I might not get to this in the next few weeks due to other commitments but I will make an attempt when I have a bit of bandwidth. The idea of using conditional unions to expose only required bits of the symbol table is very interesting. Regarding the problem of Verilator having to predict padding, an alternative would be to invoke the compiler on a stub file from the verilated makefile as a first compilation step, which can yield the exact structure sizes used by that particular compiler, and then feed this back into the actual compilation phase. It is a bit of a gross hack, but would mean that Verilator need not bee aware of the padding habits of various compilers. Regarding manual partitioning and protect-lib, that is certainly an option for homogeneous architectures or for chip level 'loosely coupled' blocks, but sadly what I am fighting with at the moment is a highly heterogeneous accelerator where there isn't much re-use of functionality, and the whole thing is tightly interconnected so while partitioning it manually would be possible, it would certainly not be a trivial exercise.
I have noticed that too, eyeballing it it was mostly the clock sensitivity lists being ordered differently, but it seems to only happen when a rebuild would be needed anyway due to symbol table changes. |
Another step towards verilator#2958/verilator#2140. Make the mentioned generated functions static for modules (but not for classes).
commit 6fd48da Author: Wilson Snyder <wsnyder@wsnyder.org> Date: Mon Jun 7 07:47:15 2021 -0400 Untabify cmakefiles. No functional change. commit b976b8d Author: Wilson Snyder <wsnyder@wsnyder.org> Date: Sun Jun 6 22:09:30 2021 -0400 Fix slowdown in elaboration (verilator#2911). commit c238d3d Author: github action <action@example.com> Date: Sun Jun 6 23:57:41 2021 +0000 Apply clang-format commit 0edf1f0 Author: Geza Lore <gezalore@gmail.com> Date: Mon Jun 7 00:56:30 2021 +0100 Add ccache-report target to standard Makefile (verilator#3011) Using the standard model Makefile, when in addition to an explicit target, the target 'ccache-report' is also given, a summary of ccache hits/misses during this invocation of 'make' will be prited at the end of the build. commit 31bb73e Author: Wilson Snyder <wsnyder@wsnyder.org> Date: Sun Jun 6 19:32:48 2021 -0400 Fix MCD close also closing stdout (verilator#2931). commit 8f2e4f6 Author: Wilson Snyder <wsnyder@wsnyder.org> Date: Sun Jun 6 10:32:50 2021 -0400 Fix clang warning. commit 2158a45 Author: Wilson Snyder <wsnyder@wsnyder.org> Date: Sun Jun 6 10:27:44 2021 -0400 Tests: Reenable 18.04 MT (verilator#2963). commit 1e89392 Author: Wilson Snyder <wsnyder@wsnyder.org> Date: Sun Jun 6 10:27:01 2021 -0400 Add --expand-limit argument (verilator#3005). commit b0c1ac7 Author: Martin Schmidt <martin.schmidt@epita.fr> Date: Sun Jun 6 15:27:44 2021 +0200 Add support of --trace-structs parameter for CMake (verilator#2986) commit 1f19e8e Author: Wilson Snyder <wsnyder@wsnyder.org> Date: Sun Jun 6 09:17:56 2021 -0400 Tests: Add test case for verilator#2895. commit 258d9ad Author: Geza Lore <gezalore@gmail.com> Date: Sat Jun 5 17:40:56 2021 +0100 Aid IDE code linking in V3AstNodes.h (verilator#3009) commit fa06357 Author: Miodrag Milanović <mmicko@gmail.com> Date: Fri Jun 4 18:04:55 2021 +0200 Fix Makefiles to support Windows EXEEXT usage (verilator#3008). commit eea7e1b Author: Geza Lore <gezalore@gmail.com> Date: Fri Jun 4 15:00:13 2021 +0100 Do not emit leading spaces on blank lines (verilator#3007) commit fb561d9 Author: Wilson Snyder <wsnyder@wsnyder.org> Date: Thu Jun 3 21:19:11 2021 -0400 Commentary (verilator#2996) commit 9f5eb8f Author: Wilson Snyder <wsnyder@wsnyder.org> Date: Thu Jun 3 21:15:42 2021 -0400 Commentary commit 1f331bd Author: Julien Margetts <56540603+margej@users.noreply.github.com> Date: Tue Jun 1 14:01:18 2021 +0100 Fix part select issues in LATCH warning. (verilator#2948) (verilator#2938) commit 2143bcf Author: Wilson Snyder <wsnyder@wsnyder.org> Date: Mon May 31 22:46:41 2021 -0400 Fix constant function calls with uninit value (verilator#2995). commit e1f9fff Author: Geza Lore <gezalore@gmail.com> Date: Mon May 31 13:40:22 2021 +0100 Fix --protect-ids when using SV classes (verilator#2994) A few names were incorrectly mangled, which made --protect-ids produce invalid output when certain SV class constructs were uses. Now fixed and added a few extra tests to catch this. commit e4dcbb2 Author: Pieter Kapsenberg <pieter.kapsenberg@gmail.com> Date: Sun May 30 17:19:35 2021 -0700 Fix unused variable warnings (verilator#2991) commit f4c1a7e Author: Geza Lore <gezalore@gmail.com> Date: Sat May 29 23:46:15 2021 +0100 Emit: Fix indent tracking when // inside string literal (verilator#2990) // was so far unconditionally treated as comment. c443e22 introduced a string literal in the output that contained a http:// url, which broke the indent tracking. No functional change intended commit ef9f477 Author: Geza Lore <gezalore@gmail.com> Date: Sat May 22 18:50:55 2021 +0100 Make _ctror_var_reset and _configure_coverage static. (verilator#2977) Another step towards verilator#2958/verilator#2140. Make the mentioned generated functions static for modules (but not for classes). commit 2dd5ef5 Author: Geza Lore <gezalore@gmail.com> Date: Sat May 22 12:27:32 2021 +0100 Internals: Move --coverage and --savable check out of V3EmitC (verilator#2976) commit a43eba7 Author: github action <action@example.com> Date: Sat May 22 10:14:07 2021 +0000 Apply clang-format commit 61c9866 Author: Geza Lore <gezalore@gmail.com> Date: Sat May 22 11:13:02 2021 +0100 Internals: Generate ASTGEN_SUPER_* macros instead of expanding. (verilator#2975) astgen now generates ASTGEN_SUPER_* macros, instead of expanding the ASTGEN_SUPER itself. This means that V3AstNodes.h itself can be included in V3Ast.h, which helps IDEs (namely CLion) find definitions in V3AstNodes.h a lot better. Albeit this is a little bit more boilerplate, writing constructors of Ast nodes should be a lot rarer than trying to find their definitions, so hopefully this is an improvement overall. astgen will error if the developer calls the wrong superclass constructor. commit 6378255 Author: Wilson Snyder <wsnyder@wsnyder.org> Date: Fri May 21 20:47:53 2021 -0400 Internals: Fix some pylint warnings commit 8814111 Author: Geza Lore <gezalore@gmail.com> Date: Fri May 21 14:34:27 2021 +0100 Rework Ast hashing to be stable (verilator#2974) Rework Ast hashing to be stable Eliminated reliance on pointer values in AstNode hashes in order to make them stable. This requires moving the sameHash functions into a visitor, as nodes pointed to via members (and not child nodes) need to be hashed themselves. The hashes are now stable (as far as I could test them), and the impact on verilation time is small enough not to be reliably measurable. commit fd35492 Author: Geza Lore <gezalore@gmail.com> Date: Fri May 21 01:41:46 2021 +0100 Split V3Hashed to V3Hasher and V3DupFinder (verilator#2967) V3Hasher is responsible for computing AstNode hashes, while V3DupFinder can be used to find duplicate trees based on hashes. Interface of V3DupFinder simplified somewhat. No functional change intended at this point, but hash computation might differ in minor details, this however should have no perceivable effect on output/runtime. Implements (verilator#2964) commit a44d2b2 Author: Geza Lore <gezalore@gmail.com> Date: Thu May 20 11:30:36 2021 +0100 Move unreleased changes in right place in Changelog commit aba3883 Author: Wilson Snyder <wsnyder@wsnyder.org> Date: Wed May 19 08:14:14 2021 -0400 Commentary on MULTIDRIVEN (verilator#2972). commit 9699192 Author: Geza Lore <gezalore@gmail.com> Date: Tue May 18 19:28:48 2021 +0100 Don't merge bit select assignments in C code (verilator#2971) commit 0f7ec6c Author: Wilson Snyder <wsnyder@wsnyder.org> Date: Mon May 17 18:24:18 2021 -0400 Fix missing array include (verilator#2966) commit 471f14d Author: Geza Lore <gezalore@gmail.com> Date: Mon May 17 13:26:24 2021 +0100 Clean up V3Combine (verilator#2965) - Remove dead code - Simplify what is left - Minor improvements using C++11 - Remove special case AstNode constructors used only in one place in V3Combine (inlined instead). commit bdc162d Author: Wilson Snyder <wsnyder@wsnyder.org> Date: Sun May 16 18:38:43 2021 -0400 Fix 16.04 gcc warning commit 706842d Author: Wilson Snyder <wsnyder@wsnyder.org> Date: Sun May 16 15:11:25 2021 -0400 CI: Disable Ubuntu-18.04 clang (verilator#2963) commit 31779b8 Author: Yutetsu TAKATSUKASA <y.takatsukasa@gmail.com> Date: Sun May 16 19:01:03 2021 +0900 Format time string using integer (verilator#2940) Co-authored-by: Wilson Snyder <wsnyder@wsnyder.org> commit 80d62ad Author: Geza Lore <gezalore@gmail.com> Date: Sat May 15 21:10:16 2021 +0100 Make all AstNode* base class constructors protected. (verilator#2962) No functional changes intended. Boring patch in the hope of being helpful to new contributors. Although AstNode* base classes needing to be abstract is described in the internals manual, this might provide a bit of extra safety. commit 38cab56 Author: Geza Lore <gezalore@gmail.com> Date: Sat May 15 18:04:40 2021 +0100 Add --reloop-limit argument (verilator#2960) Add --reloop-limit argument commit 828f78e Author: Geza Lore <gezalore@gmail.com> Date: Sat May 15 16:05:24 2021 +0100 Don't emit empty files with low split limits (verilator#2961) Attempt to split output files when we know a function will actually be emitted, otherwise we might end up with empty files. commit 5e95cc9 Author: Geza Lore <gezalore@gmail.com> Date: Sat May 15 15:56:28 2021 +0100 Internals: Make AstAlwaysPost an AstNodeProcedure. (verilator#2959) This seems to belong there, eliminates some code duplication in V3Clock, and also enables splitting AstAlwaysPost statements into different functions in V3Order, but should otherwise have little effect. commit 88fed4b Author: Wilson Snyder <wsnyder@wsnyder.org> Date: Thu May 13 18:56:07 2021 -0400 Commentary on traces (verilator#2925) commit 3718fe1 Author: Wilson Snyder <wsnyder@wsnyder.org> Date: Thu May 13 18:34:20 2021 -0400 Commentary (trigger rebuild) commit a4ab3e1 Author: Ameya Vikram Singh <ameya.v.singh@gmail.com> Date: Thu May 13 23:56:53 2021 +0530 Update latest C++ Standard Compilation flag (verilator#2951) For SystemC Project sets the CXX_STANDARD flag from SystemC CMake build config. commit 9c85426 Author: Yutetsu TAKATSUKASA <y.takatsukasa@gmail.com> Date: Thu May 13 06:45:56 2021 +0900 Internals: Fix build failure on older gcc such as 4.8.5 on CentOS7. No functional change is intended. (verilator#2954) commit e3b20a3 Author: Yutetsu TAKATSUKASA <y.takatsukasa@gmail.com> Date: Wed May 12 00:45:43 2021 +0900 Internals: Mark VerilatedContextImp::timeFormatSuffix() const (verilator#2947) commit f7c23c4 Author: Yutetsu TAKATSUKASA <y.takatsukasa@gmail.com> Date: Tue May 11 22:38:13 2021 +0900 Internals: Set missing timescale though it is not referred yet. (verilator#2946) commit 00cedf3 Author: Yutetsu TAKATSUKASA <y.takatsukasa@gmail.com> Date: Tue May 11 22:27:31 2021 +0900 Tests: Add a test to check if there is overflow or rounding (verilator#2945) commit 1422c23 Author: Geza Lore <gezalore@gmail.com> Date: Tue May 11 12:44:07 2021 +0100 Split procedures to better respect --output-split-cfuncs (verilator#2942) CFuncs only used to be split at procedure (always/initial/final block), which on occasion can still yield huge output files if they have large procedures. This patch make CFuncs split at statement boundaries within procedures. This has the potential to help a lot, but still does not help if there are huge statements within procedures. commit 1a63782 Author: Geza Lore <gezalore@gmail.com> Date: Mon May 10 22:15:12 2021 +0100 Emit 'else if' without nesting. No functional change intended. (verilator#2944) Instead of: if (a) { x; } else { if (b) { y; } else { if (c) { z; } else { w; } } } Emit: if (a) { x; } else if (b) { y; } else if (c) { z; } else { w; } commit 267c6f6 Author: Geza Lore <gezalore@gmail.com> Date: Mon May 10 18:01:11 2021 +0100 Improve Reloop to accept constant index offsets. (verilator#2939) V3Reloop now can roll up indexed assignments between arrays if there is a constant offset between indices on the left and right hand sides, e.g.: a[0] = b[2]; a[1] = b[3]; ... a[x] = b[x + 2]; commit 45fbd98 Author: Yutetsu TAKATSUKASA <y.takatsukasa@gmail.com> Date: Sun May 9 07:04:22 2021 +0900 Use V3OptionParser in verilator_coverage (verilator#2935) * Internals: Mark unused to avoid compilation failure. No functional change is intended. * Use V3OptionParser in VlcMain.cpp commit f6c0108 Author: Geza Lore <gezalore@gmail.com> Date: Sat May 8 20:04:56 2021 +0100 Optimize large lookup tables to static data (verilator#2926) Implements verilator#2925 commit 37d68d3 Author: Jonathan Drolet <jonathan.drolet@riedel.net> Date: Sat May 8 08:42:00 2021 -0400 Support --trace-fst for SystemC with CMake (verilator#2927) commit 5e56f4d Author: Yutetsu TAKATSUKASA <y.takatsukasa@gmail.com> Date: Sat May 8 21:20:26 2021 +0900 Tests: Enable undefined behavior sanitizor when --sanitize is set. (verilator#2923) commit 2bf248b Author: Jonathan Drolet <jonathan.drolet@gmail.com> Date: Sat May 8 08:18:08 2021 -0400 Add TRACE_THREADS to CMake (verilator#2934) commit 39ce2f7 Author: Yutetsu TAKATSUKASA <y.takatsukasa@gmail.com> Date: Sat May 8 09:45:58 2021 +0900 Internals: Remove VerilatedVcd::m_suffixesp. No functional change is intended. (verilator#2933) Reasons are: - it's error prone to keep updating whennever m_suffixes is resized - invalid pointer may be set when there is not signal to trace as in t_trace_dumporder_bad commit 9797af0 Author: Yutetsu TAKATSUKASA <y.takatsukasa@gmail.com> Date: Sat May 8 07:16:40 2021 +0900 Introduce a macro VL_ATTR_NO_SANITIZE_ALIGN to suppress unaligned access check in ubsan (verilator#2929) * Add VL_ATTR_NO_SANITIZE_ALIGN macro to disable alignment check of ubsan * Mark a function VL_ATTR_NO_SANITIZE_ALIGN because the function is intentionally using unaligned access for the sake of performance. Co-authored-by: Wilson Snyder <wsnyder@wsnyder.org> commit 1e4839e Author: Yutetsu TAKATSUKASA <y.takatsukasa@gmail.com> Date: Sat May 8 01:00:36 2021 +0900 Fix casting to integer not to cause integer overflow. (verilator#2930) commit b2139f6 Author: Todd Strader <todd.strader@gmail.com> Date: Fri May 7 07:17:54 2021 -0400 VPI memory access for packed arrays (verilator#2922) commit 44fd205 Author: Philipp Wagner <mail@philipp-wagner.com> Date: Thu May 6 17:07:15 2021 +0100 Fix make support for gmake 3.x (verilator#2920) (verilator#2921) The "file" make function is only available in gmake 4.x, which isn't available on RHEL/CentOS 7. Use alternative syntax to support older gmake versions. Fixes verilator#2920
@gezalore do you have any more actions you expect relative to this issue? Maybe we should close this, and if there's anything specifically left to be done in the short/medium file a bug on that? |
I think there is not much else to do on this without significant other considerations so best to close this. |
I also noticed:
Is this behavior also related to the fact that Verilator does not support incremental compilation? |
Likely you need ccache installed, it will run GCC, but it will finish nearly instantly.
I suspect you didn't have any make dependencies on the .v files, so any change in them won't rebuild which is bad as your model will be stale. One alternative to listing them is to include the .d files Verilator can make for you with -MMD. If you need help on that please file a new ticket as is unrelated to this one. |
I have been using icecream + ccache to speed up builds of the C++ output by Verilator. This works to some extent when running with -Oi to disable module inlining in order to give ccache a chance. The caching however becomes useless after moderate changes or if any module has the properties (name, size) of any named port/state/signal changed, which causes a full re-build. Reading the output of Verilator, I see at least 2 reasons why the compiler cache has a hard time:
I wonder if it would be reasonable to attempt to remedy this (under a new Verilator switch), by:
this
as needed), in companion *__Internals.{h,cpp} files.Theory is then that the only C++ that would need to be re-compiled are the modules that changed, their dependencies (which are limited to everything below in the hierarchy unless there are interface changes or hierarchical references), and the top level _eval and friends, but not all the other modules. I am sure I am missing a lot of detail, can you think of anything that would make this whole idea a non-starter? I would also be interested to know if you think this would not be as useful as I think it would for any reason.
The text was updated successfully, but these errors were encountered: