Skip to content

[codex] fix A5 validation link discovery#837

Draft
HecreReed wants to merge 1 commit into
hw-native-sys:mainfrom
HecreReed:codex/pr836-a5-boardfix
Draft

[codex] fix A5 validation link discovery#837
HecreReed wants to merge 1 commit into
hw-native-sys:mainfrom
HecreReed:codex/pr836-a5-boardfix

Conversation

@HecreReed

Copy link
Copy Markdown
Collaborator

Fix the A5 remote NPU validation flow so it no longer mis-detects A3 from simulator fallback directories and can resolve libnnopbase.so from the actual CANN install.\n\nValidation: bash -n on test/npu_validation/scripts/run_remote_npu_validation.sh and test/npu_validation/templates/run_sh_template.sh, plus python3 -m py_compile test/npu_validation/scripts/generate_testcase.py.

@reedhecre

reedhecre commented Jun 18, 2026

Copy link
Copy Markdown

Codex Review

该评论由 review 机器人自动更新。

  • PR: [codex] fix A5 validation link discovery #837 [codex] fix A5 validation link discovery
  • Author: HecreReed
  • Base/Head: main / codex/pr836-a5-boardfix
  • Head SHA: a5ccbdc95877
  • Trigger: 检测到新的 open PR
  • Generated At: 2026-06-18T04:11:06Z
  • Status: failed at codex-review (exit=1)

Summary

Review failed at stage codex-review: exit=1

Findings

未生成结构化 findings,因为 review 过程提前失败。

Log Tail


===== STAGE clone @ 2026-06-18 12:10:27 =====
set -euo pipefail
rm -rf '/tmp/ptoas-pr-review-monitor/runs/20260618_121026_pr837/repo'
git clone --branch 'main' --depth 50 'https://github.com/hw-native-sys/PTOAS.git' '/tmp/ptoas-pr-review-monitor/runs/20260618_121026_pr837/repo'
cd '/tmp/ptoas-pr-review-monitor/runs/20260618_121026_pr837/repo'
git fetch origin 'refs/pull/837/head:pr-837' --depth 50
git fetch origin 'main' --depth 50 || true
git checkout -f 'pr-837'
git rev-parse HEAD
git diff --stat 'origin/main...HEAD' || true
Cloning into '/tmp/ptoas-pr-review-monitor/runs/20260618_121026_pr837/repo'...
From https://github.com/hw-native-sys/PTOAS
 * [new ref]         refs/pull/837/head -> pr-837
From https://github.com/hw-native-sys/PTOAS
 * branch            main       -> FETCH_HEAD
Switched to branch 'pr-837'
a5ccbdc95877ceede60f16de073a3ba25099ba95
 test/npu_validation/scripts/generate_testcase.py   |  25 +++-
 .../scripts/run_remote_npu_validation.sh           | 139 ++++++++++++++++++---
 test/npu_validation/templates/run_sh_template.sh   | 122 +++++++++++++++++-
 3 files changed, 269 insertions(+), 17 deletions(-)
===== END STAGE clone rc=0 @ 2026-06-18 12:10:32 =====

===== STAGE codex-review @ 2026-06-18 12:10:32 =====
set -euo pipefail
cd '/tmp/ptoas-pr-review-monitor/runs/20260618_121026_pr837/repo'
'codex' exec -C '/tmp/ptoas-pr-review-monitor/runs/20260618_121026_pr837/repo' -s read-only -c 'model_provider="codereview"' -c 'model="gpt-5.4"' -c 'model_reasoning_effort="xhigh"' --output-schema '/tmp/ptoas-pr-review-monitor/runs/20260618_121026_pr837/review_schema.json' -o '/tmp/ptoas-pr-review-monitor/runs/20260618_121026_pr837/codex_last_message.json' --color never - < '/tmp/ptoas-pr-review-monitor/runs/20260618_121026_pr837/review_prompt.txt'
OpenAI Codex v0.115.0 (research preview)
--------
workdir: /tmp/ptoas-pr-review-monitor/runs/20260618_121026_pr837/repo
model: gpt-5.4
provider: codereview
approval: never
sandbox: read-only
reasoning effort: xhigh
reasoning summaries: none
session id: 019ed8ec-6a2b-7a01-9c61-6e420493b0d4
--------
user
你现在在审查 GitHub PR。

仓库:hw-native-sys/PTOAS
PR:#837 [codex] fix A5 validation link discovery
作者:HecreReed
base branch:origin/main
head branch:HEAD(当前已 checkout 到 PR head)

要求:
1. 只审查这个 PR 相对 origin/main 的改动,必要时可以看上下文文件。
2. 重点找真实的 correctness / regression / contract mismatch / CI / runtime / compatibility 问题。
3. 不要提纯风格建议,不要提低价值猜测。
4. 严格按优先级输出:
   - P1:高概率会导致错误结果、编译/运行失败、严重回归、发布阻断
   - P2:重要缺陷、行为回归、遗漏校验/测试、较大兼容性问题
   - P3:次要但明确可改的问题
5. 如果没有问题,summary 直接写:未检查到 PR #837 存在问题,并返回 findings=[]。
6. 如果有问题,summary 简洁概括,findings 里每条都要给出:
   - severity
   - title
   - body(说明为什么是问题,尽量具体)
   - file(尽量给相对路径)
   - line(能确定就填整数,否则 null)

建议先查看:
- git status --short
- git diff --stat origin/main...HEAD
- git diff --unified=80 origin/main...HEAD

最终输出必须严格匹配 JSON schema。

mcp startup: no servers
Reconnecting... 1/5 (unexpected status 503 Service Unavailable: Service temporarily unavailable, url: https://codex.0u0o.com/responses, cf-ray: a0d771feb8af3385-LAX, request id: 3618e3dc-cc30-4438-acfe-cd05969f9b13)
Reconnecting... 2/5 (unexpected status 503 Service Unavailable: Service temporarily unavailable, url: https://codex.0u0o.com/responses, cf-ray: a0d7721c58f79ab6-LAX, request id: f8ec9582-9571-49f6-92d2-0dd057a27889)
Reconnecting... 3/5 (unexpected status 503 Service Unavailable: Service temporarily unavailable, url: https://codex.0u0o.com/responses, cf-ray: a0d7723c587d4747-LAX, request id: f5b34b27-1958-40fb-b350-1364d14f08ca)
Reconnecting... 4/5 (unexpected status 503 Service Unavailable: Service temporarily unavailable, url: https://codex.0u0o.com/responses, cf-ray: a0d7725e0b545bf3-LAX, request id: a75f1361-546b-4716-a332-3fa84653fc2a)
Reconnecting... 5/5 (unexpected status 503 Service Unavailable: Service temporarily unavailable, url: https://codex.0u0o.com/responses, cf-ray: a0d77282feb5c69d-LAX, request id: 48f6f3a2-8efb-459d-a660-623f116caa8b)
ERROR: unexpected status 503 Service Unavailable: Service temporarily unavailable, url: https://codex.0u0o.com/responses, cf-ray: a0d772b45988cb9c-LAX, request id: b9b684a2-cfe8-4b27-9779-76d4562dd2ad
Warning: no last agent message; wrote empty content to /tmp/ptoas-pr-review-monitor/runs/20260618_121026_pr837/codex_last_message.json
===== END STAGE codex-review rc=1 @ 2026-06-18 12:11:06 =====

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a dynamic discovery mechanism for CANN host link directories to improve the robustness of NPU validation across different environments. The changes include adding helper functions to search for standard and fallback CANN roots and updating CMake configurations to link against the discovered paths. The review feedback highlights significant code duplication of these helper functions across scripts, suggesting centralizing them into a shared utility file. Additionally, the feedback recommends declaring the _pto_list_dirs array as local to prevent side effects and refactoring duplicated glob patterns in the search loops to improve maintainability.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +21 to +130
append_unique_colon_item() {
local list="$1"
local item="$2"
[[ -n "${item}" && -d "${item}" ]] || {
echo "${list}"
return 0
}
if [[ -z "${list}" ]]; then
echo "${item}"
return 0
fi
case ":${list}:" in
*":${item}:"*) echo "${list}" ;;
*) echo "${list}:${item}" ;;
esac
}

list_contains_file() {
local list="$1"
local file_name="$2"
local dir
IFS=':' read -r -a _pto_list_dirs <<< "${list}"
for dir in "${_pto_list_dirs[@]}"; do
[[ -n "${dir}" && -e "${dir}/${file_name}" ]] && return 0
done
return 1
}

host_lib_arch() {
case "$(uname -m)" in
aarch64 | arm64) echo "aarch64" ;;
x86_64 | amd64) echo "x86_64" ;;
*) uname -m ;;
esac
}

collect_cann_host_link_dirs_for_root() {
local root="$1"
local arch="$2"
local dirs="$3"
local dir=""
for dir in \
"${root}/lib64" \
"${root}/${arch}-linux/lib64" \
"${root}/runtime/lib64" \
"${root}/fwkacllib/lib64" \
"${root}/${arch}-linux/devlib" \
"${root}/${arch}-linux/devlib/linux/${arch}"; do
[[ -d "${dir}" ]] || continue
if [[ -e "${dir}/libnnopbase.so" || -e "${dir}/libascendcl.so" \
|| -e "${dir}/libplatform.so" || -e "${dir}/libtiling_api.a" \
|| -e "${dir}/libtiling_api.so" ]]; then
dirs="$(append_unique_colon_item "${dirs}" "${dir}")"
fi
done
echo "${dirs}"
}

discover_cann_host_link_dirs() {
local arch="$1"
local dirs=""
local root=""
local current_base=""
local -a candidate_roots=()
shopt -s nullglob

if [[ -n "${ASCEND_HOME_PATH:-}" ]]; then
dirs="$(collect_cann_host_link_dirs_for_root "${ASCEND_HOME_PATH}" "${arch}" "${dirs}")"
current_base="$(basename "${ASCEND_HOME_PATH}")"
fi
if list_contains_file "${dirs}" "libnnopbase.so"; then
shopt -u nullglob
echo "${dirs}"
return 0
fi

for root in \
/usr/local/Ascend/cann \
/usr/local/Ascend/cann-* \
/usr/local/Ascend/ascend-toolkit/latest \
/home/*/cann*/cann-* \
/home/*/*/cann-* \
/home/*/Ascend/*/cann-*; do
[[ -d "${root}" ]] || continue
[[ -n "${current_base}" && "${root}" == "${ASCEND_HOME_PATH:-}" ]] && continue
if [[ -n "${current_base}" && "${root}" == *"/${current_base}" ]]; then
candidate_roots+=("${root}")
fi
done
for root in \
/usr/local/Ascend/cann \
/usr/local/Ascend/cann-* \
/usr/local/Ascend/ascend-toolkit/latest \
/home/*/cann*/cann-* \
/home/*/*/cann-* \
/home/*/Ascend/*/cann-*; do
[[ -d "${root}" ]] || continue
[[ "${root}" == "${ASCEND_HOME_PATH:-}" ]] && continue
candidate_roots+=("${root}")
done
shopt -u nullglob

for root in "${candidate_roots[@]}"; do
dirs="$(collect_cann_host_link_dirs_for_root "${root}" "$(host_lib_arch)" "${dirs}")"
if list_contains_file "${dirs}" "libnnopbase.so"; then
break
fi
done
echo "${dirs}"
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

These helper functions are also defined in test/npu_validation/scripts/run_remote_npu_validation.sh. This large amount of duplicated code is a significant maintenance concern. Any bug fix or improvement would need to be applied in both places.

Consider moving these shared functions into a separate utility script (e.g., npu_validation_utils.sh) and sourcing it from both run_remote_npu_validation.sh and this template. This would centralize the logic and improve maintainability.

local list="$1"
local file_name="$2"
local dir
IFS=':' read -r -a _pto_list_dirs <<< "${list}"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The array _pto_list_dirs is not declared as a local variable. This could cause side effects if another part of the script uses a variable with the same name. It's best practice to declare all function-scoped variables as local.

Suggested change
IFS=':' read -r -a _pto_list_dirs <<< "${list}"
local -a _pto_list_dirs
IFS=':' read -r -a _pto_list_dirs <<< "${list}"

Comment on lines +114 to +137
for root in \
/usr/local/Ascend/cann \
/usr/local/Ascend/cann-* \
/usr/local/Ascend/ascend-toolkit/latest \
/home/*/cann*/cann-* \
/home/*/*/cann-* \
/home/*/Ascend/*/cann-*; do
[[ -d "${root}" ]] || continue
[[ -n "${current_base}" && "${root}" == "${ASCEND_HOME_PATH:-}" ]] && continue
if [[ -n "${current_base}" && "${root}" == *"/${current_base}" ]]; then
candidate_roots+=("${root}")
fi
done
for root in \
/usr/local/Ascend/cann \
/usr/local/Ascend/cann-* \
/usr/local/Ascend/ascend-toolkit/latest \
/home/*/cann*/cann-* \
/home/*/*/cann-* \
/home/*/Ascend/*/cann-*; do
[[ -d "${root}" ]] || continue
[[ "${root}" == "${ASCEND_HOME_PATH:-}" ]] && continue
candidate_roots+=("${root}")
done

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The list of glob patterns for discovering CANN roots is duplicated in these two for loops. This makes the script harder to maintain, as any changes to the search paths must be made in two places.

To improve maintainability, you could define the list of paths in a variable or an array and reuse it in both loops.

  local search_paths
  read -r -d '' search_paths <<'EOF'
    /usr/local/Ascend/cann
    /usr/local/Ascend/cann-*
    /usr/local/Ascend/ascend-toolkit/latest
    /home/*/cann*/cann-*
    /home/*/*/cann-*
    /home/*/Ascend/*/cann-*
EOF

  for root in $search_paths; do
    [[ -d "${root}" ]] || continue
    [[ -n "${current_base}" && "${root}" == "${ASCEND_HOME_PATH:-}" ]] && continue
    if [[ -n "${current_base}" && "${root}" == *"/${current_base}" ]]; then
      candidate_roots+=("${root}")
    fi
  done
  for root in $search_paths; do
    [[ -d "${root}" ]] || continue
    [[ "${root}" == "${ASCEND_HOME_PATH:-}" ]] && continue
    candidate_roots+=("${root}")
  done

local list="$1"
local file_name="$2"
local dir
IFS=':' read -r -a _pto_list_dirs <<< "${list}"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The array _pto_list_dirs is not declared as a local variable. This could cause side effects if another part of the script uses a variable with the same name. It's best practice to declare all function-scoped variables as local.

Suggested change
IFS=':' read -r -a _pto_list_dirs <<< "${list}"
local -a _pto_list_dirs
IFS=':' read -r -a _pto_list_dirs <<< "${list}"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants