|
1 | 1 | #!/usr/bin/env python3 |
2 | | -# Copyright 2020-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved. |
3 | | -# |
4 | | -# Redistribution and use in source and binary forms, with or without |
5 | | -# modification, are permitted provided that the following conditions |
6 | | -# are met: |
7 | | -# * Redistributions of source code must retain the above copyright |
8 | | -# notice, this list of conditions and the following disclaimer. |
9 | | -# * Redistributions in binary form must reproduce the above copyright |
10 | | -# notice, this list of conditions and the following disclaimer in the |
11 | | -# documentation and/or other materials provided with the distribution. |
12 | | -# * Neither the name of NVIDIA CORPORATION nor the names of its |
13 | | -# contributors may be used to endorse or promote products derived |
14 | | -# from this software without specific prior written permission. |
15 | | -# |
16 | | -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY |
17 | | -# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
18 | | -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
19 | | -# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
20 | | -# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
21 | | -# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
22 | | -# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
23 | | -# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
24 | | -# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 | | -# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
26 | | -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 2 | +# SPDX-FileCopyrightText: Copyright (c) 2020-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved. |
| 3 | +# SPDX-License-Identifier: BSD-3-Clause |
27 | 4 |
|
28 | 5 | import argparse |
29 | 6 | import importlib.util |
@@ -2556,6 +2533,20 @@ def enable_all(): |
2556 | 2533 | required=False, |
2557 | 2534 | help="Override specified backend CMake argument in the build as <backend>:<name>=<value>. The argument is passed to CMake as -D<name>=<value>. This flag only impacts CMake arguments that are used by build.py. To unconditionally add a CMake argument to the backend build use --extra-backend-cmake-arg.", |
2558 | 2535 | ) |
| 2536 | + parser.add_argument( |
| 2537 | + "--build-presets-file", |
| 2538 | + type=str, |
| 2539 | + required=False, |
| 2540 | + default=None, |
| 2541 | + help="(EXPERIMENTAL; requires TRITON_BUILD_EXPERIMENTAL=1) Path to a build " |
| 2542 | + "presets JSON file that pins per-component cmake flags (tag, cmake_args, " |
| 2543 | + "extra_cmake_args, library_path) for core/backends/repoagents/caches. " |
| 2544 | + "Command-line flags take precedence over the file. With --dryrun, a " |
| 2545 | + "provenance-annotated snapshot of every resolved cmake flag (labeled " |
| 2546 | + "cli/preset/default) is written to build_presets.json in the build " |
| 2547 | + "directory; that file can be loaded back with this flag. See " |
| 2548 | + "tools/build/build_presets.py for the schema.", |
| 2549 | + ) |
2559 | 2550 | parser.add_argument( |
2560 | 2551 | "--release-version", |
2561 | 2552 | required=False, |
@@ -2870,6 +2861,45 @@ def enable_all(): |
2870 | 2861 | OVERRIDE_BACKEND_CMAKE_FLAGS[be] = {} |
2871 | 2862 | OVERRIDE_BACKEND_CMAKE_FLAGS[be][parts[0]] = parts[1] |
2872 | 2863 |
|
| 2864 | + # Per-backend clone-organization overrides. Empty unless the experimental |
| 2865 | + # --build-presets-file supplies a TRITON_REPO_ORGANIZATION for a backend, in |
| 2866 | + # which case the backend build loop below clones from that organization. |
| 2867 | + backend_org_overrides = {} |
| 2868 | + |
| 2869 | + # Snapshots captured BEFORE applying a preset, so the --dryrun dump can tell |
| 2870 | + # which values came from the CLI vs the preset file vs build.py defaults. |
| 2871 | + _bp_before_backends = dict(backends) |
| 2872 | + _bp_before_repoagents = dict(repoagents) |
| 2873 | + _bp_before_caches = dict(caches) |
| 2874 | + _bp_cli_extra_be = {be: set(m) for be, m in EXTRA_BACKEND_CMAKE_FLAGS.items()} |
| 2875 | + _bp_cli_override_be = {be: set(m) for be, m in OVERRIDE_BACKEND_CMAKE_FLAGS.items()} |
| 2876 | + _bp_cli_core = set(EXTRA_CORE_CMAKE_FLAGS) | set(OVERRIDE_CORE_CMAKE_FLAGS) |
| 2877 | + |
| 2878 | + # Experimental: apply a build preset (all load/validate/precedence logic lives |
| 2879 | + # in tools/build/build_presets.py). Command-line flags win over the file. |
| 2880 | + if FLAGS.build_presets_file is not None: |
| 2881 | + from tools.build import build_presets |
| 2882 | + |
| 2883 | + try: |
| 2884 | + for msg in build_presets.apply( |
| 2885 | + FLAGS.build_presets_file, |
| 2886 | + backends=backends, |
| 2887 | + repoagents=repoagents, |
| 2888 | + caches=caches, |
| 2889 | + cli_backend_specs=FLAGS.backend, |
| 2890 | + cli_repoagent_specs=FLAGS.repoagent, |
| 2891 | + cli_cache_specs=FLAGS.cache, |
| 2892 | + library_paths=library_paths, |
| 2893 | + extra_backend_flags=EXTRA_BACKEND_CMAKE_FLAGS, |
| 2894 | + override_backend_flags=OVERRIDE_BACKEND_CMAKE_FLAGS, |
| 2895 | + extra_core_flags=EXTRA_CORE_CMAKE_FLAGS, |
| 2896 | + override_core_flags=OVERRIDE_CORE_CMAKE_FLAGS, |
| 2897 | + backend_org_overrides=backend_org_overrides, |
| 2898 | + ): |
| 2899 | + log(msg) |
| 2900 | + except build_presets.BuildPresetError as e: |
| 2901 | + fail(str(e)) |
| 2902 | + |
2873 | 2903 | # Initialize map of common components and repo-tag for each. |
2874 | 2904 | components = { |
2875 | 2905 | "common": default_repo_tag, |
@@ -2907,6 +2937,61 @@ def enable_all(): |
2907 | 2937 |
|
2908 | 2938 | # Write the build script that invokes cmake for the core, backends, repo-agents, and caches. |
2909 | 2939 | pathlib.Path(FLAGS.build_dir).mkdir(parents=True, exist_ok=True) |
| 2940 | + |
| 2941 | + # Experimental: on a --dryrun, emit a provenance-annotated snapshot of the |
| 2942 | + # fully-resolved cmake configuration -- every -D each component receives, as |
| 2943 | + # in cmake_build -- to <build-dir>/build_presets.json, labeling each value's |
| 2944 | + # source (cli / preset / default). The file can be loaded back with |
| 2945 | + # --build-presets-file to pin every flag. Gated behind |
| 2946 | + # TRITON_BUILD_EXPERIMENTAL=1. |
| 2947 | + if FLAGS.dryrun and os.getenv("TRITON_BUILD_EXPERIMENTAL") == "1": |
| 2948 | + from tools.build import build_presets |
| 2949 | + |
| 2950 | + _bp_be = [b for b in backends if b not in CORE_BACKENDS] |
| 2951 | + try: |
| 2952 | + for msg in build_presets.write_snapshot( |
| 2953 | + os.path.join(FLAGS.build_dir, "build_presets.json"), |
| 2954 | + parser=parser, |
| 2955 | + argv=sys.argv, |
| 2956 | + core_args=core_cmake_args( |
| 2957 | + components, backends, script_cmake_dir, script_install_dir |
| 2958 | + ), |
| 2959 | + backend_args={ |
| 2960 | + be: backend_cmake_args( |
| 2961 | + images, components, be, script_install_dir, library_paths |
| 2962 | + ) |
| 2963 | + for be in _bp_be |
| 2964 | + }, |
| 2965 | + repoagent_args={ |
| 2966 | + ra: repoagent_cmake_args(images, components, ra, script_install_dir) |
| 2967 | + for ra in repoagents |
| 2968 | + }, |
| 2969 | + cache_args={ |
| 2970 | + ca: cache_cmake_args(images, components, ca, script_install_dir) |
| 2971 | + for ca in caches |
| 2972 | + }, |
| 2973 | + backends=backends, |
| 2974 | + repoagents=repoagents, |
| 2975 | + caches=caches, |
| 2976 | + before_backends=_bp_before_backends, |
| 2977 | + before_repoagents=_bp_before_repoagents, |
| 2978 | + before_caches=_bp_before_caches, |
| 2979 | + cli_backend_specs=FLAGS.backend, |
| 2980 | + cli_repoagent_specs=FLAGS.repoagent, |
| 2981 | + cli_cache_specs=FLAGS.cache, |
| 2982 | + cli_extra_be=_bp_cli_extra_be, |
| 2983 | + cli_override_be=_bp_cli_override_be, |
| 2984 | + cli_core=_bp_cli_core, |
| 2985 | + extra_backend_flags=EXTRA_BACKEND_CMAKE_FLAGS, |
| 2986 | + override_backend_flags=OVERRIDE_BACKEND_CMAKE_FLAGS, |
| 2987 | + extra_core_flags=EXTRA_CORE_CMAKE_FLAGS, |
| 2988 | + override_core_flags=OVERRIDE_CORE_CMAKE_FLAGS, |
| 2989 | + library_paths=library_paths, |
| 2990 | + ): |
| 2991 | + log(msg) |
| 2992 | + except build_presets.BuildPresetError as e: |
| 2993 | + fail(str(e)) |
| 2994 | + |
2910 | 2995 | with BuildScript( |
2911 | 2996 | os.path.join(FLAGS.build_dir, script_name), |
2912 | 2997 | verbose=FLAGS.verbose, |
@@ -2940,7 +3025,9 @@ def enable_all(): |
2940 | 3025 | if be == "armnn_tflite": |
2941 | 3026 | github_organization = "https://gitlab.com/arm-research/smarter/" |
2942 | 3027 | else: |
2943 | | - github_organization = FLAGS.github_organization |
| 3028 | + github_organization = backend_org_overrides.get( |
| 3029 | + be, FLAGS.github_organization |
| 3030 | + ) |
2944 | 3031 |
|
2945 | 3032 | if be == "vllm": |
2946 | 3033 | backend_clone( |
|
0 commit comments