C内核按库功能拆解,编译结果缓存区构建,编译过程与已有缓存结果对照功能实现
This commit is contained in:
1 parent
aa4951b14e
commit
151e6e4b97
30 files changed
+4856
-604
No files matched your search
@@ -220,9 +220,15 @@ def prepare(args: argparse.Namespace) -> dict:
|
||||
# Reject numerical/runtime drift; a sparse timing-only cached main is allowed
|
||||
# because control and our current writer share the numeric model contract.
|
||||
differences = []
|
||||
for name, expected in manifest["sourceHashes"].items():
|
||||
recorded_sources = dict(manifest["sourceHashes"])
|
||||
if manifest.get("cacheVersion", 1) >= 2:
|
||||
headers = manifest.get("nativeHeaderHashes")
|
||||
if not isinstance(headers, dict) or not headers:
|
||||
raise RuntimeError("Cached build lacks native header hashes; rebuild before profiling")
|
||||
recorded_sources.update(headers)
|
||||
for name, expected in recorded_sources.items():
|
||||
relative = name.split("native/", 1)[-1]
|
||||
current = ROOT / "native" / relative
|
||||
current = cache / relative if relative == "model.c" else ROOT / "native" / relative
|
||||
if digest(current) != expected:
|
||||
differences.append(relative)
|
||||
if any(name != "runtime/main.c" for name in differences):
|
||||
@@ -243,7 +249,16 @@ def prepare(args: argparse.Namespace) -> dict:
|
||||
for name in ("model.c", "model.h", "manifest.json"):
|
||||
shutil.copy2(cache / name, output / name)
|
||||
instrument(native)
|
||||
command = [compiler, *manifest["compilerFlags"], "-I", str(output), "-I", str(native / "include"), "-I", str(sundials / "include"), str(output / "model.c"), *map(str, sorted(native.rglob("*.c"))), "-Wl,--start-group", *map(str, libraries), "-Wl,--end-group", "-lm", "-o", str(output / "profiled-model")]
|
||||
# Match the cached translation units. Compiling the compatibility entry
|
||||
# together with its new modules would define every component twice.
|
||||
sources = [native / name.split("native/", 1)[-1]
|
||||
for name in manifest["sourceHashes"]
|
||||
if name.endswith(".c") and name != "model.c"]
|
||||
if not sources or (native / "components/kernels.c" in sources and
|
||||
any(path.parent == native / "components/modules" for path in sources)):
|
||||
raise RuntimeError("Cached translation units are missing or mix amalgamation and modules")
|
||||
sources.append(native / "runtime/compute_profile.c")
|
||||
command = [compiler, *manifest["compilerFlags"], "-I", str(output), "-I", str(native / "include"), "-I", str(sundials / "include"), str(output / "model.c"), *map(str, sources), "-Wl,--start-group", *map(str, libraries), "-Wl,--end-group", "-lm", "-o", str(output / "profiled-model")]
|
||||
prepared = {"controlExecutable": str(cache / "model"), "profiledExecutable": str(output / "profiled-model"), "buildCommand": command, "runtimeArguments": numerical_arguments, "verifyJacobian": "--verify-jacobian" in numerical_arguments, "algorithm": "production-automatic", "cacheDir": str(cache), "cachedMainDifference": differences, "stateCount": len(manifest["stateKeys"]), "modelSha256": digest(output / "model.c"), "compiler": compiler_version, "warmups": args.warmups, "repeats": args.repeats, "scope": "Inclusive times overlap. Exclusive scope times partition integration including instrumentation overhead. No component or libc sub-cost inference.", "sourceHashes": {str(p.relative_to(output)): digest(p) for p in sorted(native.rglob("*")) if p.is_file()}}
|
||||
write_json(output / "prepared.json", prepared)
|
||||
return prepared
|
||||
|
||||
Reference in new issue
Block a user