已合并
gym编包流程补充pypto包更新覆盖,同时冒烟复用编包流程的run包 #1120
hsqnb创建于 9 天前
gym编包流程补充pypto包更新覆盖,同时冒烟复用编包流程的run包 #1120
已合并
hsqnb创建于 9 天前
共 6 个文件变更+234-44
@@ -96,6 +96,68 @@ case "${ARCH}" in
96 ;;96 ;;
97esac97esac
98 98 
99+# ---------------------------------------------------------------------------
100+# Build & install pypto (master) before gym build (gym build depends on pypto).
101+# Skip the build when this PR's cached archive pypto_run_<arch>.tar.gz
102+# (.run + master sha, at ci/package/<MR>) matches current master HEAD
103+# (compile pods are ephemeral, so the cache rides on OBS).
104+# ---------------------------------------------------------------------------
105+PYPTO_REPO_DIR="${WORKSPACE}/pypto"
106+PYPTO_CACHE_TMP="${WORKSPACE}/pypto_cache_tmp"
107+ 
108+rm -rf "${PYPTO_REPO_DIR}"
109+git clone --depth 1 --branch master --single-branch https://gitcode.com/cann/pypto.git "${PYPTO_REPO_DIR}"
110+DP_ASSERT_EQUAL "$?" 0 "clone pypto master"
111+PYPTO_SHA=$(git -C "${PYPTO_REPO_DIR}" rev-parse HEAD)
112+ 
113+# reuse this PR's previous round archive when its sha matches master HEAD
114+PYPTO_RUN_PKG=""
115+if [ -n "${PYPTO_CACHE_URL}" ]; then
116+ rm -rf "${PYPTO_CACHE_TMP}" && mkdir -p "${PYPTO_CACHE_TMP}"
117+ if wget -q -O "${PYPTO_CACHE_TMP}/pypto_run.tar.gz" "${PYPTO_CACHE_URL}/pypto_run_${ARCH_TAG}.tar.gz"; then
118+ tar -zxf "${PYPTO_CACHE_TMP}/pypto_run.tar.gz" -C "${PYPTO_CACHE_TMP}"
119+ _cached_sha=$(cat "${PYPTO_CACHE_TMP}/pypto_master_sha_${ARCH_TAG}.txt" 2>/dev/null)
120+ if [ "${_cached_sha}" = "${PYPTO_SHA}" ]; then
121+ PYPTO_RUN_PKG=$(find "${PYPTO_CACHE_TMP}" -maxdepth 1 -name "cann-pypto_*.run" -print -quit)
122+ [ -n "${PYPTO_RUN_PKG}" ] && echo "pypto master unchanged (${PYPTO_SHA}), reuse cached run package from ${PYPTO_CACHE_URL}"
123+ else
124+ echo "pypto run cache outdated (cache sha: ${_cached_sha:-none}, master: ${PYPTO_SHA})"
125+ fi
126+ else
127+ echo "no cached pypto run package at ${PYPTO_CACHE_URL}/pypto_run_${ARCH_TAG}.tar.gz"
128+ fi
129+fi
130+if [ -z "${PYPTO_RUN_PKG}" ]; then
131+ echo "no reusable pypto run cache, build pypto"
132+fi
133+ 
134+if [ -z "${PYPTO_RUN_PKG}" ]; then
135+ cd "${PYPTO_REPO_DIR}"
136+ python3 -m pip install build "packaging==24.2"
137+ python3 build_ci.py --clean --build_type=Release --timeout=900 --no_isolation --job_num=16 --pkg-type run
138+ DP_ASSERT_EQUAL "$?" 0 "build pypto ${task_name}"
139+ PYPTO_RUN_PKG=$(find "${PYPTO_REPO_DIR}/build_out" -maxdepth 1 -name "cann-pypto_*.run" -print -quit)
140+ [ -n "${PYPTO_RUN_PKG}" ] || { LOG_ERROR "No pypto run package found in ${PYPTO_REPO_DIR}/build_out"; exit 1; }
141+fi
142+ 
143+# install as jenkins user: a root install aborts because install-path parents
144+# (/home/jenkins/Ascend/cann) belong to jenkins; --install-path is the Ascend
145+# root, pypto install.sh appends the "cann" version dir itself
146+echo "y" | su - jenkins -c "cd '${PYPTO_RUN_PKG%/*}' && bash './${PYPTO_RUN_PKG##*/}' --full --quiet --pylocal --install-path=/home/jenkins/Ascend"
147+DP_ASSERT_EQUAL "$?" 0 "install pypto run package"
148+ 
149+# archive .run + master sha: consumed by the smoke stage and the next round's
150+# cache read of this PR
151+echo "${PYPTO_SHA}" > "${WORKSPACE}/pypto_master_sha_${ARCH_TAG}.txt"
152+PYPTO_PKG_NAME="pypto_run_${ARCH_TAG}.tar.gz"
153+tar -zcf "${WORKSPACE}/${PYPTO_PKG_NAME}" -C "${PYPTO_RUN_PKG%/*}" "${PYPTO_RUN_PKG##*/}" -C "${WORKSPACE}" "pypto_master_sha_${ARCH_TAG}.txt"
154+ 
155+# pylocal-installed python packages for gym build-time pypto/pypto_pro codegen
156+export PYTHONPATH="/home/jenkins/Ascend/cann/python/site-packages:${PYTHONPATH}"
157+python3 -c "import pypto, pypto_pro" || { LOG_ERROR "import pypto/pypto_pro failed after pypto install"; exit 1; }
158+ 
159+cd "${WORKSPACE}"
160+ 
99python3 build_ci.py --clean --pkg-type run161python3 build_ci.py --clean --pkg-type run
100build_ret=$?162build_ret=$?
101DP_ASSERT_EQUAL "${build_ret}" 0 "build ${task_name}"163DP_ASSERT_EQUAL "${build_ret}" 0 "build ${task_name}"
@@ -111,3 +173,4 @@ PKG_NAME="build_whl_run_${ARCH_TAG}.tar.gz"
111tar -zcf "${WORKSPACE}/${PKG_NAME}" -C "${WORKSPACE}" build_whl_run173tar -zcf "${WORKSPACE}/${PKG_NAME}" -C "${WORKSPACE}" build_whl_run
112find "${WORKSPACE}/build_out" -mindepth 1 -delete174find "${WORKSPACE}/build_out" -mindepth 1 -delete
113cp -f "${WORKSPACE}/${PKG_NAME}" "${WORKSPACE}/build_out/"175cp -f "${WORKSPACE}/${PKG_NAME}" "${WORKSPACE}/build_out/"
176+cp -f "${WORKSPACE}/${PYPTO_PKG_NAME}" "${WORKSPACE}/build_out/"
@@ -51,7 +51,11 @@ echo "[INFO] pto-isa package url: ${pto_url}"
51 51 
52log "start run test case, please wait ..."52log "start run test case, please wait ..."
53echo "==============start smoke testing================="53echo "==============start smoke testing================="
54-bash pypto_gym_smoke.sh --src ${WORKSPACE} --pto_isa_url "${pto_url}" --src_target_branch master --f ${WORKSPACE}/pr_filelist.txt --ci 2>&1 | tee -a ./run_test.log54+# PYPTO_RUN_URL: compile.sh(stage2) 已编好的 pypto run 包下载地址, 由 workflow run:| 导出
55+# (x86 -> pypto_run_x86.tar.gz / aarch64 -> pypto_run_arm.tar.gz);
56+# 非空时 smoke 下载安装该包并跳过 pypto 源码构建, 为空时回退原 clone+build 流程
57+bash pypto_gym_smoke.sh --src ${WORKSPACE} --pto_isa_url "${pto_url}" --src_target_branch master \
58+ --f ${WORKSPACE}/pr_filelist.txt --ci --pypto_run_url "${PYPTO_RUN_URL:-}" 2>&1 | tee -a ./run_test.log
55smoke_rc=${PIPESTATUS[0]}59smoke_rc=${PIPESTATUS[0]}
56 60 
57# ==============================61# ==============================
@@ -109,8 +113,27 @@ STEST_ARG="--stest"
109[ -n "${GYM_STEST_FILTER}" ] && STEST_ARG="--stest=${GYM_STEST_FILTER}"113[ -n "${GYM_STEST_FILTER}" ] && STEST_ARG="--stest=${GYM_STEST_FILTER}"
110 114 
111cd "${WORKSPACE}" || exit 1115cd "${WORKSPACE}" || exit 1
116+# gym run 包复用 compile 产物: 下载 build_whl_run_<arch>.tar.gz 解出 .run 传给
117+# --stest-pkg, stest 只做轻量 aclnn bridges 构建 + 装包(跳过 gym 内核编译风暴);
118+# GYM_PKG_URL 为空时回退原全量构建流程
119+STEST_PKG=""
120+if [ -n "${GYM_PKG_URL}" ]; then
121+ rm -rf "${WORKSPACE}/gym_pkg" && mkdir -p "${WORKSPACE}/gym_pkg"
122+ if wget -q -O "${WORKSPACE}/gym_pkg/gym_bundle.tar.gz" "${GYM_PKG_URL}"; then
123+ tar -zxf "${WORKSPACE}/gym_pkg/gym_bundle.tar.gz" -C "${WORKSPACE}/gym_pkg"
124+ STEST_PKG=$(find "${WORKSPACE}/gym_pkg" -type f -name "cann-*pypto_gym*.run" -print -quit)
125+ fi
126+ if [ -z "${STEST_PKG}" ]; then
127+ echo "$(date +%Y%m%d.%H%M%S) : gym package download/extract failed from ${GYM_PKG_URL}"
128+ exit 1
129+ fi
130+ echo "$(date +%Y%m%d.%H%M%S) : gym stest reuses prebuilt package: ${STEST_PKG}"
131+fi
132+STEST_PKG_ARG=""
133+[ -n "${STEST_PKG}" ] && STEST_PKG_ARG="--stest-pkg ${STEST_PKG}"
134+ 
112# 三方库不传 cann_3rd_lib_path, 与 compile.sh(stage2) 一致, 由 prepare_3rd.cmake 回退 FetchContent135# 三方库不传 cann_3rd_lib_path, 与 compile.sh(stage2) 一致, 由 prepare_3rd.cmake 回退 FetchContent
113-"${GYM_PYTHON3}" build_ci.py --pkg-type run "${STEST_ARG}" --timeout "${GYM_STEST_TIMEOUT:-2700}" 2>&1 | tee -a ./run_stest.log136+"${GYM_PYTHON3}" build_ci.py --pkg-type run "${STEST_ARG}" ${STEST_PKG_ARG} --timeout "${GYM_STEST_TIMEOUT:-2700}" 2>&1 | tee -a ./run_stest.log
114stest_rc=${PIPESTATUS[0]}137stest_rc=${PIPESTATUS[0]}
115check_result "${stest_rc}" "./run_stest.log" "run gym stest"138check_result "${stest_rc}" "./run_stest.log" "run gym stest"
116echo "$(date +%Y%m%d.%H%M%S) : run gym stest success"139echo "$(date +%Y%m%d.%H%M%S) : run gym stest success"
@@ -63,6 +63,9 @@ jobs:
63 export REPOSITORY_NAME=ge63 export REPOSITORY_NAME=ge
64 export GIT_PR_NUMBER=${{ env.MERGE_ID }}64 export GIT_PR_NUMBER=${{ env.MERGE_ID }}
65 export ASCEND_3RD_LIB_PATH=/home/jenkins/opensource65 export ASCEND_3RD_LIB_PATH=/home/jenkins/opensource
66+ # pypto run 包缓存源(本 PR 的 OBS 归档目录): compile.sh 下载上一轮归档里的 sha
67+ # 与 master HEAD 比对, 一致则跳过 pypto 编包(编译 pod 不持久, 缓存走 OBS)
68+ export PYPTO_CACHE_URL="https://ascend-ci.obs.cn-north-4.myhuaweicloud.com/${{ env.obs_path }}"
66 BuildAccelerate bash compile.sh69 BuildAccelerate bash compile.sh
67 AC_SERVER_IP: ${{ vars.AC_SERVER_IP }}70 AC_SERVER_IP: ${{ vars.AC_SERVER_IP }}
68 - name: upload71 - name: upload
@@ -140,6 +140,9 @@ stages:
140 export repo_name=${{env.repo_name}}140 export repo_name=${{env.repo_name}}
141 export pr_id=${{ env.MERGE_ID }}141 export pr_id=${{ env.MERGE_ID }}
142 export PTO_ISA_ARCH=aarch64142 export PTO_ISA_ARCH=aarch64
143+ # compile.sh(stage2) 已编好的 pypto run 包, 冒烟下载安装以跳过 pypto 源码构建
144+ # (注: called workflow 的 outputs 拿不到 caller 的 env.obs_path, 此处直接拼 URL)
145+ export PYPTO_RUN_URL="https://ascend-ci.obs.cn-north-4.myhuaweicloud.com/${{ env.obs_path }}/pypto_run_arm.tar.gz"
143 bash ${{ steps.process_checkout.outputs.path }}/pre_smoke.sh146 bash ${{ steps.process_checkout.outputs.path }}/pre_smoke.sh
144 - name: upload147 - name: upload
145 uses: obs-upload148 uses: obs-upload
@@ -189,8 +192,8 @@ stages:
189 path: ${{ steps.process_checkout.outputs.path }}192 path: ${{ steps.process_checkout.outputs.path }}
190 -193 -
191 name: smoke executor194 name: smoke executor
192- # 覆盖 冒烟(pypto 构建/安装+910 用例跳过) + gym 950 run 包 clean 构建 + stest:195+ # 覆盖 冒烟(装 compile 产出的 pypto run 包+910 用例跳过) + gym 950 run 包 clean 构建 + stest:
193- # 需大于 GYM_STEST_TIMEOUT(默认 2700s) + pypto 构建安装预算 + gym clean 编译耗时196+ # 需大于 GYM_STEST_TIMEOUT(默认 2700s) + gym clean 编译耗时(pypto 构建已由 compile 产物替代)
194 timeout-minutes: 75197 timeout-minutes: 75
195 run: |198 run: |
196 set -e199 set -e
@@ -200,6 +203,12 @@ stages:
200 export pr_id=${{ env.MERGE_ID }}203 export pr_id=${{ env.MERGE_ID }}
201 export PTO_ISA_ARCH=x86_64204 export PTO_ISA_ARCH=x86_64
202 export GYM_SMOKE_SOC=950205 export GYM_SMOKE_SOC=950
206+ # compile.sh(stage2) 已编好的 pypto run 包, 冒烟下载安装以跳过 pypto 源码构建
207+ # (注: called workflow 的 outputs 拿不到 caller 的 env.obs_path, 此处直接拼 URL)
208+ export PYPTO_RUN_URL="https://ascend-ci.obs.cn-north-4.myhuaweicloud.com/${{ env.obs_path }}/pypto_run_x86.tar.gz"
209+ # compile 阶段的 gym run 包(build_whl_run_x86.tar.gz 内含 .run), stest 复用
210+ # 以跳过 gym 内核编译(build_ci.py --stest-pkg)
211+ export GYM_PKG_URL="https://ascend-ci.obs.cn-north-4.myhuaweicloud.com/${{ env.obs_path }}/build_whl_run_x86.tar.gz"
203 # gym stest 总超时(pypto 构装 + gym 构建 + stest 的 build_ci 内部预算)212 # gym stest 总超时(pypto 构装 + gym 构建 + stest 的 build_ci 内部预算)
204 export GYM_STEST_TIMEOUT=3600213 export GYM_STEST_TIMEOUT=3600
205 bash ${{ steps.process_checkout.outputs.path }}/pre_smoke.sh214 bash ${{ steps.process_checkout.outputs.path }}/pre_smoke.sh
@@ -340,6 +340,7 @@ class TestParam(CMakeParam):
340 """340 """
341 self.stest = args.stest # False (not requested) / True (no filter) / str (filter)341 self.stest = args.stest # False (not requested) / True (no filter) / str (filter)
342 self.stest_mode: str = args.stest_mode # auto / jit / torch / aclnn342 self.stest_mode: str = args.stest_mode # auto / jit / torch / aclnn
343+ self.stest_pkg: str = args.stest_pkg # prebuilt .run path (skip the cmake build)
343 344 
344 @property345 @property
345 def enabled(self) -> bool:346 def enabled(self) -> bool:
@@ -360,6 +361,8 @@ class TestParam(CMakeParam):
360 desc = "\nTests"361 desc = "\nTests"
361 desc += f"\n STest : {'ON' if not self.filter_expr else self.filter_expr}"362 desc += f"\n STest : {'ON' if not self.filter_expr else self.filter_expr}"
362 desc += f"\n STestMode : {self.stest_mode}"363 desc += f"\n STestMode : {self.stest_mode}"
364+ if self.stest_pkg:
365+ desc += f"\n STestPkg : {self.stest_pkg}"
363 return desc366 return desc
364 367 
365 @staticmethod368 @staticmethod
@@ -383,6 +386,13 @@ class TestParam(CMakeParam):
383 "in the environment); torch = force torch custom-op mode against the installed "386 "in the environment); torch = force torch custom-op mode against the installed "
384 "artifact; aclnn = force C++ bridge mode (run only).",387 "artifact; aclnn = force C++ bridge mode (run only).",
385 )388 )
389+ parser.add_argument(
390+ "--stest-pkg",
391+ default="",
392+ help="run stest against a prebuilt .run package (e.g. the compile-stage "
393+ "artifact) instead of building one: skips the kernel build and only "
394+ "compiles the lightweight aclnn test bridges locally. Requires --stest.",
395+ )
386 396 
387 def get_cfg_cmd(self, pkg_type_run: bool) -> str:397 def get_cfg_cmd(self, pkg_type_run: bool) -> str:
388 """Enable test targets (aclnn C++ bridge) only when run stest consumes them.398 """Enable test targets (aclnn C++ bridge) only when run stest consumes them.
@@ -591,23 +601,35 @@ class BuildCtrl(CMakeParam):
591 if ctrl.tests.enabled and len(ctrl.feature.soc_list) != 1:601 if ctrl.tests.enabled and len(ctrl.feature.soc_list) != 1:
592 raise ValueError("--stest supports exactly one soc; pass a single --soc")602 raise ValueError("--stest supports exactly one soc; pass a single --soc")
593 if ctrl.feature.pkg_type_run:603 if ctrl.feature.pkg_type_run:
594- soc_list = ctrl.feature.soc_list604+ if ctrl.tests.stest_pkg:
595- logging.info("PackageType(run), start process with CMake, %s soc(s): %s", len(soc_list), soc_list)605+ # stest from a prebuilt run package (e.g. the compile-stage
596- ctrl.cmake_clean()606+ # artifact): skip the kernel build, compile only the test bridges
597- # Build environment precheck is enforced on the CMake configure side607+ if not ctrl.tests.enabled:
598- # (cmake/config.cmake), covering every entry point (build_ci.py / manual cmake / CLion).608+ raise ValueError("--stest-pkg requires --stest")
609+ if ctrl.tests.stest_mode == "jit":
610+ raise ValueError("--stest-pkg is meaningless with --stest-mode jit "
611+ "(jit tests run from the source tree, no artifact)")
612+ logging.info("PackageType(run), stest from prebuilt package: %s", ctrl.tests.stest_pkg)
613+ ctrl.prepare_stest_pkg(soc=ctrl.feature.soc_list[0])
614+ ctrl.run_stest()
615+ else:
616+ soc_list = ctrl.feature.soc_list
617+ logging.info("PackageType(run), start process with CMake, %s soc(s): %s", len(soc_list), soc_list)
618+ ctrl.cmake_clean()
619+ # Build environment precheck is enforced on the CMake configure side
620+ # (cmake/config.cmake), covering every entry point (build_ci.py / manual cmake / CLion).
599 621 
600- # Multi-soc = multiple full build rounds: each soc gets its own binary dir and622+ # Multi-soc = multiple full build rounds: each soc gets its own binary dir and
601- # produces an independent .run (chip in package name); the output dir is shared.623+ # produces an independent .run (chip in package name); the output dir is shared.
602- for i, soc in enumerate(soc_list, start=1):624+ for i, soc in enumerate(soc_list, start=1):
603- logging.info("===== Soc round (%s/%s): %s =====", i, len(soc_list), soc)625+ logging.info("===== Soc round (%s/%s): %s =====", i, len(soc_list), soc)
604- ctrl.cmake_configure(soc=soc)626+ ctrl.cmake_configure(soc=soc)
605- ctrl.cmake_build(soc=soc)627+ ctrl.cmake_build(soc=soc)
606- # Shell wheel must exist before `package`: the install(CODE) rule628+ # Shell wheel must exist before `package`: the install(CODE) rule
607- # globs build/<soc>/shell_whl/*.whl into the run payload (决策 29).629+ # globs build/<soc>/shell_whl/*.whl into the run payload (决策 29).
608- ctrl.build_shell_wheel(soc=soc)630+ ctrl.build_shell_wheel(soc=soc)
609- ctrl.cmake_package(soc=soc)631+ ctrl.cmake_package(soc=soc)
610- ctrl.run_stest()632+ ctrl.run_stest()
611 else:633 else:
612 logging.info("PackageType(whl/aot), start process with CMake")634 logging.info("PackageType(whl/aot), start process with CMake")
613 ctrl.cmake_clean()635 ctrl.cmake_clean()
@@ -821,18 +843,6 @@ class BuildCtrl(CMakeParam):
821 _, duration = self._run_build_cmd(cmd=cmd)843 _, duration = self._run_build_cmd(cmd=cmd)
822 logging.info("CMake Configure[%s] success, %s", soc, duration)844 logging.info("CMake Configure[%s] success, %s", soc, duration)
823 845 
824- def cmake_build(self, soc: str):
825- """Execute CMake Build stage for one soc build round
826- 
827- :param soc: Soc name of current build round
828- """
829- jobs = self.jobs or (os.cpu_count() or 8)
830- cmd = f"{self.cmake} --build {self._build_dir(soc)} -j {jobs}"
831- cmd += " --verbose" if self.verbose else ""
832- logging.info("CMake Build[%s], Cmd: %s, Timeout: %s secs", soc, cmd, self.remain_timeout)
833- _, duration = self._run_build_cmd(cmd=cmd)
834- logging.info("CMake Build[%s] success, %s", soc, duration)
835- 
836 def cmake_package(self, soc: str):846 def cmake_package(self, soc: str):
837 """Execute CMake Package stage for one soc build round (set_cann_cpack_config -> .run)847 """Execute CMake Package stage for one soc build round (set_cann_cpack_config -> .run)
838 848 
@@ -888,6 +898,21 @@ class BuildCtrl(CMakeParam):
888 raise RuntimeError(f"no artifact matching {pattern!r} under {directory}")898 raise RuntimeError(f"no artifact matching {pattern!r} under {directory}")
889 return files[0]899 return files[0]
890 900 
901+ def cmake_build(self, soc: str, targets: Optional[List[str]] = None):
902+ """Execute CMake Build stage for one soc build round
903+ 
904+ :param soc: Soc name of current build round
905+ :param targets: Optional CMake target names; when omitted all targets build.
906+ """
907+ jobs = self.jobs or (os.cpu_count() or 8)
908+ cmd = f"{self.cmake} --build {self._build_dir(soc)} -j {jobs}"
909+ for target in (targets or []):
910+ cmd += f" --target {target}"
911+ cmd += " --verbose" if self.verbose else ""
912+ logging.info("CMake Build[%s], Cmd: %s, Timeout: %s secs", soc, cmd, self.remain_timeout)
913+ _, duration = self._run_build_cmd(cmd=cmd)
914+ logging.info("CMake Build[%s] success, %s", soc, duration)
915+ 
891 def _discover_op_dirs(self) -> Dict[str, Path]:916 def _discover_op_dirs(self) -> Dict[str, Path]:
892 """Discover operator dirs that have a tests/ directory (ops/{pro,tensor} only)."""917 """Discover operator dirs that have a tests/ directory (ops/{pro,tensor} only)."""
893 found: Dict[str, Path] = {}918 found: Dict[str, Path] = {}
@@ -995,6 +1020,32 @@ class BuildCtrl(CMakeParam):
995 }1020 }
996 self._run_pytest(op_dirs, mode="torch", soc=soc, update_env=update_env)1021 self._run_pytest(op_dirs, mode="torch", soc=soc, update_env=update_env)
997 1022 
1023+ def prepare_stest_pkg(self, soc: str):
1024+ """Stage a prebuilt .run for stest; build only the aclnn test bridges.
1025+ 
1026+ --stest-pkg mode: the run package comes from the compile stage (same
1027+ merge commit), so the kernel/op_host build storm is skipped. cmake runs
1028+ only to produce the lightweight EXCLUDE_FROM_ALL aclnn test bridges
1029+ (build/<soc>/tests) that aclnn-mode pytest loads via --aclnn-lib-dir.
1030+ The build tree is always cleaned first: a stale compile_stop.flag or
1031+ compile_pids.txt from an interrupted round must not leak into this one.
1032+ """
1033+ pkg = Path(self.tests.stest_pkg).resolve()
1034+ if not pkg.is_file():
1035+ raise RuntimeError(f"--stest-pkg not found: {pkg}")
1036+ if self.install_root in pkg.parents or self._build_root in pkg.parents:
1037+ raise RuntimeError(f"--stest-pkg must live outside {self.install_root}: {pkg}")
1038+ self.clean = True # force clean: build tree and build_out are rebuilt here
1039+ self.cmake_clean()
1040+ self.cmake_configure(soc=soc)
1041+ if self.tests.stest_mode in ("auto", "aclnn"):
1042+ self.cmake_build(soc=soc, targets=["gym_test_bridges"])
1043+ run_dir = self._run_dir(soc)
1044+ run_dir.mkdir(parents=True, exist_ok=True)
1045+ staged = run_dir / pkg.name
1046+ shutil.copy2(pkg, staged)
1047+ logging.info("Staged prebuilt run package for stest: %s", staged)
1048+ 
998 def _install_run_for_test(self, soc: str):1049 def _install_run_for_test(self, soc: str):
999 """Install the built .run into build_out/run/<soc> and return the pytest env."""1050 """Install the built .run into build_out/run/<soc> and return the pytest env."""
1000 run_dir = self._run_dir(soc).resolve()1051 run_dir = self._run_dir(soc).resolve()
@@ -301,6 +301,7 @@ LOG_INFO "PYPTO_3RD_LIB_PATH=$PYPTO_3RD_LIB_PATH"
301SRC_DIR=""301SRC_DIR=""
302SRC_TARGET_BRANCH="master" # 不传入本参数时默认是 master302SRC_TARGET_BRANCH="master" # 不传入本参数时默认是 master
303PTO_ISA_URL=""303PTO_ISA_URL=""
304+PYPTO_RUN_URL="" # compile.sh 已编好的 pypto run 包下载地址, 非空时跳过 pypto 源码构建
304CI_MODE=false305CI_MODE=false
305CHANGED_FILE_FROM_ARG=""306CHANGED_FILE_FROM_ARG=""
306while [[ $# -gt 0 ]]; do307while [[ $# -gt 0 ]]; do
@@ -317,6 +318,10 @@ while [[ $# -gt 0 ]]; do
317 PTO_ISA_URL="$2"318 PTO_ISA_URL="$2"
318 shift 2319 shift 2
319 ;;320 ;;
321+ --pypto_run_url)
322+ PYPTO_RUN_URL="$2"
323+ shift 2
324+ ;;
320 --ci)325 --ci)
321 CI_MODE=true326 CI_MODE=true
322 shift327 shift
@@ -345,6 +350,7 @@ SRC_DIR=$(cd "$SRC_DIR" && pwd)
345LOG_INFO "SRC_DIR=$SRC_DIR"350LOG_INFO "SRC_DIR=$SRC_DIR"
346LOG_INFO "SRC_TARGET_BRANCH=$SRC_TARGET_BRANCH"351LOG_INFO "SRC_TARGET_BRANCH=$SRC_TARGET_BRANCH"
347LOG_INFO "PTO_ISA_URL=$PTO_ISA_URL"352LOG_INFO "PTO_ISA_URL=$PTO_ISA_URL"
353+LOG_INFO "PYPTO_RUN_URL=$PYPTO_RUN_URL"
348 354 
349# ======================================================================================================================355# ======================================================================================================================
350# 4: 设置 CANN 环境变量356# 4: 设置 CANN 环境变量
@@ -397,12 +403,34 @@ if [ ! -f "$SETENV_SH" ]; then
397fi403fi
398LOG_DO source "$SETENV_SH"404LOG_DO source "$SETENV_SH"
399 405 
400-# 下载pypto代码406+# 获取 pypto run 包:
407+# PYPTO_RUN_URL 非空 -> 下载 compile.sh(stage2) 已编好的 pypto run 包, 跳过 pypto 源码构建,
408+# 按 install_pypto_run 期望的 <repo>/build_out 目录摆放
409+# 为空 -> 回退原流程: clone pypto 源码(与 gym 同级)
401work_dir="$SRC_DIR"410work_dir="$SRC_DIR"
402# 定位上级目录411# 定位上级目录
403work_parent_dir="${work_dir}/.."412work_parent_dir="${work_dir}/.."
404target_repo="${work_parent_dir}/pypto"413target_repo="${work_parent_dir}/pypto"
405 414 
415+if [ -n "${PYPTO_RUN_URL}" ]; then
416+ LOG_INFO "PYPTO_RUN_URL=${PYPTO_RUN_URL}, fetch prebuilt PyPTO run package"
417+ rm -rf "${target_repo}"
418+ mkdir -p "${target_repo}/build_out"
419+ pushd "${target_repo}" > /dev/null || exit 1
420+ if ! wget -q -O pypto_run.tar.gz "${PYPTO_RUN_URL}"; then
421+ LOG_ERROR "Download prebuilt PyPTO run package failed: ${PYPTO_RUN_URL}"
422+ exit 1
423+ fi
424+ if ! tar -zxf pypto_run.tar.gz -C build_out; then
425+ LOG_ERROR "Extract prebuilt PyPTO run package failed"
426+ exit 1
427+ fi
428+ rm -f pypto_run.tar.gz
429+ echo "========== prebuilt PyPTO run package =========="
430+ ls build_out
431+ echo "================================================"
432+ popd > /dev/null
433+else
406# 判断上级目录是否存在pypto文件夹,存在则彻底删除434# 判断上级目录是否存在pypto文件夹,存在则彻底删除
407if [ -d "${target_repo}" ]; then435if [ -d "${target_repo}" ]; then
408 echo "检测到上级目录已存在pypto仓库,开始删除..."436 echo "检测到上级目录已存在pypto仓库,开始删除..."
@@ -431,6 +459,7 @@ echo "======================================"
431 459 
432# 进入上级目录执行克隆操作460# 进入上级目录执行克隆操作
433cd "${work_dir}" || exit 1461cd "${work_dir}" || exit 1
462+fi
434 463 
435 464 
436# ======================================================================================================================465# ======================================================================================================================
@@ -470,20 +499,23 @@ LOG_DO "$PYTHON3_EXE" --version
470LOG_DO "$PYTHON3_EXE" -m pip list499LOG_DO "$PYTHON3_EXE" -m pip list
471LOG_DO "npu-smi" "info"500LOG_DO "npu-smi" "info"
472 501 
473-# 使用 PyPTO 仓库自身的构建入口生成 run 包。不要传 --just_build_whl,502+# 编 pypto run 包(仅源码构建分支; PYPTO_RUN_URL 非空时已由 compile 产物替代)。
503+# 不要传 --just_build_whl,
474# 也不要传 --models/-u/-s,避免在 PyPTO 仓库内提前执行其自身测试。504# 也不要传 --models/-u/-s,避免在 PyPTO 仓库内提前执行其自身测试。
475# $target_repo 是本脚本前面克隆的 pypto 仓(与 gym 同级), gym 的 build_ci.py 职责已修正为505# $target_repo 是本脚本前面克隆的 pypto 仓(与 gym 同级), gym 的 build_ci.py 职责已修正为
476# 构建 gym 自身产物(whl/custom run), 不再代理 pypto 构建.506# 构建 gym 自身产物(whl/custom run), 不再代理 pypto 构建.
477-if run_pypto_build "$PYTHON3_EXE" "$target_repo" \507+if [ -z "${PYPTO_RUN_URL}" ]; then
478- --clean \508+ if run_pypto_build "$PYTHON3_EXE" "$target_repo" \
479- --verbose \509+ --clean \
480- "--cann_3rd_lib_path=$PYPTO_3RD_LIB_PATH" \510+ --verbose \
481- "--timeout=$PYTHON_TOTAL_TIMEOUT"; then511+ "--cann_3rd_lib_path=$PYPTO_3RD_LIB_PATH" \
482- :512+ "--timeout=$PYTHON_TOTAL_TIMEOUT"; then
483-else513+ :
484- ret=$?514+ else
485- cleanup_npu_processes "$PYTHON3_EXE" "$SRC_DIR"515+ ret=$?
486- exit "$ret"516+ cleanup_npu_processes "$PYTHON3_EXE" "$SRC_DIR"
517+ exit "$ret"
518+ fi
487fi519fi
488 520 
489# gym 验证对象是 run 安装结果,不直接 pip install build_out 中的 whl。521# gym 验证对象是 run 安装结果,不直接 pip install build_out 中的 whl。
@@ -505,6 +537,15 @@ else
505fi537fi
506LOG_DO source "$SETENV_SH"538LOG_DO source "$SETENV_SH"
507 539 
540+# pypto whl 为 abi3 + 绑定在线编译设计(首次 import pypto 现场编译 pybind11 桥),
541+# pybind11 属隐含运行时依赖(pyproject dependencies 为空, run 包安装器 --no-deps 不携带);
542+# 源码构建分支由构建环节顺带备好, 下载 compile 产物分支需在此显式补装
543+if ! "$PYTHON3_EXE" -m pip install --disable-pip-version-check "pybind11>=2.13.6"; then
544+ LOG_ERROR "install pybind11 for pypto online binding build failed"
545+ cleanup_npu_processes "$PYTHON3_EXE" "$SRC_DIR"
546+ exit 1
547+fi
548+ 
508elapsed_before_tests=$(($(date +%s) - total_start))549elapsed_before_tests=$(($(date +%s) - total_start))
509GYM_TEST_TIMEOUT=$((PYTHON_TOTAL_TIMEOUT - elapsed_before_tests))550GYM_TEST_TIMEOUT=$((PYTHON_TOTAL_TIMEOUT - elapsed_before_tests))
510if [ "$GYM_TEST_TIMEOUT" -le 0 ]; then551if [ "$GYM_TEST_TIMEOUT" -le 0 ]; then