Repository navigation
test(rccl): guard Makefile dep tracking stays on -MM #12933
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
131478a
test(rccl): guard Makefile dep tracking stays on -MM
PedramAlizadeh 4a5b240
test(rccl): address review on Makefile -MM guard
PedramAlizadeh f64929e
Merge branch 'develop' into users/PedramAlizadeh/cmake_test
PedramAlizadeh 630d58e
test(rccl): join Makefile continuations with a space
PedramAlizadeh 5f9708f
test(rccl): cover the depgen gate and ignore comment -M
PedramAlizadeh f74b407
Merge branch 'develop' into users/PedramAlizadeh/cmake_test
PedramAlizadeh c97e615
Merge branch 'develop' into users/PedramAlizadeh/cmake_test
PedramAlizadeh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,161 @@ | ||
| #!/usr/bin/env python3 | ||
| """Guard that Makefile header-dep tracking uses -MM (NCCL PR #1806). | ||
|
|
||
| NCCL 2.30.7 switched include tracking from -M to -MM so system headers are | ||
| omitted from generated .d files. src/device/Makefile (and the diagnostics | ||
| copy) then realpath-filters those paths down to the tree; listing libc / HIP | ||
| / compiler headers made that loop excessively slow on some filesystems. | ||
|
|
||
| This is a source scan, not a compile. Nothing in RCCL CI runs ctest, so the | ||
| copy that gates is test/host/run_host_tests.sh `guards` (folded into `run`). | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import os | ||
| import re | ||
| import unittest | ||
|
|
||
| HERE = os.path.dirname(os.path.abspath(__file__)) | ||
|
|
||
| # Longest-match first so -MMD is not read as -MM or -M, and -MD / -MM are | ||
| # not read as -M. -march and friends fail the trailing boundary. | ||
| DEP_FLAG_RE = re.compile(r"(?<!\S)(-MMD|-MM|-MD|-MF|-MG|-MP|-MT|-MQ|-M)(?=\s|$)") | ||
|
|
||
| # -MM / -MMD omit system headers. -M / -MD include them (the #1806 bug). | ||
| USER_ONLY = frozenset({"-MM", "-MMD"}) | ||
| SYSTEM_INCLUSIVE = frozenset({"-M", "-MD"}) | ||
|
|
||
| # Files that carry the NCCL #1806 recipes (plus the RCCL diagnostics copy). | ||
| REQUIRED = ( | ||
| ("Makefile", ("d_tmp",), 2), | ||
| (os.path.join("device", "Makefile"), ("DEPENDS.cu", "DEPENDS.cc"), 2), | ||
| (os.path.join("diagnostics", "device", "Makefile"), ("DEPENDS.cu",), 1), | ||
| ) | ||
|
|
||
|
|
||
| def _join_continued_lines(text): | ||
| """Collapse makefile / recipe backslash continuations into logical lines.""" | ||
| logical = [] | ||
| buf = [] | ||
| for raw in text.splitlines(): | ||
| stripped = raw.rstrip() | ||
| if stripped.endswith("\\"): | ||
| buf.append(stripped[:-1]) | ||
| continue | ||
| buf.append(stripped) | ||
| logical.append("".join(buf)) | ||
| buf = [] | ||
| if buf: | ||
| logical.append("".join(buf)) | ||
| return logical | ||
|
|
||
|
|
||
| def _dep_flags(line): | ||
| return tuple(DEP_FLAG_RE.findall(line)) | ||
|
|
||
|
|
||
| def _is_depgen_line(line): | ||
| """True for a compiler dep-tracking recipe, not a later sed of .d.tmp.""" | ||
| if not line or line.lstrip().startswith("#"): | ||
| return False | ||
| flags = _dep_flags(line) | ||
| if not flags: | ||
| return False | ||
| return ( | ||
| ".d.tmp" in line | ||
| or re.search(r"DEPENDS\.(cu|cc)\s*=", line) is not None | ||
| ) | ||
|
|
||
|
|
||
| def depgen_sites(text): | ||
| """Return (lineno, line, flags) for each header-dep recipe in `text`.""" | ||
| sites = [] | ||
| for i, line in enumerate(_join_continued_lines(text), start=1): | ||
| if _is_depgen_line(line): | ||
| sites.append((i, line, _dep_flags(line))) | ||
| return sites | ||
|
|
||
|
|
||
| def site_errors(flags): | ||
| """Human-readable problems for one recipe's -M* flags, or [].""" | ||
| have = set(flags) | ||
| errors = [] | ||
| bad = have & SYSTEM_INCLUSIVE | ||
| if bad: | ||
| errors.append("uses system-header flag %s (want -MM or -MMD)" % | ||
| ", ".join(sorted(bad))) | ||
| if not (have & USER_ONLY): | ||
| errors.append("missing -MM / -MMD") | ||
| return errors | ||
|
|
||
|
|
||
| class TestMakefileDepFlags(unittest.TestCase): | ||
| def test_parser_accepts_dash_mm(self): | ||
| sites = depgen_sites( | ||
| "\t@$(CXX) -I. $(CXXFLAGS) -MM $< > $(@:%.o=%.d.tmp)\n" | ||
| ) | ||
| self.assertEqual(len(sites), 1) | ||
| self.assertEqual(sites[0][2], ("-MM",)) | ||
| self.assertEqual(site_errors(sites[0][2]), []) | ||
|
|
||
| def test_parser_rejects_dash_m(self): | ||
| sites = depgen_sites( | ||
| "\t@$(CXX) -I. $(CXXFLAGS) -M $< > $(@:%.o=%.d.tmp)\n" | ||
| ) | ||
| self.assertEqual(len(sites), 1) | ||
| self.assertEqual(sites[0][2], ("-M",)) | ||
| self.assertTrue(site_errors(sites[0][2])) | ||
|
|
||
| def test_parser_rejects_dash_md(self): | ||
| sites = depgen_sites("DEPENDS.cu = $(NVCC) $(NVCUFLAGS) -MD -dc $1\n") | ||
| self.assertEqual(len(sites), 1) | ||
| self.assertTrue(site_errors(sites[0][2])) | ||
|
|
||
| def test_parser_ignores_sed_of_d_tmp(self): | ||
| text = ( | ||
| "\t@sed \"0,/^.*:/s//x:/\" $(@:%.o=%.d.tmp) > $(@:%.o=%.d)\n" | ||
| "\t$(CXX) -c $< -o $@\n" | ||
| ) | ||
| self.assertEqual(depgen_sites(text), []) | ||
|
|
||
| def test_parser_does_not_treat_march_as_dep_flag(self): | ||
| sites = depgen_sites( | ||
| "\t$(CXX) -march=native -MM $< > foo.d.tmp\n" | ||
| ) | ||
| self.assertEqual(len(sites), 1) | ||
| self.assertEqual(sites[0][2], ("-MM",)) | ||
|
|
||
| def test_src_makefiles_use_user_only_deps(self): | ||
| failures = [] | ||
| for rel, kinds, min_sites in REQUIRED: | ||
| path = os.path.join(HERE, rel) | ||
| self.assertTrue(os.path.isfile(path), "missing %s" % path) | ||
| with open(path) as f: | ||
| text = f.read() | ||
| sites = depgen_sites(text) | ||
| if len(sites) < min_sites: | ||
| failures.append( | ||
| "%s: expected at least %d depgen site(s), found %d" | ||
| % (rel, min_sites, len(sites)) | ||
| ) | ||
| for kind in kinds: | ||
| if kind == "d_tmp": | ||
| if not any(".d.tmp" in line for _, line, _ in sites): | ||
| failures.append("%s: no .d.tmp -MM recipe" % rel) | ||
| continue | ||
| if not any(kind in line for _, line, _ in sites): | ||
| failures.append("%s: no %s recipe" % (rel, kind)) | ||
| for lineno, line, flags in sites: | ||
| errs = site_errors(flags) | ||
| if errs: | ||
| failures.append( | ||
| "%s:%d: %s\n %s" | ||
| % (rel, lineno, "; ".join(errs), line.strip()) | ||
| ) | ||
| self.assertFalse(failures, "NCCL PR #1806 -MM guard failed:\n" + | ||
| "\n".join(failures)) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main(verbosity=2) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.