Merged
docs: 补齐op_common公共接口列表并修复AllocTensor函数声明 #588
songkai111Add on Jul 2
docs: 补齐op_common公共接口列表并修复AllocTensor函数声明 #588
Merged
Merged fromsongkai111/opbase_3968masterintocann/opbasemaster
Total: 4 files changed+279-36
| @@ -20,10 +20,10 @@ | |||
| 20 | </tr></thead> | 20 | </tr></thead> |
| 21 | <tbody> | 21 | <tbody> |
| 22 | <tr> | 22 | <tr> |
| 23 | - <td rowspan="33">log</td> | 23 | + <td rowspan="44">log</td> |
| 24 | <td><a href='OP_LOGE.md'>OP_LOGE</a></td> | 24 | <td><a href='OP_LOGE.md'>OP_LOGE</a></td> |
| 25 | <td>打印算子ERROR级别日志。</td> | 25 | <td>打印算子ERROR级别日志。</td> |
| 26 | - <td rowspan="33">include/op_common/log/log.h</td> | 26 | + <td rowspan="44">include/op_common/log/log.h</td> |
| 27 | </tr> | 27 | </tr> |
| 28 | <tr> | 28 | <tr> |
| 29 | <td><a href='OP_LOGD.md'>OP_LOGD</a></td> | 29 | <td><a href='OP_LOGD.md'>OP_LOGD</a></td> |
| @@ -153,6 +153,50 @@ | |||
| 153 | <td><a href='OP_LOGE_FOR_INVALID_VALUES_WITH_REASON.md'>OP_LOGE_FOR_INVALID_VALUES_WITH_REASON</a></td> | 153 | <td><a href='OP_LOGE_FOR_INVALID_VALUES_WITH_REASON.md'>OP_LOGE_FOR_INVALID_VALUES_WITH_REASON</a></td> |
| 154 | <td>记录并上报多参数值校验错误(带原因),上报EZ0027错误码。</td> | 154 | <td>记录并上报多参数值校验错误(带原因),上报EZ0027错误码。</td> |
| 155 | </tr> | 155 | </tr> |
| 156 | + <tr> | ||
| 157 | + <td><a href='OP_LOGE_FOR_INVALID_STRIDE.md'>OP_LOGE_FOR_INVALID_STRIDE</a></td> | ||
| 158 | + <td>记录并上报参数stride校验错误,上报EZ0028错误码。</td> | ||
| 159 | + </tr> | ||
| 160 | + <tr> | ||
| 161 | + <td><a href='OP_LOGE_FOR_FILE_PATH.md'>OP_LOGE_FOR_FILE_PATH</a></td> | ||
| 162 | + <td>记录并上报文件路径无效错误,上报EZ0029错误码。</td> | ||
| 163 | + </tr> | ||
| 164 | + <tr> | ||
| 165 | + <td><a href='OP_LOGE_FOR_FILE_OPEN.md'>OP_LOGE_FOR_FILE_OPEN</a></td> | ||
| 166 | + <td>记录并上报文件打开失败错误,上报EZ0030错误码。</td> | ||
| 167 | + </tr> | ||
| 168 | + <tr> | ||
| 169 | + <td><a href='OP_LOGE_FOR_FILE_PARSE.md'>OP_LOGE_FOR_FILE_PARSE</a></td> | ||
| 170 | + <td>记录并上报文件解析失败错误,上报EZ0031错误码。</td> | ||
| 171 | + </tr> | ||
| 172 | + <tr> | ||
| 173 | + <td><a href='OP_LOGE_FOR_INVALID_CONFIG.md'>OP_LOGE_FOR_INVALID_CONFIG</a></td> | ||
| 174 | + <td>记录并上报配置项值无效错误,上报EZ0032错误码。</td> | ||
| 175 | + </tr> | ||
| 176 | + <tr> | ||
| 177 | + <td><a href='OP_LOGE_FOR_INVALID_CONFIG_WITH_REASON.md'>OP_LOGE_FOR_INVALID_CONFIG_WITH_REASON</a></td> | ||
| 178 | + <td>记录并上报配置项值无效错误(带原因),上报EZ0033错误码。</td> | ||
| 179 | + </tr> | ||
| 180 | + <tr> | ||
| 181 | + <td><a href='OP_LOGE_FOR_INVALID_CONFIGS_WITH_REASON.md'>OP_LOGE_FOR_INVALID_CONFIGS_WITH_REASON</a></td> | ||
| 182 | + <td>记录并上报多配置项值无效错误(带原因),上报EZ0034错误码。</td> | ||
| 183 | + </tr> | ||
| 184 | + <tr> | ||
| 185 | + <td><a href='OP_LOGE_FOR_INVALID_FORMAT_WITH_REASON.md'>OP_LOGE_FOR_INVALID_FORMAT_WITH_REASON</a></td> | ||
| 186 | + <td>记录并上报参数格式校验错误(带原因),上报EZ0035错误码。</td> | ||
| 187 | + </tr> | ||
| 188 | + <tr> | ||
| 189 | + <td><a href='OP_LOGE_FOR_INVALID_GRAPH_NODE.md'>OP_LOGE_FOR_INVALID_GRAPH_NODE</a></td> | ||
| 190 | + <td>记录并上报图节点无效错误,上报EZ0036错误码。</td> | ||
| 191 | + </tr> | ||
| 192 | + <tr> | ||
| 193 | + <td><a href='OP_LOGE_FOR_INVALID_ARGUMENT_WITH_REASON.md'>OP_LOGE_FOR_INVALID_ARGUMENT_WITH_REASON</a></td> | ||
| 194 | + <td>记录并上报参数无效错误(带原因),上报EZ0037错误码。</td> | ||
| 195 | + </tr> | ||
| 196 | + <tr> | ||
| 197 | + <td><a href='OP_LOGE_FOR_INVALID_LISTSIZE_WITH_REASON.md'>OP_LOGE_FOR_INVALID_LISTSIZE_WITH_REASON</a></td> | ||
| 198 | + <td>记录并上报参数列表大小校验错误(带原因),上报EZ0038错误码。</td> | ||
| 199 | + </tr> | ||
| 156 | <tr> | 200 | <tr> |
| 157 | <td rowspan="5">math</td> | 201 | <td rowspan="5">math</td> |
| 158 | <td><a href='FloorDiv.md'>FloorDiv</a></td> | 202 | <td><a href='FloorDiv.md'>FloorDiv</a></td> |
| @@ -176,10 +220,10 @@ | |||
| 176 | <td>判断两个float类型或double类型的数值是否相等。</td> | 220 | <td>判断两个float类型或double类型的数值是否相等。</td> |
| 177 | </tr> | 221 | </tr> |
| 178 | <tr> | 222 | <tr> |
| 179 | - <td rowspan="4">platform</td> | 223 | + <td rowspan="11">platform</td> |
| 180 | <td><a href='GetAivCoreNum.md'>GetAivCoreNum</a></td> | 224 | <td><a href='GetAivCoreNum.md'>GetAivCoreNum</a></td> |
| 181 | <td>获取平台AI Vector的核数。</td> | 225 | <td>获取平台AI Vector的核数。</td> |
| 182 | - <td rowspan="4">include/op_common/op_host/util/platform_util.h</td> | 226 | + <td rowspan="11">include/op_common/op_host/util/platform_util.h</td> |
| 183 | </tr> | 227 | </tr> |
| 184 | <tr> | 228 | <tr> |
| 185 | <td><a href='GetAicCoreNum.md'>GetAicCoreNum</a></td> | 229 | <td><a href='GetAicCoreNum.md'>GetAicCoreNum</a></td> |
| @@ -190,11 +234,39 @@ | |||
| 190 | <td>获取平台UB(Unified Buffer)空间大小,单位bytes。</td> | 234 | <td>获取平台UB(Unified Buffer)空间大小,单位bytes。</td> |
| 191 | </tr> | 235 | </tr> |
| 192 | <tr> | 236 | <tr> |
| 193 | - <td><a href='GetUbBlockSize.md'>GetUbBlockSize</a></td> | 237 | + <td><a href='GetUbBlockSize.md'>GetUbBlockSize</a></td> |
| 194 | <td>获取平台UB(Unified Buffer)的block单元大小,单位bytes。</td> | 238 | <td>获取平台UB(Unified Buffer)的block单元大小,单位bytes。</td> |
| 195 | </tr> | 239 | </tr> |
| 196 | <tr> | 240 | <tr> |
| 197 | - <td rowspan="6">infershape</td> | 241 | + <td><a href='GetVRegSize.md'>GetVRegSize</a></td> |
| 242 | + <td>获取平台向量寄存器(Vector Register)的大小,单位bytes。</td> | ||
| 243 | + </tr> | ||
| 244 | + <tr> | ||
| 245 | + <td><a href='GetSimtMaxThreadNum.md'>GetSimtMaxThreadNum</a></td> | ||
| 246 | + <td>获取平台SIMT最大线程数。</td> | ||
| 247 | + </tr> | ||
| 248 | + <tr> | ||
| 249 | + <td><a href='GetSimtMaxDCacheSize.md'>GetSimtMaxDCacheSize</a></td> | ||
| 250 | + <td>获取平台SIMT最大DCache大小,单位bytes。</td> | ||
| 251 | + </tr> | ||
| 252 | + <tr> | ||
| 253 | + <td><a href='GetCacheLineSize.md'>GetCacheLineSize</a></td> | ||
| 254 | + <td>获取平台Cache Line的大小,单位bytes。</td> | ||
| 255 | + </tr> | ||
| 256 | + <tr> | ||
| 257 | + <td><a href='GetSectorCacheLineSize.md'>GetSectorCacheLineSize</a></td> | ||
| 258 | + <td>获取平台Sector Cache Line的大小,单位bytes。</td> | ||
| 259 | + </tr> | ||
| 260 | + <tr> | ||
| 261 | + <td><a href='GetNddmaDcacheSize.md'>GetNddmaDcacheSize</a></td> | ||
| 262 | + <td>获取平台NDDMA DCache的大小,单位bytes。</td> | ||
| 263 | + </tr> | ||
| 264 | + <tr> | ||
| 265 | + <td><a href='GetWorkspaceSize.md'>GetWorkspaceSize</a></td> | ||
| 266 | + <td>获取平台LibApi Workspace的大小,单位bytes。</td> | ||
| 267 | + </tr> | ||
| 268 | + <tr> | ||
| 269 | + <td rowspan="8">infershape</td> | ||
| 198 | <td><a href='SetUnknownRank.md'>SetUnknownRank</a></td> | 270 | <td><a href='SetUnknownRank.md'>SetUnknownRank</a></td> |
| 199 | <td>设置输入shape为维度不确定的动态shape。</td> | 271 | <td>设置输入shape为维度不确定的动态shape。</td> |
| 200 | <td rowspan="4">include/op_common/op_host/util/shape_util.h</td> | 272 | <td rowspan="4">include/op_common/op_host/util/shape_util.h</td> |
| @@ -212,14 +284,23 @@ | |||
| 212 | <td>检查输入shape的每一根轴长度是否都为不确定值。</td> | 284 | <td>检查输入shape的每一根轴长度是否都为不确定值。</td> |
| 213 | </tr> | 285 | </tr> |
| 214 | <tr> | 286 | <tr> |
| 215 | - <td><a href='InferShape4Broadcast.md'>InferShape4Broadcast</a></td> | 287 | + <td><a href='InferShape4Broadcast.md'>InferShape4Broadcast</a></td> |
| 216 | <td>broadcast类算子的infershape方法。</td> | 288 | <td>broadcast类算子的infershape方法。</td> |
| 217 | - <td rowspan="1">include/op_common/op_host/infershape_broadcast_util.h</td> | 289 | + <td rowspan="2">include/op_common/op_host/infershape_broadcast_util.h</td> |
| 218 | </tr> | 290 | </tr> |
| 219 | <tr> | 291 | <tr> |
| 220 | - <td><a href='InferShape4Elewise.md'>InferShape4Elewise</a></td> | 292 | + <td><a href='BroadcastShape.md'>BroadcastShape</a></td> |
| 293 | + <td>根据输入张量的shape推导broadcast后的输出shape。</td> | ||
| 294 | + </tr> | ||
| 295 | + <tr> | ||
| 296 | + <td><a href='InferShape4Elewise.md'>InferShape4Elewise</a></td> | ||
| 221 | <td>elewise类算子的infershape方法。</td> | 297 | <td>elewise类算子的infershape方法。</td> |
| 222 | <td rowspan="1">include/op_common/op_host/infershape_elewise_util.h</td> | 298 | <td rowspan="1">include/op_common/op_host/infershape_elewise_util.h</td> |
| 223 | </tr> | 299 | </tr> |
| 300 | + <tr> | ||
| 301 | + <td><a href='InferShape4Reduce.md'>InferShape4Reduce</a></td> | ||
| 302 | + <td>reduce类算子的infershape方法。</td> | ||
| 303 | + <td rowspan="1">include/op_common/op_host/infershape_reduce_util.h</td> | ||
| 304 | + </tr> | ||
| 224 | </tbody> | 305 | </tbody> |
| 225 | </table> | 306 | </table> |
| @@ -1,10 +1,10 @@ | |||
| 1 | #!/bin/sh | 1 | #!/bin/sh |
| 2 | # ----------------------------------------------------------------------------------------------------------- | 2 | # ----------------------------------------------------------------------------------------------------------- |
| 3 | # Copyright (c) 2026 Huawei Technologies Co., Ltd. | 3 | # Copyright (c) 2026 Huawei Technologies Co., Ltd. |
| 4 | -# This program is free software, you can redistribute it and/or modify it under the terms and conditions of | 4 | +# This program is free software, you can redistribute it and/or modify it under the terms and conditions of |
| 5 | # CANN Open Software License Agreement Version 2.0 (the "License"). | 5 | # CANN Open Software License Agreement Version 2.0 (the "License"). |
| 6 | # Please refer to the License for details. You may not use this file except in compliance with the License. | 6 | # Please refer to the License for details. You may not use this file except in compliance with the License. |
| 7 | -# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | 7 | +# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, |
| 8 | # INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | 8 | # INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. |
| 9 | # See LICENSE in the root of the software repository for the full text of the License. | 9 | # See LICENSE in the root of the software repository for the full text of the License. |
| 10 | # ----------------------------------------------------------------------------------------------------------- | 10 | # ----------------------------------------------------------------------------------------------------------- |
| @@ -48,12 +48,25 @@ if [ -z "$_PYTHON" ]; then | |||
| 48 | fi | 48 | fi |
| 49 | 49 | ||
| 50 | # --------------------------------------------------------------------------- | 50 | # --------------------------------------------------------------------------- |
| 51 | -# 1. Ensure oat-py is installed | 51 | +# 1. Ensure oat-py is installed (serialized via flock to prevent parallel pip conflicts) |
| 52 | # --------------------------------------------------------------------------- | 52 | # --------------------------------------------------------------------------- |
| 53 | _OAT_OK=$("$_PYTHON" -c "import importlib.util; print('ok' if importlib.util.find_spec('oat') else 'missing')" 2>/dev/null || echo "missing") | 53 | _OAT_OK=$("$_PYTHON" -c "import importlib.util; print('ok' if importlib.util.find_spec('oat') else 'missing')" 2>/dev/null || echo "missing") |
| 54 | if [ "$_OAT_OK" != "ok" ]; then | 54 | if [ "$_OAT_OK" != "ok" ]; then |
| 55 | echo "[OAT] oat-py not found. Installing oat-py>=1.0.1 ..." | 55 | echo "[OAT] oat-py not found. Installing oat-py>=1.0.1 ..." |
| 56 | - "$_PYTHON" -m pip install --quiet "oat-py>=1.0.1" | 56 | + _LOCK_FILE="/tmp/oat_pip_install.lock" |
| 57 | + # flock ensures only one concurrent invocation runs pip install at a time; | ||
| 58 | + # re-check inside the lock so processes that waited skip redundant installs | ||
| 59 | + if command -v flock >/dev/null 2>&1; then | ||
| 60 | + ( | ||
| 61 | + flock -w 120 9 | ||
| 62 | + _RECHECK=$("$_PYTHON" -c "import importlib.util; print('ok' if importlib.util.find_spec('oat') else 'missing')" 2>/dev/null || echo "missing") | ||
| 63 | + if [ "$_RECHECK" != "ok" ]; then | ||
| 64 | + "$_PYTHON" -m pip install --quiet "oat-py>=1.0.1" | ||
| 65 | + fi | ||
| 66 | + ) 9>"$_LOCK_FILE" | ||
| 67 | + else | ||
| 68 | + "$_PYTHON" -m pip install --quiet "oat-py>=1.0.1" | ||
| 69 | + fi | ||
| 57 | _OAT_OK=$("$_PYTHON" -c "import importlib.util; print('ok' if importlib.util.find_spec('oat') else 'missing')" 2>/dev/null || echo "missing") | 70 | _OAT_OK=$("$_PYTHON" -c "import importlib.util; print('ok' if importlib.util.find_spec('oat') else 'missing')" 2>/dev/null || echo "missing") |
| 58 | if [ "$_OAT_OK" != "ok" ]; then | 71 | if [ "$_OAT_OK" != "ok" ]; then |
| 59 | echo "[OAT] [WARNING] Failed to install oat-py. Please run: pip install oat-py>=1.0.1" | 72 | echo "[OAT] [WARNING] Failed to install oat-py. Please run: pip install oat-py>=1.0.1" |
| @@ -68,10 +81,99 @@ fi | |||
| 68 | # --------------------------------------------------------------------------- | 81 | # --------------------------------------------------------------------------- |
| 69 | REPO_ROOT=$(git rev-parse --show-toplevel 2>/dev/null || pwd) | 82 | REPO_ROOT=$(git rev-parse --show-toplevel 2>/dev/null || pwd) |
| 70 | REPO_NAME=$(basename "$REPO_ROOT") | 83 | REPO_NAME=$(basename "$REPO_ROOT") |
| 71 | -OAT_REPORT_DIR="$REPO_ROOT/oat_reports" | 84 | +OAT_REPORT_DIR="${TMPDIR:-/tmp}/oat_reports_$$" |
| 85 | +OAT_RESULT_DIR="$REPO_ROOT/oat_reports" | ||
| 86 | + | ||
| 87 | +# --------------------------------------------------------------------------- | ||
| 88 | +# 2a. PR-range deduplication (pure git, no CI env vars required) | ||
| 89 | +# | ||
| 90 | +# Strategy: | ||
| 91 | +# 1. Find the merge-base between HEAD and the upstream branch (origin/master | ||
| 92 | +# or similar). If found, this is a feature-branch context — collect ALL | ||
| 93 | +# files changed since the branch diverged (full PR diff). | ||
| 94 | +# 2. Key a done-marker on the HEAD SHA. The first invocation runs the scan; | ||
| 95 | +# every subsequent invocation for the same HEAD exits 0 immediately. | ||
| 96 | +# This eliminates redundant scans when CI calls the hook once per commit. | ||
| 97 | +# 3. If no merge-base is found (e.g. committing directly on master) fall back | ||
| 98 | +# to scanning only the currently staged files, with no done-marker. | ||
| 99 | +# --------------------------------------------------------------------------- | ||
| 100 | +_PR_MERGE_BASE="" | ||
| 101 | +_DONE_MARKER="" | ||
| 102 | +_HEAD_SHA=$(git rev-parse HEAD 2>/dev/null | cut -c1-12 || true) | ||
| 103 | + | ||
| 104 | +if [ -n "$_HEAD_SHA" ]; then | ||
| 105 | + # Try to find merge-base with a known upstream branch | ||
| 106 | + if [ -n "${PRE_COMMIT_FROM_REF:-}" ]; then | ||
| 107 | + # pre-commit --from-ref/--to-ref: use the provided base directly | ||
| 108 | + _PR_MERGE_BASE=$(git merge-base "$PRE_COMMIT_FROM_REF" HEAD 2>/dev/null || true) | ||
| 109 | + fi | ||
| 110 | + if [ -z "$_PR_MERGE_BASE" ]; then | ||
| 111 | + # Search all remotes (origin, upstream, etc.) for common trunk branch names. | ||
| 112 | + # This handles fork setups where origin=fork and upstream=main-repo. | ||
| 113 | + _CANDIDATE_BASE="" | ||
| 114 | + _CANDIDATE_DIST=0 | ||
| 115 | + for _b in $(git for-each-ref --format='%(refname:short)' \ | ||
| 116 | + 'refs/remotes/*/master' 'refs/remotes/*/main' \ | ||
| 117 | + 'refs/remotes/*/develop' 'refs/remotes/*/dev' 2>/dev/null); do | ||
| 118 | + _mb=$(git merge-base HEAD "$_b" 2>/dev/null || true) | ||
| 119 | + [ -z "$_mb" ] && continue | ||
| 120 | + # Skip if merge-base is HEAD itself (branch is ahead of or equal to HEAD) | ||
| 121 | + [ "$_mb" = "$(git rev-parse HEAD 2>/dev/null)" ] && continue | ||
| 122 | + # Pick the candidate whose merge-base is furthest from HEAD | ||
| 123 | + # (most commits since divergence = most likely true PR base) | ||
| 124 | + _dist=$(git rev-list --count "$_mb"..HEAD 2>/dev/null || echo 0) | ||
| 125 | + if [ -z "$_CANDIDATE_BASE" ] || [ "$_dist" -gt "$_CANDIDATE_DIST" ]; then | ||
| 126 | + _CANDIDATE_BASE="$_mb" | ||
| 127 | + _CANDIDATE_DIST="$_dist" | ||
| 128 | + fi | ||
| 129 | + done | ||
| 130 | + _PR_MERGE_BASE="$_CANDIDATE_BASE" | ||
| 131 | + fi | ||
| 132 | + | ||
| 133 | + # Only use PR-range mode when HEAD has diverged from the upstream base | ||
| 134 | + if [ -n "$_PR_MERGE_BASE" ] && [ "$_PR_MERGE_BASE" != "$(git rev-parse HEAD 2>/dev/null)" ]; then | ||
| 135 | + mkdir -p "$OAT_RESULT_DIR" | ||
| 136 | + _DONE_MARKER="$OAT_RESULT_DIR/.done_${_HEAD_SHA}" | ||
| 137 | + if [ -f "$_DONE_MARKER" ]; then | ||
| 138 | + echo "[OAT] [SKIP] Already scanned HEAD=${_HEAD_SHA}. Skipping duplicate invocation." | ||
| 139 | + exit 0 | ||
| 140 | + fi | ||
| 141 | + else | ||
| 142 | + # HEAD == merge-base: on the upstream branch itself, no PR range | ||
| 143 | + _PR_MERGE_BASE="" | ||
| 144 | + fi | ||
| 145 | +fi | ||
| 146 | + | ||
| 147 | +# --------------------------------------------------------------------------- | ||
| 148 | +# 2b. Deduplicate parallel invocations within the same pre-commit run. | ||
| 149 | +# Only the first instance that acquires the lock actually runs the scan; | ||
| 150 | +# all others wait then exit 0. | ||
| 151 | +# --------------------------------------------------------------------------- | ||
| 152 | +if command -v flock >/dev/null 2>&1; then | ||
| 153 | + _OAT_SCAN_LOCK="${TMPDIR:-/tmp}/oat_scan_$(echo "$REPO_ROOT" | tr '/\\: ' '____').lock" | ||
| 154 | + exec 9>"$_OAT_SCAN_LOCK" | ||
| 155 | + if ! flock -n 9; then | ||
| 156 | + echo "[OAT] Another OAT scan instance is running. Waiting..." | ||
| 157 | + flock -w 120 9 | ||
| 158 | + # Re-check done marker: if the scanning instance completed normally, skip. | ||
| 159 | + # If it exited abnormally (no marker), fall through and run the scan ourselves. | ||
| 160 | + if [ -n "$_DONE_MARKER" ] && [ -f "$_DONE_MARKER" ]; then | ||
| 161 | + echo "[OAT] Scan already completed by another instance. Skipping." | ||
| 162 | + exit 0 | ||
| 163 | + fi | ||
| 164 | + echo "[OAT] Previous instance did not complete. Proceeding with scan..." | ||
| 165 | + # Fall through to run the scan below | ||
| 166 | + fi | ||
| 167 | + # This instance now owns the lock and will run the scan. | ||
| 168 | +fi | ||
| 72 | 169 | ||
| 73 | echo "[OAT] Running OAT scan (Python Edition) — INCREMENTAL MODE" | 170 | echo "[OAT] Running OAT scan (Python Edition) — INCREMENTAL MODE" |
| 74 | echo "[OAT] Project: $REPO_NAME" | 171 | echo "[OAT] Project: $REPO_NAME" |
| 172 | +if [ -n "$_PR_MERGE_BASE" ]; then | ||
| 173 | + echo "[OAT] Mode: PR range — scanning all files changed since merge-base" | ||
| 174 | +else | ||
| 175 | + echo "[OAT] Mode: staged files — scanning only currently staged files" | ||
| 176 | +fi | ||
| 75 | 177 | ||
| 76 | # --------------------------------------------------------------------------- | 178 | # --------------------------------------------------------------------------- |
| 77 | # 3. Collect staged files | 179 | # 3. Collect staged files |
| @@ -93,7 +195,31 @@ if [ $# -gt 0 ]; then | |||
| 93 | FILE_LIST="$FILE_LIST,$_abs" | 195 | FILE_LIST="$FILE_LIST,$_abs" |
| 94 | fi | 196 | fi |
| 95 | done | 197 | done |
| 198 | +elif [ -n "$_PR_MERGE_BASE" ]; then | ||
| 199 | + # PR range mode: collect ALL files changed since the branch diverged | ||
| 200 | + _STAGED=$(git diff --name-only --diff-filter=ACM "$_PR_MERGE_BASE" HEAD \ | ||
| 201 | + 2>/dev/null || true) | ||
| 202 | + if [ -z "$_STAGED" ]; then | ||
| 203 | + echo "[OAT] No files changed in PR range. Skipping." | ||
| 204 | + [ -n "$_DONE_MARKER" ] && touch "$_DONE_MARKER" 2>/dev/null || true | ||
| 205 | + exit 0 | ||
| 206 | + fi | ||
| 207 | + FILE_COUNT=$(echo "$_STAGED" | wc -l | tr -d ' ') | ||
| 208 | + FILE_LIST="" | ||
| 209 | + for _f in $_STAGED; do | ||
| 210 | + case "$_f" in | ||
| 211 | + /*) _abs="$_f" ;; | ||
| 212 | + *) _abs="$REPO_ROOT/$_f" ;; | ||
| 213 | + esac | ||
| 214 | + [ -f "$_abs" ] || continue | ||
| 215 | + if [ -z "$FILE_LIST" ]; then | ||
| 216 | + FILE_LIST="$_abs" | ||
| 217 | + else | ||
| 218 | + FILE_LIST="$FILE_LIST,$_abs" | ||
| 219 | + fi | ||
| 220 | + done | ||
| 96 | else | 221 | else |
| 222 | + # Staged files mode: on upstream branch directly, scan only staged files | ||
| 97 | _STAGED=$(git diff --cached --name-only --diff-filter=ACM 2>/dev/null || true) | 223 | _STAGED=$(git diff --cached --name-only --diff-filter=ACM 2>/dev/null || true) |
| 98 | if [ -z "$_STAGED" ]; then | 224 | if [ -z "$_STAGED" ]; then |
| 99 | echo "[OAT] No staged files to check. Skipping." | 225 | echo "[OAT] No staged files to check. Skipping." |
| @@ -123,17 +249,10 @@ fi | |||
| 123 | echo "[OAT] Checking $FILE_COUNT staged file(s)..." | 249 | echo "[OAT] Checking $FILE_COUNT staged file(s)..." |
| 124 | 250 | ||
| 125 | # --------------------------------------------------------------------------- | 251 | # --------------------------------------------------------------------------- |
| 126 | -# 4. Ensure oat_reports/ exists and is in .gitignore | 252 | +# 4. Ensure report directories exist |
| 127 | # --------------------------------------------------------------------------- | 253 | # --------------------------------------------------------------------------- |
| 128 | mkdir -p "$OAT_REPORT_DIR" | 254 | mkdir -p "$OAT_REPORT_DIR" |
| 129 | - | 255 | +mkdir -p "$OAT_RESULT_DIR" |
| 130 | -_GITIGNORE="$REPO_ROOT/.gitignore" | ||
| 131 | -for _entry in "oat_reports" "log"; do | ||
| 132 | - if ! grep -qE "^${_entry}/?$" "$_GITIGNORE" 2>/dev/null; then | ||
| 133 | - printf "\n%s/\n" "$_entry" >> "$_GITIGNORE" 2>/dev/null || true | ||
| 134 | - echo "[OAT] Added ${_entry}/ to .gitignore" | ||
| 135 | - fi | ||
| 136 | -done | ||
| 137 | 256 | ||
| 138 | # --------------------------------------------------------------------------- | 257 | # --------------------------------------------------------------------------- |
| 139 | # 5. Build oat command — use OAT.xml if present in repo root | 258 | # 5. Build oat command — use OAT.xml if present in repo root |
| @@ -170,7 +289,7 @@ fi | |||
| 170 | # Only: Invalid File Type + License Header Invalid (no copyright) | 289 | # Only: Invalid File Type + License Header Invalid (no copyright) |
| 171 | # --------------------------------------------------------------------------- | 290 | # --------------------------------------------------------------------------- |
| 172 | REPORT_FILE="$OAT_REPORT_DIR/PlainReport_${REPO_NAME}.txt" | 291 | REPORT_FILE="$OAT_REPORT_DIR/PlainReport_${REPO_NAME}.txt" |
| 173 | -RESULT_FILE="$OAT_REPORT_DIR/result.txt" | 292 | +RESULT_FILE="$OAT_RESULT_DIR/result.txt" |
| 174 | 293 | ||
| 175 | # Section headers used as stop-boundaries when extracting sections | 294 | # Section headers used as stop-boundaries when extracting sections |
| 176 | _ALL_HEADERS="Invalid File Type Total Count:|License Not Compatible Total Count:|License Header Invalid Total Count:|Copyright Header Invalid Total Count:|No License File Total Count:|No Readme.OpenSource Total Count:|No Readme Total Count:|Import Invalid Total Count:|Redundant License File Total Count:|Third Party Software Info Total Count:" | 295 | _ALL_HEADERS="Invalid File Type Total Count:|License Not Compatible Total Count:|License Header Invalid Total Count:|Copyright Header Invalid Total Count:|No License File Total Count:|No Readme.OpenSource Total Count:|No Readme Total Count:|Import Invalid Total Count:|Redundant License File Total Count:|Third Party Software Info Total Count:" |
| @@ -201,17 +320,29 @@ _extract_section() { | |||
| 201 | 320 | ||
| 202 | if [ ! -f "$REPORT_FILE" ]; then | 321 | if [ ! -f "$REPORT_FILE" ]; then |
| 203 | if [ "$_OAT_RC" -eq 0 ]; then | 322 | if [ "$_OAT_RC" -eq 0 ]; then |
| 323 | + # oat exited cleanly with no report: all staged files were filtered out | ||
| 204 | echo "[OAT] [OK] All checks passed ($FILE_COUNT file(s) checked)." | 324 | echo "[OAT] [OK] All checks passed ($FILE_COUNT file(s) checked)." |
| 325 | + [ -n "$_DONE_MARKER" ] && touch "$_DONE_MARKER" 2>/dev/null || true | ||
| 326 | + rm -rf "$OAT_REPORT_DIR" | ||
| 205 | exit 0 | 327 | exit 0 |
| 206 | else | 328 | else |
| 207 | - echo "[OAT] [WARNING] Report not found: $REPORT_FILE" | 329 | + # oat returned exit code 1 but produced no report — possible disk issue |
| 330 | + # or oat internal error. Do not silently pass; block the commit. | ||
| 331 | + echo "" | ||
| 332 | + echo "[OAT] [ERROR] oat exited with code $_OAT_RC but no report was generated." | ||
| 333 | + echo "[OAT] This may indicate a disk error or an oat internal bug." | ||
| 334 | + echo "[OAT] To investigate, run manually:" | ||
| 335 | + echo " $_OAT_CMD" | ||
| 336 | + echo "[OAT] Blocking commit to prevent silent compliance bypass." | ||
| 337 | + echo "" | ||
| 338 | + rm -rf "$OAT_REPORT_DIR" | ||
| 208 | exit 1 | 339 | exit 1 |
| 209 | fi | 340 | fi |
| 210 | fi | 341 | fi |
| 211 | 342 | ||
| 212 | -# Parse counts | 343 | +# Parse counts — use || true to prevent set -e from triggering if grep finds no match |
| 213 | -_INVALID_TYPE=$(grep "^Invalid File Type Total Count:" "$REPORT_FILE" | grep -oE '[0-9]+' | head -1) | 344 | +_INVALID_TYPE=$(grep "^Invalid File Type Total Count:" "$REPORT_FILE" | grep -oE '[0-9]+' | head -1 || true) |
| 214 | -_LICENSE_INVALID=$(grep "^License Header Invalid Total Count:" "$REPORT_FILE" | grep -oE '[0-9]+' | head -1) | 345 | +_LICENSE_INVALID=$(grep "^License Header Invalid Total Count:" "$REPORT_FILE" | grep -oE '[0-9]+' | head -1 || true) |
| 215 | _INVALID_TYPE=${_INVALID_TYPE:-0} | 346 | _INVALID_TYPE=${_INVALID_TYPE:-0} |
| 216 | _LICENSE_INVALID=${_LICENSE_INVALID:-0} | 347 | _LICENSE_INVALID=${_LICENSE_INVALID:-0} |
| 217 | 348 | ||
| @@ -240,11 +371,8 @@ _SECTION_LIC=$(_extract_section "$REPORT_FILE" "License Header Invalid Total Cou | |||
| 240 | echo "===================================" | 371 | echo "===================================" |
| 241 | } > "$RESULT_FILE" | 372 | } > "$RESULT_FILE" |
| 242 | 373 | ||
| 243 | -# Clean up full plain report (keep only result.txt) | ||
| 244 | -rm -f "$REPORT_FILE" | ||
| 245 | - | ||
| 246 | # --------------------------------------------------------------------------- | 374 | # --------------------------------------------------------------------------- |
| 247 | -# 8. Block commit if issues found | 375 | +# 8. Block commit if issues found; always clean up temp dir |
| 248 | # --------------------------------------------------------------------------- | 376 | # --------------------------------------------------------------------------- |
| 249 | TOTAL_ISSUES=$(( _INVALID_TYPE + _LICENSE_INVALID )) | 377 | TOTAL_ISSUES=$(( _INVALID_TYPE + _LICENSE_INVALID )) |
| 250 | 378 | ||
| @@ -258,12 +386,15 @@ if [ "$TOTAL_ISSUES" -gt 0 ]; then | |||
| 258 | echo " - Invalid File Type: $_INVALID_TYPE" | 386 | echo " - Invalid File Type: $_INVALID_TYPE" |
| 259 | echo " - License Header Invalid: $_LICENSE_INVALID" | 387 | echo " - License Header Invalid: $_LICENSE_INVALID" |
| 260 | echo "" | 388 | echo "" |
| 261 | - echo "[OAT] Details:" | 389 | + echo "[OAT] Details (also saved to: $RESULT_FILE):" |
| 262 | - echo " cat $RESULT_FILE" | 390 | + echo "---" |
| 391 | + cat "$RESULT_FILE" | ||
| 392 | + echo "---" | ||
| 263 | echo "" | 393 | echo "" |
| 264 | echo "Fix the issues and recommit, or skip with:" | 394 | echo "Fix the issues and recommit, or skip with:" |
| 265 | echo " git commit --no-verify" | 395 | echo " git commit --no-verify" |
| 266 | echo "" | 396 | echo "" |
| 397 | + rm -rf "$OAT_REPORT_DIR" | ||
| 267 | exit 1 | 398 | exit 1 |
| 268 | fi | 399 | fi |
| 269 | 400 | ||
| @@ -271,4 +402,10 @@ echo "" | |||
| 271 | echo "[OAT] [OK] All checks passed ($FILE_COUNT file(s) checked)." | 402 | echo "[OAT] [OK] All checks passed ($FILE_COUNT file(s) checked)." |
| 272 | echo "[OAT] Summary: cat $RESULT_FILE" | 403 | echo "[OAT] Summary: cat $RESULT_FILE" |
| 273 | echo "" | 404 | echo "" |
| 405 | +# Mark scan as done for CI range mode (prevents redundant re-runs on same PR head) | ||
| 406 | +if [ -n "$_DONE_MARKER" ]; then | ||
| 407 | + touch "$_DONE_MARKER" 2>/dev/null || true | ||
| 408 | + echo "[OAT] Done-marker created: $_DONE_MARKER" | ||
| 409 | +fi | ||
| 410 | +rm -rf "$OAT_REPORT_DIR" | ||
| 274 | exit 0 | 411 | exit 0 |
| @@ -4,8 +4,8 @@ | |||
| 4 | * CANN Open Software License Agreement Version 2.0 (the "License"). | 4 | * CANN Open Software License Agreement Version 2.0 (the "License"). |
| 5 | * Please refer to the License for details. You may not use this file except in compliance with the License. | 5 | * Please refer to the License for details. You may not use this file except in compliance with the License. |
| 6 | * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | 6 | * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, |
| 7 | - * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | 7 | + * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. |
| 8 | - * See LICENSE in the root of the software repository for the full text of the License. | 8 | + * See LICENSE in the root of the software repository for the full text of the License. |
| 9 | */ | 9 | */ |
| 10 | 10 | ||
| 11 | #include "indv_base.h" | 11 | #include "indv_base.h" |
| @@ -308,3 +308,28 @@ aclError aclrtDestroyEvent(aclrtEvent event) | |||
| 308 | } | 308 | } |
| 309 | return ACL_SUCCESS; | 309 | return ACL_SUCCESS; |
| 310 | } | 310 | } |
| 311 | + | ||
| 312 | +EXTERN_C | ||
| 313 | +aclError aclrtCtxGetCurrentDefaultStream(aclrtStream* stream) | ||
| 314 | +{ | ||
| 315 | + *stream = (void*)(new uint8_t[1]); | ||
| 316 | + return ACL_SUCCESS; | ||
| 317 | +} | ||
| 318 | + | ||
| 319 | +EXTERN_C | ||
| 320 | +aclError aclrtDestroyStream(aclrtStream stream) | ||
| 321 | +{ | ||
| 322 | + if (stream != nullptr) { | ||
| 323 | + delete[] static_cast<uint8_t*>(stream); | ||
| 324 | + } | ||
| 325 | + return ACL_SUCCESS; | ||
| 326 | +} | ||
| 327 | + | ||
| 328 | +EXTERN_C | ||
| 329 | +aclError aclrtGetResInCurrentThread(aclrtDevResLimitType type, uint32_t* value) | ||
| 330 | +{ | ||
| 331 | + if (value != nullptr) { | ||
| 332 | + *value = 24U; | ||
| 333 | + } | ||
| 334 | + return ACL_SUCCESS; | ||
| 335 | +} | ||