diff --git a/.github/actions/detect-changes/action.yml b/.github/actions/detect-changes/action.yml index 1903bbe43..0133567a0 100644 --- a/.github/actions/detect-changes/action.yml +++ b/.github/actions/detect-changes/action.yml @@ -58,11 +58,21 @@ outputs: flm-dev-kit/ paths never select product suites: a change only there gives run "false" (see devkit-overlay for the packages it may build). value: ${{ steps.changes.outputs.devkit }} + devkit-catalog: + description: > + "true" when a file the dev-kit catalog check reads changed (what src/ + ships: src/model_list.json, src/xclbins/, src/lib/; and the dev kit's + engines.json, kernel_assignment.json/.md and build_units.json), or the + changed files are unknown: devkit-static runs, as it does for devkit, + and nothing else. + value: ${{ steps.changes.outputs.devkit_catalog }} devkit-areas: description: > Comma-separated dev-kit areas the change touches: xclbin, dll, converter, pybind, launchlib, including the areas that build from a - changed file of another area. Empty when devkit is "false". + changed file of another area, and xclbin for a shipped kernel + (src/xclbins//.xclbin, rebuilt to compare). Empty when + devkit is "false". value: ${{ steps.changes.outputs.devkit_areas }} devkit-families: description: > @@ -76,7 +86,8 @@ outputs: devkit-overlay: description: > "true" when the dev-kit overlay tests run: the change touches a dev-kit - engine's families or selects the xclbin area. A pull request then + engine's families or selects the xclbin area (other than through + shipped kernels alone, which are only compared). A pull request then builds the portable packages they start from even when run is "false" (suites is then "none", so no product test runs). value: ${{ steps.changes.outputs.devkit_overlay }} diff --git a/.github/script/ci/changes.py b/.github/script/ci/changes.py index 2489cafa2..8e47e02be 100644 --- a/.github/script/ci/changes.py +++ b/.github/script/ci/changes.py @@ -63,12 +63,22 @@ aie-build:, built in the run when it is not published, so a pull request that also changes a kernel builds it with its own toolchain.lock and Dockerfile + devkit_catalog + true when a file the dev-kit catalog check (devkit_check.py's + catalog rules: what src/ ships against the dev kit's JSON) + reads changed: src/model_list.json, src/xclbins/, src/lib/, + flm-dev-kit/FLM_DLL/engines.json or FLM_Xclbin/ + kernel_assignment.{json,md} or build_units.json, or the changed + files are unknown. Runs devkit-static (as devkit does) and + nothing else: no product suite, dev-kit build or overlay devkit_areas comma-separated dev-kit areas the change touches, from xclbin, dll, converter, pybind and launchlib, plus the areas that build from a changed file of another area, of src/lib/xrt or of - hrx-integration/; every - area when the changed files are unknown, a changed dev-kit file + hrx-integration/, and xclbin for a shipped kernel + (src/xclbins//.xclbin), which devkit-xclbins + rebuilds from its sources to compare (devkit_xclbin_plan.py); + every area when the changed files are unknown, a changed dev-kit file is in none of them, or the dev-kit CI changed devkit_families comma-separated catalog families whose dev-kit engines the change @@ -86,7 +96,9 @@ devkit_overlay true when the dev-kit overlay tests run (build-and-test.yml test-*-devkit): the dll area with devkit_families, or the xclbin - area (the kernel build names the models it rebuilt). On a pull + area (the kernel build names the models it rebuilt), unless only + shipped kernels selected it: the product suites test those, + and the rebuild is only compared with them. On a pull request the portable packages the overlay starts from (Linux XRT and HRX, Windows XRT and HRX) are then built even when run_tests is false, which then gives suites "none", so no @@ -207,6 +219,19 @@ (re.compile(r"^\.github/windows-deps/"), {"dll"}), ) +# The files devkit_check.py's catalog rules read: what the product ships +# (src/model_list.json, src/xclbins, src/lib) and the dev-kit JSON describing +# where it comes from. A change to one runs devkit-static (devkit_catalog) +# without selecting a dev-kit area, so no dev-kit build or overlay starts. +DEVKIT_CATALOG = re.compile( + r"^(src/model_list\.json$|src/xclbins/|src/lib/|flm-dev-kit/FLM_DLL/engines\.json$" + r"|flm-dev-kit/FLM_Xclbin/(kernel_assignment\.(json|md)|build_units\.json)$)") +# A shipped kernel: devkit-xclbins rebuilds the artifact kernel_assignment.json +# maps to its slot and compares the two (report only). It selects the xclbin +# area, but no overlay: the product suites test the shipped file, and the +# rebuild comes from sources this change did not touch. +SHIPPED_KERNEL = re.compile(r"^src/xclbins/.+/[^/]+\.xclbin$") + # The kernel build image: its Dockerfile, kernel check script and pinned PDIs # (docker/aie-build*), its versions (toolchain.lock, which would otherwise be # in the xclbin area) and the workflow that builds it. Each selects the @@ -597,6 +622,10 @@ class Decision: bench_source: Optional[str] = None # Changed bench CI files (BENCH_CI), which Build and Test leaves alone. bench_ci: list = field(default_factory=list) + # A file the dev-kit catalog check reads changed (DEVKIT_CATALOG). + devkit_catalog: bool = False + # Only shipped kernels (SHIPPED_KERNEL) selected the xclbin area. + xclbin_compare_only: bool = False reasons: list = field(default_factory=list) def all_suites(self, path: str, why: str = "") -> None: @@ -638,7 +667,8 @@ def devkit_overlay(self) -> bool: and then every overlay job skips (summary does not hold the missing approval against it). Narrowing it would mean running the kernel plan (devkit_xclbin_plan.py) here.""" - return bool(self.devkit_families and "dll" in self.devkit_areas) or "xclbin" in self.devkit_areas + return (bool(self.devkit_families and "dll" in self.devkit_areas) + or ("xclbin" in self.devkit_areas and not self.xclbin_compare_only)) def bench(self) -> bool: """Whether the dev-kit benches (devkit-bench.yml) run: engine or kernel @@ -651,10 +681,14 @@ def summary(self) -> str: devkit = f"; dev kit: {self.devkit_value().replace(',', ', ')}" if self.devkit_areas else "" if self.devkit_families: devkit += f" (engine families: {len(self.devkit_families)})" + if self.xclbin_compare_only: + devkit += " (shipped kernels rebuilt to compare)" if self.devkit_overlay(): devkit += "; dev-kit overlay tests run" if self.bench(): devkit += "; dev-kit benches run" + if self.devkit_catalog and not self.devkit_areas: + devkit += "; dev-kit catalog check runs" if not self.run_tests: if self.devkit_areas: what = ("product NPU tests skipped, portable packages built for the overlay" @@ -664,7 +698,7 @@ def summary(self) -> str: return "kernel build image only (devkit-aie-image.yml): NPU tests and dev-kit jobs skipped" if self.bench_ci: return "bench CI only (devkit-bench.yml): NPU tests and dev-kit jobs skipped" - return "documentation only: NPU tests skipped" + return "documentation only: NPU tests skipped" + devkit return self._product_summary() + devkit def _product_summary(self) -> str: @@ -700,6 +734,7 @@ def outputs(self) -> dict[str, str]: "new_models": ",".join(self.new_models), "hipep_models": ",".join(sorted(self.gpu_models)), "devkit": str(bool(self.devkit_areas)).lower(), + "devkit_catalog": str(self.devkit_catalog).lower(), "devkit_areas": self.devkit_value(), "devkit_families": ",".join(sorted(self.devkit_families)), "devkit_overlay": str(self.devkit_overlay()).lower(), @@ -1012,6 +1047,7 @@ def decide(files: Optional[list[str]], git: Optional[Git] = None, devkit_engines = load_devkit_engines() if files is None: d.asr_full = True + d.devkit_catalog = True d.devkit_areas = set(ALL_DEVKIT_AREAS) d.devkit_families = every_engine_family(devkit_engines) d.bench_source = "changed files unknown" @@ -1025,6 +1061,12 @@ def decide(files: Optional[list[str]], git: Optional[Git] = None, d.reasons.append("no changed files: running the tests anyway; no dev-kit benches") return d + catalog = [f for f in files if DEVKIT_CATALOG.match(f)] + if catalog: + d.devkit_catalog = True + d.reasons.append(f"{catalog[0]}{f' and {len(catalog) - 1} more' if len(catalog) > 1 else ''}: " + "read by the dev-kit catalog check (devkit-static)") + bench_ci = [f for f in files if BENCH_CI.match(f)] if bench_ci: d.bench_ci = bench_ci @@ -1102,6 +1144,12 @@ def decide(files: Optional[list[str]], git: Optional[Git] = None, if new: d.reasons.append(f"{path}: linked by the dev kit -> {', '.join(sorted(new))}") break + shipped = [f for f in code if SHIPPED_KERNEL.match(f)] + if shipped and "xclbin" not in d.devkit_areas: + d.devkit_areas.add("xclbin") + d.xclbin_compare_only = True + d.reasons.append(f"{shipped[0]}{f' and {len(shipped) - 1} more' if len(shipped) > 1 else ''}: " + "shipped kernel(s) -> xclbin, rebuilt from the dev kit to compare (no overlay)") head_catalog = load_catalog(head_catalog_text) gpu_fams = gpu_families(head_catalog) diff --git a/.github/script/ci/devkit_check.py b/.github/script/ci/devkit_check.py index 765d11bd0..6c64155a3 100644 --- a/.github/script/ci/devkit_check.py +++ b/.github/script/ci/devkit_check.py @@ -41,7 +41,29 @@ detail/ sources ("../", also as "-I../") or include/models// headers its Makefile or CMakeLists.txt (outside # comments) or the #include lines of its sources and - own headers name. The JSON files must not repeat a key + own headers name; a model with no assignment of its own + may be listed when it is a catalog alias (see catalog). + The JSON files must not repeat a key + catalog what the product ships (src/) is what the dev kit describes. + The NPU models of src/model_list.json are the entries flm + keeps on an aie2p machine (supported_platforms naming aie2p + or absent, backend flm); a model's xclbin folder is its + xclbin_folder, else its name. (1) every NPU model has a + kernel_assignment.json entry, unless it is an alias: no entry + but an xclbin_folder that some entry's folder is; (2) every + assignment model is an NPU model, unless engines.json lists + it under served_elsewhere; (3) an entry's folder is its + model's xclbin folder; (4) every assigned slot ships as + src/xclbins// (served_elsewhere skipped); (5) + every src/xclbins//*.xclbin is a slot some model with + that folder assigns; (6) every NPU model is listed by an + engine and every engine model is an NPU model; (7) every + file in src/lib/{xrt,hrx} is lib.so, .dll or + .lib of a library an engine or shared directory builds + (its Makefile TARGET and CMakeLists.txt add_library, which + must agree), and each such library ships all three in both. + CATALOG_ALLOW excuses named files and alias tags, each with + its reason; an entry that excuses nothing is an error rtp lock FLM_Xclbin/rtp_addresses.lock.txt (devkit_rtp_lock.py) parses and names only artifacts a build unit produces and some kernel_assignment.json model uses. With --base, when the pull @@ -380,7 +402,10 @@ def scan_engine_uses(dll_root: Path | str, engines: set, shared: set) -> dict[st return out -def check_engines(repo: Path, data: dict, models: dict, errors: list) -> None: +def check_engines(repo: Path, data: dict, models: dict, errors: list, + aliases: frozenset | set = frozenset()) -> None: + """aliases: catalog tags with no kernel_assignment.json entry that run + another model's kernels (catalog_aliases); an engine may list them.""" detail = repo / DLL / "detail" shared = data.get("shared") engines = data.get("engines") @@ -425,7 +450,7 @@ def check_engines(repo: Path, data: dict, models: dict, errors: list) -> None: if m in owner and owner[m] != name: errors.append(f"{where}: model {m} is also served by {owner[m]}") owner.setdefault(m, name) - if models and m not in models: + if models and m not in models and m not in aliases: errors.append(f"{where}: model {m} is not in {ASSIGNMENT}") for u in entry.get("uses") or []: if u not in engines: @@ -448,6 +473,241 @@ def check_engines(repo: Path, data: dict, models: dict, errors: list) -> None: f"reference {sorted(scanned[name])}") +# ── catalog: what the product ships (src/) against the dev kit ────────────── +# The product builds nothing from flm-dev-kit/: it ships prebuilt engine +# libraries (src/lib//) and kernels (src/xclbins//). +# These rules keep the dev kit the source of both, so a model cannot ship +# under src/ without its engine, its engines.json entry and its +# kernel_assignment.json entry. +MODEL_LIST = "src/model_list.json" +SHIPPED_XCLBINS = "src/xclbins" +# src/CMakeLists.txt links the engines from src/lib/${FLM_RUNTIME_NAME}, xrt or +# hrx: lib.so on Linux, the .lib import library on Windows, whose +# .dll .github/workflows/win-build.yml copies from the same directory +# into the package. Each runtime ships all three, built by the dev-kit dir. +SHIPPED_RUNTIMES = ("xrt", "hrx") +NPU_PLATFORM = "aie2p" # the generation the FLM_DLL engines and kernels are built for +FLM_BACKEND = "flm" # flm::backend::kFlmBackendId +BACKEND_SUFFIXES = {"-core": "core", "-oga-hipep": "oga-hipep"} # catalog::backend_for_model_type +# Shipped files and catalog tags the catalog rules accept without a dev-kit +# source (key: a src/ path, or a model tag) -> why. An entry that no longer +# excuses anything is an error, so the list cannot go stale. +CATALOG_ALLOW = { + f"{SHIPPED_XCLBINS}/MiniCPM-OCR-1.0-NPU2/conv.xclbin": + "loaded by no engine: minicpm_ocr_npu registers conv8.xclbin (and only when built with " + "PREFILL_CONV=npu); conv.xclbin is the older conv1d kernel it does not work with " + "(FLM_DLL/detail/minicpm_ocr_npu/README.md). Kept: binaries under src/ are not removed here", + "src/lib/xrt/libaiebu.a": + "the prebuilt AIE assembler the dev-kit engines and kernel hosts link, no engine library", + "src/lib/xrt/aiebu_static.lib": + "the prebuilt AIE assembler (Windows) the dev-kit engines link, no engine library", +} + +MK_TARGET = re.compile(r"^\s*TARGET\s*[:?]?=\s*\$\((?:LIB_DIR|BUILD_DIR)\)/(?:lib)?([A-Za-z0-9_]+)\.(?:so|dll)\s*$") +CMAKE_LIBRARY = re.compile(r"\badd_library\s*\(\s*([A-Za-z0-9_]+)\s+SHARED\b") + + +def entry_backend(family: str, entry: dict) -> str: + """The backend that runs a catalog entry: its "backend" key, else the + family's suffix (model_list::backend_for_family).""" + backend = entry.get("backend") + if isinstance(backend, str) and backend: + return backend + return next((b for sfx, b in BACKEND_SUFFIXES.items() + if family.endswith(sfx) and len(family) > len(sfx)), FLM_BACKEND) + + +def npu_catalog(data: dict) -> dict[str, dict]: + """tag -> entry for the catalog models the FLM_DLL engines and kernels run: + those flm on an NPU2 (aie2p) machine keeps (model_list:: + apply_support_filter): backend flm (any backend for an embedding model) + and supported_platforms naming aie2p, or absent (every generation).""" + out = {} + for family, sizes in (data.get("models") or {}).items(): + if not isinstance(sizes, dict): + continue + for size, entry in sizes.items(): + if not isinstance(entry, dict): + continue + platforms = entry.get("supported_platforms") + if platforms is not None and (not isinstance(platforms, list) or NPU_PLATFORM not in platforms): + continue + if entry.get("model_kind") != "embedding" and entry_backend(family, entry) != FLM_BACKEND: + continue + out[f"{family}:{size}"] = entry + return out + + +def xclbin_folder(entry: dict) -> str: + """The src/xclbins folder the engine loads: xclbin_folder, else name + (AutoModel::_shared_initialize_model_state, model_list::resolve_source).""" + folder = entry.get("xclbin_folder") + return folder if isinstance(folder, str) and folder else str(entry.get("name") or "") + + +def catalog_aliases(catalog: dict, assignment: dict) -> set[str]: + """NPU tags without a kernel_assignment.json entry that name an + xclbin_folder: they run the kernels of whichever model uses it.""" + return {t for t, e in npu_catalog(catalog).items() + if t not in assignment and isinstance(e.get("xclbin_folder"), str) and e["xclbin_folder"]} + + +def unit_library(dll: Path, unit: str, errors: list) -> Optional[str]: + """The library a detail/ builds: its Makefile's TARGET + (lib.so, .dll) and its CMakeLists.txt add_library( + SHARED), which must agree; None when it builds none (vision_common).""" + names = set() + for f, rx in (("Makefile", MK_TARGET), ("CMakeLists.txt", CMAKE_LIBRARY)): + try: + lines = (dll / "detail" / unit / f).read_text(encoding="utf-8", errors="replace").splitlines() + except OSError: + continue + names |= {m.group(1) for l in lines for m in [rx.search(l.split("#", 1)[0])] if m} + if len(names) > 1: + errors.append(f"{DLL}/detail/{unit}: its Makefile TARGET and CMakeLists.txt add_library name " + f"different libraries ({', '.join(sorted(names))}): make them build one") + return None + return next(iter(names), None) + + +def shipped_names(lib: str) -> tuple[str, ...]: + """The files of library lib each runtime directory ships.""" + return (f"lib{lib}.so", f"{lib}.dll", f"{lib}.lib") + + +def check_catalog(repo: Path, catalog: dict, assignment: dict, engines: dict, + errors: list, allow: Optional[dict] = None) -> str: + """src/model_list.json, src/xclbins and src/lib against kernel_assignment + .json and engines.json; returns a note. allow: CATALOG_ALLOW.""" + allow = CATALOG_ALLOW if allow is None else allow + used: set[str] = set() + + def excused(key: str) -> bool: + if key in allow: + used.add(key) + return True + return False + + npu = npu_catalog(catalog) + elsewhere = engines.get("served_elsewhere") or {} + elsewhere = elsewhere if isinstance(elsewhere, dict) else {} + eng = engines.get("engines") or {} + eng = eng if isinstance(eng, dict) else {} + folders: dict[str, set] = {} # folder -> the slots its kernel_assignment.json models assign + for m, e in assignment.items(): + if isinstance(e, dict) and isinstance(e.get("folder"), str): + folders.setdefault(e["folder"], set()).update((e.get("kernels") or {}) if isinstance( + e.get("kernels"), dict) else ()) + aliases = catalog_aliases(catalog, assignment) + md = f"and its \"#### `` → ``\" section to {ASSIGNMENT_MD}" + + # 1. Every NPU tag has kernels: its own entry, or another model's folder. + for tag, entry in sorted(npu.items()): + folder = xclbin_folder(entry) + if tag in assignment: + # 3. The folder the assignment fills is the one the engine loads. + ka = assignment[tag].get("folder") if isinstance(assignment[tag], dict) else None + if ka != folder: + errors.append(f"{ASSIGNMENT}: {tag} has folder {ka}, but {MODEL_LIST} gives it xclbin folder " + f"{folder} (its xclbin_folder, else its name), which the engine loads: " + f"make the two agree (and the {ASSIGNMENT_MD} heading)") + elif tag in aliases: + if folder not in folders: + errors.append(f"{MODEL_LIST}: {tag} runs the kernels of xclbin_folder {folder}, but no " + f"{ASSIGNMENT} model has that folder: point it at a model's folder, or give " + f"{tag} an entry of its own in {ASSIGNMENT} {md}") + else: + errors.append(f"{MODEL_LIST}: NPU ({NPU_PLATFORM}) model {tag} has no {ASSIGNMENT} entry: add " + f"\"{tag}\": {{\"folder\": \"{folder}\", \"kernels\": {{\".xclbin\": " + f"\"\", ...}}}} and its \"#### `{tag}` → `{folder}`\" " + f"section to {ASSIGNMENT_MD} (a tag that runs another " + "model's kernels names that model's folder in xclbin_folder instead)") + + # 2. Every assignment is an NPU model, or runs outside FLM_DLL. + for m in sorted(set(assignment) - set(npu) - set(elsewhere)): + errors.append(f"{ASSIGNMENT}: {m} is no NPU ({NPU_PLATFORM}) model of {MODEL_LIST}: drop its entry " + f"and section in {ASSIGNMENT_MD}, fix the tag, or list it under served_elsewhere in " + f"{ENGINES} if no FLM_DLL engine runs it") + + # 4. Every assigned slot ships. + for m, e in sorted(assignment.items()): + if m in elsewhere or not isinstance(e, dict) or not isinstance(e.get("folder"), str): + continue + for slot in sorted(e.get("kernels") or {}): + if not (repo / SHIPPED_XCLBINS / e["folder"] / slot).is_file(): + errors.append(f"{ASSIGNMENT}: {m} assigns {slot}, but {SHIPPED_XCLBINS}/{e['folder']}/{slot} " + f"is not shipped: add the kernel there, or drop the slot from {ASSIGNMENT} " + f"and {ASSIGNMENT_MD}") + + # 5. Every shipped kernel is assigned by a model using its folder. + root = repo / SHIPPED_XCLBINS + shipped = sorted(p.relative_to(root).as_posix() for p in root.rglob("*.xclbin") if p.is_file()) \ + if root.is_dir() else [] + for rel in shipped: + folder, slot = rel.rsplit("/", 1) if "/" in rel else ("", rel) + path = f"{SHIPPED_XCLBINS}/{rel}" + if slot in folders.get(folder, ()) or excused(path): + continue + whose = (f"no {ASSIGNMENT} model with folder {folder} assigns {slot}" if folder in folders + else f"no {ASSIGNMENT} model has folder {folder}") + errors.append(f"{path} is shipped, but {whose}: add the slot and the build-unit artifact that " + f"builds it to {ASSIGNMENT} {md}; if no engine loads it, say why in CATALOG_ALLOW " + "(.github/script/ci/devkit_check.py)") + + # 6. Every NPU tag is served by exactly one engine (check_engines reports + # two), and engines serve catalog models. + served: dict[str, list] = {} + for name, e in sorted(eng.items()): + for m in (e.get("models") or []) if isinstance(e, dict) else []: + served.setdefault(m, []).append(name) + if isinstance(m, str) and m not in npu and m not in elsewhere: + errors.append(f"{ENGINES}: {name} lists {m}, which is no NPU ({NPU_PLATFORM}) model of " + f"{MODEL_LIST}: drop it or fix the tag") + for tag in sorted(set(npu) - set(served)): + if tag in aliases and excused(tag): + continue + errors.append(f"{ENGINES}: NPU model {tag} of {MODEL_LIST} is served by no engine: add it to the " + f"models of the engine that runs it; a new model family needs its engine under " + f"{DLL}/detail// (Makefile with -Wl,-Bsymbolic-functions, CMakeLists.txt, " + f"sources, include/models// header) and an entry in {ENGINES}") + + # 7. Every shipped engine library is a dev-kit dir's, and every dir's + # library ships for each runtime. + dirs = [d for d in (engines.get("shared") or []) if isinstance(d, str)] + sorted(eng) + libs: dict[str, str] = {} + for d in dirs: + lib = unit_library(repo / DLL, d, errors) + if lib: + libs[lib] = d + owned = {f: lib for lib in libs for f in shipped_names(lib)} + count = 0 + for rt in SHIPPED_RUNTIMES: + lib_dir = repo / "src" / "lib" / rt + files = sorted(p.name for p in lib_dir.iterdir() if p.is_file()) if lib_dir.is_dir() else [] + count += len(files) + for f in files: + path = f"src/lib/{rt}/{f}" + if f in owned or excused(path): + continue + errors.append(f"{path} is no library of an {ENGINES} engine or shared unit (their " + f"{DLL}/detail//Makefile TARGET and CMakeLists.txt add_library name it): add " + f"the sources that build it under {DLL}/detail// and the dir to {ENGINES}") + for lib, d in sorted(libs.items()): + missing = [f for f in shipped_names(lib) if f not in files] + if missing: + errors.append(f"{ENGINES}: {d} builds {lib}, but src/lib/{rt}/ lacks {', '.join(missing)}, " + f"which src/CMakeLists.txt links for {rt} (lib.so on Linux, .lib " + "and .dll on Windows): ship them, or drop the dir from " + f"{ENGINES} and {DLL}/detail/") + + for key in sorted(set(allow) - used): + errors.append(f"CATALOG_ALLOW (.github/script/ci/devkit_check.py): {key} excuses nothing any more " + f"({allow[key]}): drop the entry") + return (f"catalog: {len(npu)} NPU models ({len(aliases)} reusing another's kernels), " + f"{len(shipped)} shipped kernels, {count} prebuilt library files, {len(libs)} dev-kit libraries, " + f"{len(used)} allow-listed") + + def check_bsymbolic(repo: Path, errors: list) -> int: detail = repo / DLL / "detail" count = 0 @@ -707,11 +967,15 @@ def run(repo: Path, base: str = "", head: str = "HEAD") -> tuple[list[str], list if md_text is not None and assignment is not None: check_assignment_md(md_text, models, index, errors) notes.append(f"assignment md: {len(parse_assignment_md(md_text)[0])} model sections compared") + catalog = load_json(repo, MODEL_LIST, errors) engines = load_json(repo, ENGINES, errors) if engines is not None: - check_engines(repo, engines, models, errors) + check_engines(repo, engines, models, errors, + catalog_aliases(catalog, models) if catalog is not None else set()) notes.append(f"engines: {len(engines.get('engines') or {})} engines, " f"{len(engines.get('shared') or [])} shared") + if catalog is not None and engines is not None and assignment is not None: + notes.append(check_catalog(repo, catalog, models, engines, errors)) notes.append(f"rtp lock: {check_rtp_lock(repo, index, assignment, errors)} stanzas") notes.append(f"Bsymbolic: {check_bsymbolic(repo, errors)} Makefiles") notes.append(f"bench workflows: {check_bench_workflows(repo, errors)} checked") diff --git a/.github/script/ci/devkit_xclbin_plan.py b/.github/script/ci/devkit_xclbin_plan.py index c4f07a17d..50cf4c258 100644 --- a/.github/script/ci/devkit_xclbin_plan.py +++ b/.github/script/ci/devkit_xclbin_plan.py @@ -58,6 +58,13 @@ changes.py gives toolchain.lock and docker/aie-build* no area (devkit-aie-image.yml checks them), so those two only add the canary when another change already selected the xclbin area + - a shipped kernel, src/xclbins//.xclbin (added, + replaced or removed): the artifact kernel_assignment.json + puts in for every model whose folder is , so + devkit_xclbin_compare.py reports how the rebuild compares with + the shipped file. Nothing when no model assigns that slot (the + catalog check in devkit_check.py reports such a file). These + builds are not bench_models: their sources did not change - documentation (*.md), .gitignore files, host-only code (host_common/) and the FLM_Xclbin scripts no bitstream build reads (setup.sh, build_drivers.sh, dimhelper.py): nothing @@ -90,7 +97,7 @@ HERE = Path(__file__).resolve().parent REPO_ROOT = HERE.parents[2] sys.path.insert(0, str(HERE)) -from changes import DEVKIT_CI # noqa: E402 +from changes import DEVKIT_CI, SHIPPED_KERNEL # noqa: E402 from devkit_rtp_lock import LOCK_REL as RTP_LOCK, changed_artifacts # noqa: E402 XCLBIN = "flm-dev-kit/FLM_Xclbin" @@ -287,11 +294,29 @@ def changed_plan(plan: Plan, files: list[str], base_units: dict[str, list], plan.add(u, added, source=True) else: plan.add_unit(u) + elif SHIPPED_KERNEL.match(path): + add_shipped_kernel(plan, path) elif path.startswith(XCLBIN + "/") and not NO_BITSTREAM.match(path): for u in unit_for(path, plan.units, gone): plan.add_unit(u) +def add_shipped_kernel(plan: Plan, path: str) -> None: + """src/xclbins//.xclbin: the artifact each model using + assigns to , to compare with the shipped file.""" + folder, slot = path[len("src/xclbins/"):].rsplit("/", 1) + hits = {m: e["kernels"][slot] for m, e in sorted(plan.assignment.items()) + if e.get("folder") == folder and slot in (e.get("kernels") or {})} + if not hits: + plan.reasons.append(f"{path}: shipped kernel no {ASSIGNMENT} model assigns: nothing to build") + return + for a in sorted(set(hits.values())): + if not plan.add_artifact(a): + plan.reasons.append(f"warning: {path} is {a}, which no build unit produces") + plan.reasons.append(f"{path}: shipped kernel of {', '.join(hits)} -> {', '.join(sorted(set(hits.values())))}, " + "rebuilt to compare") + + def shard(builds: list[dict], max_shards: int, per_shard: int = 0) -> list[list[dict]]: """Contiguous shards of nearly equal size: at most max_shards, one per per_shard builds (0: as many as max_shards).""" diff --git a/.github/script/ci/test_changes.py b/.github/script/ci/test_changes.py index a1759e374..196c72c3c 100644 --- a/.github/script/ci/test_changes.py +++ b/.github/script/ci/test_changes.py @@ -132,8 +132,8 @@ def test_github_output(self): self.assertIn("run_tests=false", lines) self.assertEqual([l.split("=")[0] for l in lines], ["run_tests", "families", "asr_full", "suites", "hipep", - "new_models", "hipep_models", "devkit", "devkit_areas", "devkit_families", - "devkit_overlay", "devkit_bench", "summary"]) + "new_models", "hipep_models", "devkit", "devkit_catalog", "devkit_areas", + "devkit_families", "devkit_overlay", "devkit_bench", "summary"]) def test_suites_scoped_to_the_change(self): cases = { @@ -461,6 +461,11 @@ def test_devkit_docs_are_nothing(self): out = cli("--files", "flm-dev-kit/README.md", "flm-dev-kit/AGENTS.md", "flm-dev-kit/FLM_Xclbin/kernel_assignment.md", "flm-dev-kit/FLM_DLL/.gitignore") self.assertEqual((out["run_tests"], out["devkit"], out["devkit_areas"]), ("false", "false", "")) + # kernel_assignment.md is read by the catalog check, which still runs. + self.assertEqual(out["devkit_catalog"], "true") + self.assertEqual(out["summary"], "documentation only: NPU tests skipped; dev-kit catalog check runs") + out = cli("--files", "flm-dev-kit/README.md", "flm-dev-kit/AGENTS.md") + self.assertEqual((out["devkit"], out["devkit_catalog"]), ("false", "false")) self.assertEqual(out["summary"], "documentation only: NPU tests skipped") def test_mixed_keeps_product_rules_for_product_paths(self): @@ -584,6 +589,47 @@ def test_overlay(self): self.assertEqual(cli("--files", "docs/a.md")["suites"], "none") self.assertEqual(cli("--files", "src/server/server.cpp")["devkit_overlay"], "false") + def test_catalog_files_run_the_catalog_check(self): + """What src/ ships and the dev-kit JSON describing it run + devkit-static (devkit_catalog), and select no dev-kit build.""" + for path in ("src/model_list.json", "src/xclbins/Qwen3-8B-NPU2/attn.xclbin", + "src/xclbins/Qwen3-8B-NPU2/README.txt", "src/lib/hrx/libqwen3_npu.so", + "src/lib/xrt/libqwen3_npu.so", "src/lib/libcurl.dll", + "flm-dev-kit/FLM_DLL/engines.json", "flm-dev-kit/FLM_Xclbin/kernel_assignment.json", + "flm-dev-kit/FLM_Xclbin/kernel_assignment.md", "flm-dev-kit/FLM_Xclbin/build_units.json"): + with self.subTest(path=path): + self.assertEqual(cli("--files", path)["devkit_catalog"], "true") + # Only the model list: no dev-kit area, so no dev-kit build or overlay. + out = cli("--files", "src/model_list.json") + self.assertEqual((out["devkit"], out["devkit_areas"], out["devkit_overlay"]), ("false", "", "false")) + self.assertIn("dev-kit catalog check runs", out["summary"]) + out = cli("--files", "src/lib/hrx/libqwen3_npu.so") + self.assertEqual((out["devkit"], out["devkit_areas"]), ("false", "")) + for path in ("src/server/server.cpp", "src/model_info.json", "flm-dev-kit/FLM_DLL/model_list.json", + "flm-dev-kit/FLM_Xclbin/MM/Makefile", "docs/a.md"): + with self.subTest(path=path): + self.assertEqual(cli("--files", path)["devkit_catalog"], "false") + self.assertEqual(cli("--base", "0" * 40, "--head", "HEAD")["devkit_catalog"], "true") + self.assertEqual(changes.decide([]).outputs()["devkit_catalog"], "false") + + def test_shipped_kernel_is_rebuilt_to_compare_without_overlay(self): + out = cli("--files", "src/xclbins/Llama-3.1-8B-NPU2/layer.xclbin") + self.assertEqual((out["run_tests"], out["devkit"], out["devkit_areas"], out["devkit_families"], + out["devkit_overlay"]), ("true", "true", "xclbin", "", "false")) + self.assertEqual(families(out), {"llama3"}) + self.assertIn("shipped kernels rebuilt to compare", out["summary"]) + # Other files in the folder are no kernel. + self.assertEqual(cli("--files", "src/xclbins/Llama-3.1-8B-NPU2/rtp.txt")["devkit_areas"], "") + # With a kernel source the overlay runs as for that source alone. + out = cli("--files", "src/xclbins/Llama-3.1-8B-NPU2/layer.xclbin", + "flm-dev-kit/FLM_Xclbin/MM/iron/mm_aie.py") + self.assertEqual((out["devkit_areas"], out["devkit_overlay"]), ("xclbin", "true")) + self.assertNotIn("rebuilt to compare", out["summary"]) + # With a dev-kit engine: the engine's overlay, the kernel compared. + out = cli("--files", "src/xclbins/Llama-3.1-8B-NPU2/layer.xclbin", + "flm-dev-kit/FLM_DLL/detail/llama_npu/llama_npu.cpp") + self.assertEqual((out["devkit_areas"], out["devkit_overlay"]), ("xclbin,dll", "true")) + def test_unknown_files_select_every_area(self): out = cli("--base", "0" * 40, "--head", "HEAD") self.assertEqual((out["devkit"], out["devkit_areas"]), ("true", "xclbin,dll,converter,pybind,launchlib")) diff --git a/.github/script/ci/test_devkit_check.py b/.github/script/ci/test_devkit_check.py index 1817208b8..312d7fa24 100644 --- a/.github/script/ci/test_devkit_check.py +++ b/.github/script/ci/test_devkit_check.py @@ -11,6 +11,7 @@ import tempfile import unittest from pathlib import Path +from unittest import mock HERE = Path(__file__).resolve().parent sys.path.insert(0, str(HERE)) @@ -72,6 +73,23 @@ def __init__(self, root: Path): "m_flash": {"families": ["m-flash"], "models": [], "uses": ["m_npu"]}}} self.write_json(dc.ENGINES, self.engines) self.write(dc.RTP_LOCK, LOCK) + # What the product ships: the catalog and every assigned kernel. + self.catalog = {"model_path": "models", "models": {}} + self.sync_catalog() + + def sync_catalog(self) -> None: + """src/model_list.json and src/xclbins for every assignment model + (served_elsewhere skipped), named after its folder.""" + elsewhere = self.engines.get("served_elsewhere") or {} + for model, entry in self.assignment["models"].items(): + if model in elsewhere: + continue + family, size = model.split(":") + self.catalog["models"].setdefault(family, {}).setdefault(size, { + "supported_platforms": ["aie2p"], "name": entry["folder"], "details": {"family": family}}) + for slot in entry["kernels"]: + self.write(f"{dc.SHIPPED_XCLBINS}/{entry['folder']}/{slot}", "") + self.write_json(dc.MODEL_LIST, self.catalog) def write(self, rel: str, text: str) -> None: p = self.root / rel @@ -93,6 +111,10 @@ class Synthetic(unittest.TestCase): def setUp(self): self.tmp = Path(tempfile.mkdtemp()) self.tree = Tree(self.tmp) + # The real allow-list names real files: in a fixture it is all stale. + patcher = mock.patch.dict(dc.CATALOG_ALLOW, {}, clear=True) + patcher.start() + self.addCleanup(patcher.stop) def tearDown(self): shutil.rmtree(self.tmp) @@ -308,6 +330,7 @@ def lock_errors(base="HEAD~1"): t.engines["engines"]["o_npu"] = {"families": ["o"], "models": ["o:1b"], "uses": []} t.write_json(dc.ENGINES, t.engines) t.write(f"{dc.DLL}/detail/o_npu/Makefile", MAKEFILE) + t.sync_catalog() self.assertEqual(dc.run(self.tmp)[0], []) lock = self.tmp / dc.RTP_LOCK @@ -355,6 +378,157 @@ def lock_errors(base="HEAD~1"): self.assertTrue(any("changed with" in n and "o_npu" in n and "m_npu" in n for n in notes), notes) +class Catalog(Synthetic): + """src/ (model_list.json, xclbins, lib) against the dev kit's JSON.""" + + def entry(self, tag: str, **fields) -> None: + family, size = tag.split(":") + self.tree.catalog["models"].setdefault(family, {})[size] = { + "supported_platforms": ["aie2p"], "details": {"family": family}, **fields} + self.tree.write_json(dc.MODEL_LIST, self.tree.catalog) + + def engines(self, **models) -> None: + for engine, ms in models.items(): + self.tree.engines["engines"][engine]["models"] = ms + self.tree.write_json(dc.ENGINES, self.tree.engines) + + def library(self, unit: str, name: str, cmake: str = "") -> None: + self.tree.write(f"{dc.DLL}/detail/{unit}/Makefile", + MAKEFILE + f"TARGET = $(LIB_DIR)/lib{name}.so\nelse\nTARGET = $(BUILD_DIR)/{name}.dll\n") + self.tree.write(f"{dc.DLL}/detail/{unit}/CMakeLists.txt", + f"# add_library(old SHARED)\nadd_library({cmake or name} SHARED ${{SOURCES}})\n") + + def ship(self, *rels: str) -> None: + for rel in rels: + self.tree.write(rel, "") + + def test_npu_catalog_follows_flm_filter(self): + cat = {"models": { + "m": {"1b": {"supported_platforms": ["aie2p"]}, "2b": {"supported_platforms": ["dev04"]}, + "3b": {}, "4b": {"supported_platforms": ["aie2p"], "backend": "oga-hipep"}}, + "m-core": {"1b": {"supported_platforms": ["dev04"]}, "2b": {"supported_platforms": ["aie2p"]}}, + "m-oga-hipep": {"1b": {}, "2b": {"backend": "flm"}}, + "e": {"1b": {"supported_platforms": ["aie2p"], "model_kind": "embedding", "backend": "x"}}}} + self.assertEqual(sorted(dc.npu_catalog(cat)), ["e:1b", "m-oga-hipep:2b", "m:1b", "m:3b"]) + self.assertEqual(dc.xclbin_folder({"name": "A"}), "A") + self.assertEqual(dc.xclbin_folder({"name": "A", "xclbin_folder": "B"}), "B") + + def test_gpu_and_other_platform_entries_need_nothing(self): + self.entry("m:2b", name="M-2B") # no supported_platforms: an NPU model + self.assertError("model m:2b has no", "add \"m:2b\": {\"folder\": \"M-2B\"") + del self.tree.catalog["models"]["m"]["2b"] + self.entry("m:3b", name="M-3B", supported_platforms=["dev04"]) + self.entry("m-core:1b", name="M-Core", supported_platforms=["aie2p"]) + self.entry("m-oga-hipep:1b", name="M-GPU", supported_platforms=None) + self.assertEqual(self.tree.errors(), []) + + def test_rule1_npu_model_needs_an_assignment(self): + self.entry("n:1b", name="N-1B-NPU2") + self.assertError(f"{dc.MODEL_LIST}: NPU (aie2p) model n:1b has no {dc.ASSIGNMENT} entry", + '"folder": "N-1B-NPU2"', dc.ASSIGNMENT_MD) + self.assertError("NPU model n:1b of", "is served by no engine", "detail//") + + def test_rule1_alias_reuses_a_folder(self): + self.entry("n:1b", name="N-1B-NPU2", xclbin_folder="M-1B-NPU2") + self.assertEqual(dc.catalog_aliases(self.tree.catalog, self.tree.assignment["models"]), {"n:1b"}) + # An alias still needs an engine (or an allow-list entry). + self.assertError("NPU model n:1b of", "is served by no engine") + self.engines(m_npu=["m:1b", "n:1b"]) + self.assertEqual(self.tree.errors(), []) + self.entry("n:1b", name="N-1B-NPU2", xclbin_folder="Nope-NPU2") + self.assertError("n:1b runs the kernels of xclbin_folder Nope-NPU2, but no", "model has that folder") + + def test_rule1_alias_allow_listed(self): + self.entry("n:1b", name="N-1B-NPU2", xclbin_folder="M-1B-NPU2") + with mock.patch.dict(dc.CATALOG_ALLOW, {"n:1b": "runs elsewhere"}): + self.assertEqual(self.tree.errors(), []) + # Only an alias can be excused; a model with no kernels at all cannot. + self.entry("o:1b", name="O-1B-NPU2") + with mock.patch.dict(dc.CATALOG_ALLOW, {"o:1b": "no"}): + self.assertError("model o:1b has no") + self.assertError("CATALOG_ALLOW", "o:1b excuses nothing any more") + + def test_rule2_assignment_must_be_a_catalog_model(self): + del self.tree.catalog["models"]["m"] + self.tree.write_json(dc.MODEL_LIST, self.tree.catalog) + self.assertError(f"{dc.ASSIGNMENT}: m:1b is no NPU (aie2p) model of {dc.MODEL_LIST}", "served_elsewhere") + self.assertError("m_npu lists m:1b, which is no NPU (aie2p) model") + + def test_rule2_and_4_served_elsewhere(self): + t = self.tree + t.assignment["models"]["vla:1b"] = {"folder": "VLA", "kernels": {"attn.xclbin": "xclbins-Attn"}} + t.write_json(dc.ASSIGNMENT, t.assignment) + t.write(dc.ASSIGNMENT_MD, MD + "\n#### `vla:1b` → `VLA`\n\n| Kernels | Artifacts |\n|---|---|\n" + "| `attn.xclbin` | `xclbins-Attn` |\n") + self.assertError("vla:1b is no NPU (aie2p) model") + t.engines["served_elsewhere"] = {"vla:1b": "a pybind module"} + t.write_json(dc.ENGINES, t.engines) + # Not in the catalog and nothing shipped under src/xclbins/VLA: fine. + self.assertEqual(t.errors(), []) + + def test_rule3_folder_is_the_catalog_folder(self): + self.entry("m:1b", name="M-1B") + self.assertError(f"{dc.ASSIGNMENT}: m:1b has folder M-1B-NPU2, but", "xclbin folder M-1B") + self.entry("m:1b", name="M-1B", xclbin_folder="M-1B-NPU2") + self.assertEqual(self.tree.errors(), []) + + def test_rule4_assigned_slot_ships(self): + (self.tmp / dc.SHIPPED_XCLBINS / "M-1B-NPU2" / "layer.xclbin").unlink() + self.assertError("m:1b assigns layer.xclbin, but src/xclbins/M-1B-NPU2/layer.xclbin is not shipped") + + def test_rule5_shipped_kernel_is_assigned(self): + self.ship(f"{dc.SHIPPED_XCLBINS}/M-1B-NPU2/conv.xclbin", f"{dc.SHIPPED_XCLBINS}/M-1B-NPU2/notes.txt") + self.assertError("src/xclbins/M-1B-NPU2/conv.xclbin is shipped, but no", "with folder M-1B-NPU2 assigns " + "conv.xclbin", "CATALOG_ALLOW") + with mock.patch.dict(dc.CATALOG_ALLOW, {"src/xclbins/M-1B-NPU2/conv.xclbin": "unused"}): + self.assertEqual(self.tree.errors(), []) + self.ship(f"{dc.SHIPPED_XCLBINS}/X-NPU2/a.xclbin") + self.assertError("src/xclbins/X-NPU2/a.xclbin is shipped, but no", "model has folder X-NPU2") + + def test_rule5_union_over_models_sharing_a_folder(self): + # f:1b shares M-1B-NPU2 and adds a slot m:1b does not assign. + t = self.tree + t.assignment["models"]["f:1b"] = {"folder": "M-1B-NPU2", "kernels": {"mm.xclbin": "xclbins-Attn"}} + t.write_json(dc.ASSIGNMENT, t.assignment) + t.write(dc.ASSIGNMENT_MD, MD + "\n#### `f:1b` → `M-1B-NPU2`\n\n| Kernels | Artifacts |\n|---|---|\n" + "| `mm.xclbin` | `xclbins-Attn` |\n") + t.engines["engines"]["m_flash"]["models"] = ["f:1b"] + t.write_json(dc.ENGINES, t.engines) + t.sync_catalog() + self.entry("f:1b", name="F-1B-NPU2", xclbin_folder="M-1B-NPU2") + self.assertEqual(t.errors(), []) + + def test_stale_allow_list_entry(self): + with mock.patch.dict(dc.CATALOG_ALLOW, {"src/xclbins/M-1B-NPU2/gone.xclbin": "was unused"}): + self.assertError("src/xclbins/M-1B-NPU2/gone.xclbin excuses nothing any more (was unused)") + + def test_rule6_engine_model_must_be_in_the_catalog(self): + self.engines(m_flash=["m:9b"]) + self.assertError("m_flash lists m:9b, which is no NPU (aie2p) model of") + + def test_rule7_library_mapping(self): + self.assertEqual(self.tree.errors(), []) # no TARGET, no library: nothing to ship + self.library("q4nx", "q4_npu_eXpress") + self.library("m_npu", "m_npu") + self.assertError(f"{dc.ENGINES}: q4nx builds q4_npu_eXpress, but src/lib/xrt/ lacks " + "libq4_npu_eXpress.so, q4_npu_eXpress.dll, q4_npu_eXpress.lib") + self.assertError("m_npu builds m_npu, but src/lib/hrx/ lacks") + for rt in ("xrt", "hrx"): + self.ship(*(f"src/lib/{rt}/{f}" for lib in ("q4_npu_eXpress", "m_npu") for f in dc.shipped_names(lib))) + self.assertEqual(self.tree.errors(), []) + (self.tmp / "src/lib/hrx/m_npu.lib").unlink() + self.assertError("m_npu builds m_npu, but src/lib/hrx/ lacks m_npu.lib") + self.ship("src/lib/hrx/m_npu.lib", "src/lib/xrt/libnova_npu.so", "src/lib/xrt/libaiebu.a") + self.assertError("src/lib/xrt/libnova_npu.so is no library of an", "detail//") + self.assertError("src/lib/xrt/libaiebu.a is no library of an") + with mock.patch.dict(dc.CATALOG_ALLOW, {"src/lib/xrt/libnova_npu.so": "x", "src/lib/xrt/libaiebu.a": "y"}): + self.assertEqual(self.tree.errors(), []) + # The Makefile and CMakeLists.txt must build the same library. + self.library("m_npu", "m_npu", cmake="m_other") + self.assertError("detail/m_npu: its Makefile TARGET and CMakeLists.txt add_library name different " + "libraries (m_npu, m_other)") + + class RealTree(unittest.TestCase): def test_tree_passes(self): errors, _ = dc.run(dc.REPO_ROOT) diff --git a/.github/script/ci/test_devkit_xclbin_plan.py b/.github/script/ci/test_devkit_xclbin_plan.py index 650f50afe..2c68ffd1b 100644 --- a/.github/script/ci/test_devkit_xclbin_plan.py +++ b/.github/script/ci/test_devkit_xclbin_plan.py @@ -177,6 +177,31 @@ def test_bench_models_are_source_and_assignment_changes(self): self.assertEqual(builds(r), [("MM/host", "GENERIC")]) self.assertEqual((r["touched_models"], r["bench_models"]), (["m:1b", "m:new"], ["m:new"])) + def test_shipped_kernel_builds_its_assigned_artifact(self): + # Every model using the folder; models sharing it put the same + # artifact in a shared slot (devkit_check enforces it). + assignment = dict(ASSIGNMENT, **{"f:1b": {"folder": "M-1B", "kernels": { + "layer.xclbin": "xclbins-Fam_decoding_A", "extra.xclbin": "xclbins-Fam_decoding_C"}}}) + r = xp.make_plan("changed", UNITS, assignment, files=["src/xclbins/M-1B/layer.xclbin"], + canary=CANARY, base_units=UNITS, base_assignment=assignment) + self.assertEqual(builds(r), [("Fam/decoding", "A")]) + self.assertEqual(r["touched_models"], ["f:1b", "m:1b"]) + self.assertEqual(r["bench_models"], []) # no source changed + r = xp.make_plan("changed", UNITS, assignment, files=["src/xclbins/M-1B/extra.xclbin"], + canary=CANARY, base_units=UNITS, base_assignment=assignment) + self.assertEqual(builds(r), [("Fam/decoding", "C")]) + # A slot or folder no model assigns, and files that are no kernel: nothing. + for path in ("src/xclbins/M-1B/conv.xclbin", "src/xclbins/Nope/layer.xclbin", + "src/xclbins/M-1B/notes.txt", "src/xclbins/layer.xclbin"): + with self.subTest(path=path): + self.assertEqual(builds(plan(files=[path])), []) + self.assertTrue(any("no " in x and "assigns: nothing to build" in x + for x in plan(files=["src/xclbins/M-1B/conv.xclbin"])["reasons"])) + # Beside a source change: both, and only the source's users bench. + r = plan(files=["src/xclbins/M-3B/attn.xclbin", f"{X}/Dequant/kernel/k.cc"]) + self.assertEqual(builds(r), [("Dequant", None), ("Fam/prefill", None)]) + self.assertEqual(r["bench_models"], ["m:1b"]) + def test_unit_for_walks_up_to_the_nearest_unit(self): self.assertEqual(xp.unit_for(f"{X}/MM/host/kernel/a/b.cc", UNITS), ["MM/host"]) self.assertEqual(xp.unit_for(f"{X}/MM/host/Makefile", UNITS), ["MM/host"]) diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index e18dd13e8..0399988f1 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -139,6 +139,7 @@ jobs: # only the portable builds the overlay tests start from # (devkit-overlay); see .github/script/ci/changes.py. devkit: ${{ steps.detect.outputs.devkit }} + devkit-catalog: ${{ steps.detect.outputs.devkit-catalog }} devkit-areas: ${{ steps.detect.outputs.devkit-areas }} devkit-families: ${{ steps.detect.outputs.devkit-families }} devkit-overlay: ${{ steps.detect.outputs.devkit-overlay }} @@ -195,11 +196,19 @@ jobs: # Static checks of the dev kit's CI data (flm-dev-kit/FLM_Xclbin/ # kernel_assignment.json and build_units.json, flm-dev-kit/FLM_DLL/ # engines.json, the -Bsymbolic-functions link flag, and on a pull request - # the copyright notice of every source file it adds under flm-dev-kit/). - # Standard-library Python on a hosted runner; its unit tests run in changes. + # the copyright notice of every source file it adds under flm-dev-kit/), + # and the catalog rules: every model, kernel and engine library src/ ships + # has its dev-kit sources and entries. Runs for any dev-kit change + # (devkit) and for a change to what src/ ships or to the dev-kit JSON + # (devkit-catalog: src/model_list.json, src/xclbins/, src/lib/), which + # start no dev-kit build. Standard-library Python on a hosted runner; its + # unit tests run in changes. A release runs it too (its changes job sees + # every file as changed), deliberately: it checks the very catalog being + # released, in about a minute, but only summary's Dev-kit checks, which + # runs on pull requests, acts on its result, so it holds no release up. devkit-static: needs: changes - if: needs.changes.outputs.devkit == 'true' + if: needs.changes.outputs.devkit == 'true' || needs.changes.outputs.devkit-catalog == 'true' runs-on: ubuntu-latest timeout-minutes: 10 permissions: @@ -238,7 +247,8 @@ jobs: # the aie-build image on hosted runners (devkit-xclbins.yml): on a pull # request that selects the xclbin dev-kit area, the builds its changes # touch (mode changed, diffed like changes.py from the merge base of the - # pull request's base and head); on every push to main, every kernel the + # pull request's base and head; a replaced src/xclbins// + # rebuilds the artifact assigned to that slot, only to compare it); on every push to main, every kernel the # product ships (assigned); nightly, every build (all); on any other run # that selects the area (workflow_dispatch: no base to diff), assigned. # Not for a release. @@ -1542,8 +1552,10 @@ jobs: echo "::error::a package failed to build or its tests failed"; exit 1 fi - # A pull request whose dev-kit data does not check out, whose dev-kit - # engines do not build, or whose overlay tests (test-*-devkit) fail or + # A pull request whose dev-kit data does not check out (devkit-static, + # whose catalog rules also run for changes to src/model_list.json, + # src/xclbins and src/lib), whose dev-kit engines do not build, or + # whose overlay tests (test-*-devkit) fail or # are skipped though requested (a package or dev-kit build failed, or # the gate held them), fails here too, whatever the gate step above # decided, so this job stays the single required check. So does one diff --git a/.github/workflows/devkit-xclbins.yml b/.github/workflows/devkit-xclbins.yml index 4b73971b2..00328c1e2 100644 --- a/.github/workflows/devkit-xclbins.yml +++ b/.github/workflows/devkit-xclbins.yml @@ -12,8 +12,10 @@ name: Dev-kit xclbins # split into shards: .github/actions/devkit-xclbin-plan, rules in # .github/script/ci/devkit_xclbin_plan.py. mode changed (pull # requests): the units the change touches, the artifacts of the -# models whose kernel_assignment.json entry it changes, or for a -# toolchain or CI change two canary kernels. assigned: every +# models whose kernel_assignment.json entry it changes, the +# artifact assigned to each shipped kernel it replaces +# (src/xclbins//, so the compare below reports +# it), or for a toolchain or CI change two canary kernels. assigned: every # kernel the product ships; all: every build. A shard per 8 # builds, at most 16 (a pull request touching many kernels, as the # import did with 137, spreads them instead of packing ~34 per diff --git a/flm-dev-kit/AGENTS.md b/flm-dev-kit/AGENTS.md index 773ef50fe..4ea832fba 100644 --- a/flm-dev-kit/AGENTS.md +++ b/flm-dev-kit/AGENTS.md @@ -109,8 +109,42 @@ Kernel makefiles add `-j8` (`makefiles/common.mk`) unless `-j` is set. Test host - `aie2p-launchlib/launchlib` (`make test`) and `FLM_Pybind/SmolVLA` (`test_smolvla_*.py`). Engines and kernels are otherwise validated by running the model in `flm` and comparing outputs and -accuracy. Do not invent a `make test` or claim tests pass. FastFlowLM CI (`../.github/workflows/`) does -not build or test the dev kit. +accuracy. Do not invent a `make test` or claim tests pass. + +**FastFlowLM CI** (`../.github/workflows/build-and-test.yml`; which jobs a change selects is decided by +`../.github/script/ci/changes.py`) runs these dev-kit jobs: +- `devkit-static` (`../.github/script/ci/devkit_check.py`, seconds): the data files below agree with + each other and with the tree, every engine Makefile has `-Wl,-Bsymbolic-functions`, files a pull + request adds carry the copyright notice, and an RTP lock change comes with the engines that + hard-code those addresses. Its catalog rules also run when `../src/model_list.json`, + `../src/xclbins/` or `../src/lib/` change. +- `devkit-engines`: `FLM_DLL` built for Linux and Windows, XRT and HRX, on hosted runners, when a + change touches it or a `../src/lib/xrt/` library it links, and on every push to main and nightly. +- `devkit-xclbins`: `FLM_Xclbin` built with Peano in the `aie-build` image (Chess needs a license no + hosted runner has). A pull request builds the kernels it touches, plus the kernel assigned to each + `../src/xclbins/` file it replaces; main builds every assigned kernel, nightly every build unit. The result is compared with + `../src/xclbins/` (a report, never a failure), and a kernel whose RTP addresses differ from + `FLM_Xclbin/rtp_addresses.lock.txt` fails the job. +- Pull requests only: the NPU overlay jobs (`test-*-devkit`) put the engines and kernels built above + into the product's portable packages and run the NPU tests on the models they serve. +- `../.github/workflows/devkit-bench.yml` (its own workflow, after Build and Test): perf (`flm bench`, + the dev-kit build against the unmodified package on the same runner) and GSM8K accuracy, only + when engine or kernel source changed: on pull requests, and nightly when the source changed since + the last baseline. Results go to one pull request comment; slowdowns and accuracy drops warn. + +Keep in sync, in the same pull request: `FLM_Xclbin/build_units.json` (every directory with a +Makefile and its `MODEL_TYPE`s), `FLM_Xclbin/kernel_assignment.json` and `.md` (model → folder → slot +→ artifact), `FLM_DLL/engines.json` (engine → families, models, uses; shared units; +`served_elsewhere`), `FLM_Xclbin/rtp_addresses.lock.txt`, and the engine table in +`../.github/script/ci/changes.py`. **The dev kit is the source of what `flm` ships:** every NPU +(`aie2p`) model in `../src/model_list.json` needs a `kernel_assignment.json` entry whose folder is +its xclbin folder (a tag that only reuses another model's kernels names that folder in +`xclbin_folder` instead) and an `engines.json` engine listing it; every assigned slot ships as +`../src/xclbins//`, and every shipped `.xclbin` is assigned; every library in +`../src/lib/{xrt,hrx}/` is built by an `FLM_DLL/detail/` directory in `engines.json`, and each such +library ships as `lib.so`, `.dll` and `.lib` for both runtimes. A model added +only under `../src/` fails `devkit-static`. The few deliberate exceptions are listed, with reasons, +in `CATALOG_ALLOW` in `devkit_check.py`. ## 5. Conventions diff --git a/flm-dev-kit/FLM_DLL/engines.json b/flm-dev-kit/FLM_DLL/engines.json index 1ccc5b251..4af478f12 100644 --- a/flm-dev-kit/FLM_DLL/engines.json +++ b/flm-dev-kit/FLM_DLL/engines.json @@ -1,5 +1,5 @@ { - "_doc": "FLM_DLL engines. engines: every detail/ directory with a Makefile that builds a model library (lib.so / .dll) -> families: the FastFlowLM catalog families (details.family in src/model_list.json) to test when the engine changes, the same as the engine's row in ENGINES in .github/script/ci/changes.py; models: the kernel_assignment.json models it serves ([] = none yet); uses: the other engines whose sources or include/models// headers it compiles, so a change to one of those also tests this engine's families. shared: detail/ directories every engine builds against, which serve no model on their own; a change to one tests every engine's families. served_elsewhere: kernel_assignment.json models no engine here serves -> what runs them. Read by changes.py (devkit-families), checked by devkit_check.py.", + "_doc": "FLM_DLL engines. engines: every detail/ directory with a Makefile that builds a model library (lib.so / .dll) -> families: the FastFlowLM catalog families (details.family in src/model_list.json) to test when the engine changes, the same as the engine's row in ENGINES in .github/script/ci/changes.py; models: the kernel_assignment.json models it serves ([] = none yet), and the src/model_list.json NPU tags without an assignment of their own that it runs on another model's kernels (xclbin_folder, as qwen3.8-dflash2:27b); every NPU tag of src/model_list.json is listed by exactly one engine; uses: the other engines whose sources or include/models// headers it compiles, so a change to one of those also tests this engine's families. shared: detail/ directories every engine builds against, which serve no model on their own; a change to one tests every engine's families. served_elsewhere: kernel_assignment.json models no engine here serves -> what runs them. The library each engine and shared directory builds (its Makefile TARGET and CMakeLists.txt add_library, e.g. q4nx -> q4_npu_eXpress) must ship as src/lib/{xrt,hrx}/lib.so, .dll and .lib, and every library there must be one of them. Read by changes.py (devkit-families), checked by devkit_check.py.", "shared": [ "q4nx", "mha", @@ -272,7 +272,8 @@ "qwen3.8-dflash2" ], "models": [ - "qwen3.8-mtp:27b" + "qwen3.8-mtp:27b", + "qwen3.8-dflash2:27b" ], "uses": [] },