Fix nvfortran two-pass IPO causing full rebuild on every build - #1345
Conversation
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
|
Claude Code Review Incremental review from: e6e992d New findings since last Claude review:
|
📝 WalkthroughWalkthroughThe CMakeLists.txt change adds support for NVHPC's 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1345 +/- ##
=======================================
Coverage 64.67% 64.67%
=======================================
Files 70 70
Lines 18251 18251
Branches 1504 1504
=======================================
Hits 11804 11804
Misses 5492 5492
Partials 955 955 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Summary
When building MFC with nvfortran and GPU flags (
--gpu accor--gpu mpfor non-OpenMP targets), every rebuild recompiled all source files even when nothing changed. This turned what should be a no-op rebuild into a multi-minute wait (e.g., ~10 minutes forsimulation).Root Cause
The two-pass IPO mechanism (lines 497–506) creates an OBJECT library (
<target>_lib) that compiles all sources with-Mextract=lib:<target>_libto build an inline library. The main target then uses-Minline=lib:<target>_libto inline from that library.The problem: nvfortran's
-Mextractflag does not produce.ofiles — it only writes inline library data to a directory. CMake's OBJECT library model expects.ooutputs from each compilation. Since those.ofiles never exist, CMake considers every source file out of date and recompiles the entire_libtarget on every build.This only affects nvfortran GPU builds because:
NVHPC_USE_TWO_PASS_IPOis onlyTRUEfor nvfortran 23.11–24.11--gpu mp+simulation, the IPO is disabled by theNOT(MFC_OpenMP AND ARGS_OpenMP)guard, but all other GPU target combinations are affectedFix
A small wrapper shell script is set as
RULE_LAUNCH_COMPILEon the_libOBJECT library target. The wrapper:-Mextract) normally.ooutput file afterwardThis gives CMake the
.ofile it needs for dependency tracking. On subsequent builds, CMake sees the.oexists and is newer than the source, so it correctly skips recompilation. The inline library data in the<target>_lib/directory is still produced as before.Before
After
Test plan
--gpu acc -t pre_process: second build is no-op--gpu acc -t simulation: second build is no-op--gpu mp -t pre_process: second build is no-op