已关闭
[Bug-Report|缺陷反馈]: [工具检测] A5算子moe_compute_expert_tokens核内的流水竞争报错 #4060
s_wei创建于  7月31日关闭于  8月4日
s_wei
s_wei
7月31日 创建

Thanks for sending an issue! Please fill in the following template to help quickly solve your problem.

Describe the current behavior / 问题描述 (Mandatory / 必填)

A5算子moe_compute_expert_tokens核内的流水竞争报错

现象
====== ERROR: Potential RAW hazard detected at UB in MoeComputeExpertTokens_d1c627adc45619675efeff94a5330a80_1001: ====== PIPE_S Write at RAW()+0x20 in block 0 (aiv) on device 0 at pc current 0x4ae8 (serialNo:83) ====== #0 /data00/huawei/shenwei/sw_test/ops-transformer/build/binary/ascend950/src/moe_compute_expert_tokens/op_kernel/moe_compute_expert_tokens_int32_ss.h:231:9 ====== #1 /data00/huawei/shenwei/sw_test/ops-transformer/build/binary/ascend950/src/moe_compute_expert_tokens/op_kernel/moe_compute_expert_tokens_int32_ss.h:270:5 ====== #2 /data00/huawei/shenwei/sw_test/ops-transformer/build/binary/ascend950/src/moe_compute_expert_tokens/op_kernel/moe_compute_expert_tokens_int32_ss.h:299:9 ====== #3 /data00/huawei/shenwei/sw_test/ops-transformer/build/binary/ascend950/src/moe_compute_expert_tokens/op_kernel/moe_compute_expert_tokens.cpp:35:12 ====== #4 /data00/huawei/shenwei/sw_test/ops-transformer/build/binary/ascend950/gen/kernel_meta_MoeComputeExpertTokens_d1c627adc45619675efeff94a5330a80/kernel_meta/MoeComputeExpertTokens_d1c627adc45619675efeff94a5330a80_kernel.cpp:27:5 ====== #5 /data00/huawei/shenwei/sw_test/ops-transformer/build/binary/ascend950/gen/kernel_meta_MoeComputeExpertTokens_d1c627adc45619675efeff94a5330a80/kernel_meta/MoeComputeExpertTokens_d1c627adc45619675efeff94a5330a80_kernel.cpp:32:5 ====== PIPE_MTE3 Read at RAW()+0x20 in block 0 (aiv) on device 0 at pc current 0x4858 (serialNo:99) ====== #0 /data00/huawei/shenwei/sw_test/ops-transformer/build/binary/ascend950/src/moe_compute_expert_tokens/op_kernel/moe_compute_expert_tokens_int32_ss.h:289:5 ====== #1 /data00/huawei/shenwei/sw_test/ops-transformer/build/binary/ascend950/src/moe_compute_expert_tokens/op_kernel/moe_compute_expert_tokens_int32_ss.h:300:9 ====== #2 /data00/huawei/shenwei/sw_test/ops-transformer/build/binary/ascend950/src/moe_compute_expert_tokens/op_kernel/moe_compute_expert_tokens.cpp:35:12 ====== #3 /data00/huawei/shenwei/sw_test/ops-transformer/build/binary/ascend950/gen/kernel_meta_MoeComputeExpertTokens_d1c627adc45619675efeff94a5330a80/kernel_meta/MoeComputeExpertTokens_d1c627adc45619675efeff94a5330a80_kernel.cpp:27:5 ====== #4 /data00/huawei/shenwei/sw_test/ops-transformer/build/binary/ascend950/gen/kernel_meta_MoeComputeExpertTokens_d1c627adc45619675efeff94a5330a80/kernel_meta/MoeComputeExpertTokens_d1c627adc45619675efeff94a5330a80_kernel.cpp:32:5

Environment / 环境信息 (Mandatory / 必填)

昇腾硬件型号:950PR
image.png
软件环境信息:CANN 9.1.0
image.png

Steps to reproduce the issue / 重现步骤 (Mandatory / 必填)

moe_compute_expert_tokens
复现方式:
bash mssanitizer_test/scripts/test_single_op.sh --op moe_compute_expert_tokens --kernel MoeComputeExpertTokens
这个命令会先编译算子,然后单独跑算子,再用mssanitizer拉起检测算子

Describe the expected behavior / 预期结果 (Mandatory / 必填)

预期正常执行,无error

初步分析结论:
核内的流水竞争,
Compute的下图函数里对UB做了SetValue这种Pipe-S的操作
image.png

CopyOut里对UB做搬运GM的操作
image.png

虽然output是从队列里拿出来的,但是这个VECOUT类型的队列,是没有插入S-MTE3的同步,默认只有V-MTE3的同步。ascendc里的 kernel_event.h
image.png

Special notes for this issue/备注 (Optional / 选填)

likedislike
weihao18成员
7月31日 评论:

/assign @cpy_123456

likedislike
CANN-robotCANN-robot成员
7月31日 将 cpy_123456 设为负责人
cpy_123456成员
7月31日 评论:

已安排相关人员跟进@wuxiyuan

likedislike
wuxiyuan成员
8月3日 评论:

@s_wei 麻烦提供一下执行失败的用例和检测脚本mssanitizer_test/scripts/test_single_op.sh

likedislike
s_wei
s_wei
8月3日 评论:

@s_wei 麻烦提供一下执行失败的用例和检测脚本mssanitizer_test/scripts/test_single_op.sh

@wuxiyuan
#!/bin/bash

set -e

BASE_DIR=$(dirname $(dirname $(readlink -f ${BASH_SOURCE[0]})))
BUILD_SH="${BASE_DIR}/../build.sh"
OUTPUT_DIR="${BASE_DIR}/single_op"

mkdir -p ${OUTPUT_DIR}

show_usage() {
echo "Usage: $0 --op <op_name> [--kernel <kernel_name>] [--soc <soc_version>] [options]"
echo ""
echo "Required:"
echo " --op Operator name"
echo ""
echo "Options:"
echo " --kernel Kernel name for mssanitizer (default: derived from op name)"
echo " --soc SoC version (default: ascend950)"
echo " --tools Sanitizer tools to run (default: memcheck,racecheck,synccheck,initcheck)"
echo " Available: memcheck, racecheck, synccheck, initcheck"
echo " --skip-build Skip operator compilation (assumes already compiled)"
echo " --skip-install Skip package installation (assumes already installed)"
echo " --skip-test-compile Skip test case compilation (assumes already compiled)"
echo " --help Show this help message"
echo ""
echo "Examples:"
echo " # Full test (compile + install + test + mssanitizer)"
echo " $0 --op fused_infer_attention_score --kernel Attention"
echo ""
echo " # Only run mssanitizer (fastest, assumes everything is ready)"
echo " $0 --op fused_infer_attention_score --kernel Attention --skip-build --skip-install --skip-test-compile"
echo ""
echo " # Use only specific tools"
echo " $0 --op fused_infer_attention_score --kernel Attention --tools memcheck,racecheck"
exit 1
}

OP_NAME=""
KERNEL_NAME=""
SOC="ascend950"
TOOLS="memcheck,racecheck,synccheck"
SKIP_BUILD="false"
SKIP_INSTALL="false"
SKIP_TEST_COMPILE="false"

while [[ $# -gt 0 ]]; do
case "$1" in
--op)
OP_NAME="$2"
shift 2
;;
--kernel)
KERNEL_NAME="$2"
shift 2
;;
--soc)
SOC="$2"
shift 2
;;
--tools)
TOOLS="$2"
shift 2
;;
--skip-build)
SKIP_BUILD="true"
shift
;;
--skip-install)
SKIP_INSTALL="true"
shift
;;
--skip-test-compile)
SKIP_TEST_COMPILE="true"
shift
;;
--help)
show_usage
;;
*)
echo "Unknown option: $1"
show_usage
;;
esac
done

if [[ -z "${OP_NAME}" ]]; then
echo "Error: --op is required"
show_usage
fi

if [[ -z "${KERNEL_NAME}" ]]; then
case "${OP_NAME}" in
attention)
KERNEL_NAME="Attention"
;;
moe)
KERNEL_NAME="Moe"
;;
ffn)
KERNEL_NAME="Ffn"
;;
matmul)
KERNEL_NAME="Matmul"
;;
grouped)
KERNEL_NAME="Grouped"
;;
rotary)
KERNEL_NAME="Rotary"
;;
*)
KERNEL_NAME="${OP_NAME}"
;;
esac
fi

BUILD_LOG="${OUTPUT_DIR}/build_${OP_NAME}.log"
TEST_LOG="${OUTPUT_DIR}/test_${OP_NAME}.log"
MSSANITIZER_LOG="${OUTPUT_DIR}/mssanitizer_${OP_NAME}.log"
RESULT_FILE="${OUTPUT_DIR}/result_${OP_NAME}.txt"

TOOLS_OPTS=""
IFS=',' read -ra TOOL_LIST <<< "TOOLS"fortoolin"{TOOLS}" for tool in "{TOOL_LIST[@]}"; do
TOOLS_OPTS="${TOOLS_OPTS} --tool=${tool}"
done

echo ""
echo "========================================"
echo " Single Operator Test Script"
echo "========================================"
echo "Operator: ${OP_NAME}"
echo "Kernel: ${KERNEL_NAME}"
echo "SoC: ${SOC}"
echo "Tools: ${TOOLS}"
echo "Skip build: ${SKIP_BUILD}"
echo "Skip install: ${SKIP_INSTALL}"
echo "Skip test compile: ${SKIP_TEST_COMPILE}"
echo ""
echo "Output directory: ${OUTPUT_DIR}"
echo "========================================"
echo ""

if [[ "SKIPBUILD"!="true"]];thenecho"[Step1/4]Compilingoperatorwithsanitizer..."echo"−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−"starttime={SKIP_BUILD}" != "true" ]]; then echo "[Step 1/4] Compiling operator with sanitizer..." echo "----------------------------------------" start_time=(date +%s)
bash ${BUILD_SH} --pkg --ops=${OP_NAME} --soc=${SOC} --op_debug_config "sanitizer" -j32 2>&1 | tee ${BUILD_LOG}
end_time=$(date +%s)
echo "Compilation time: $((end_time - start_time)) seconds"

if [[ $? -ne 0 ]]; then
    echo "[ERROR] Compilation failed!"
    echo "FAIL" > &#36;{RESULT_FILE}
    exit 1
fi

else
echo "[Step 1/4] Skipping compilation (already compiled)"
fi

if [[ "${SKIP_INSTALL}" != "true" ]]; then
echo ""
echo "[Step 2/4] Installing package..."
echo "----------------------------------------"
start_time=$(date +%s)
cd BASEDIR/../buildoutRUNFILE={BASE_DIR}/../build_out RUN_FILE=(ls cann--ops-transformer.run 2>/dev/null | head -1)
if [[ -z "RUNFILE"]];thenRUNFILE={RUN_FILE}" ]]; then RUN_FILE=(ls cann-ops-transformer-*.run 2>/dev/null | head -1)
fi
if [[ -z "${RUN_FILE}" ]]; then
echo "[ERROR] Run file not found!"
echo "Available files:"
ls -la *.run 2>/dev/null || echo "No .run files found"
echo "FAIL" > ${RESULT_FILE}
exit 1
fi
echo "Found run file: ${RUN_FILE}"
bash ${RUN_FILE} 2>&1 | tee -a BUILDLOGcd−>/dev/nullendtime={BUILD_LOG} cd - > /dev/null end_time=(date +%s)
echo "Installation time: $((end_time - start_time)) seconds"
else
echo ""
echo "[Step 2/4] Skipping installation (already installed)"
fi

if [[ "SKIPTESTCOMPILE"!="true"]];thenecho""echo"[Step3/4]Compilingtestcase..."echo"−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−"starttime={SKIP_TEST_COMPILE}" != "true" ]]; then echo "" echo "[Step 3/4] Compiling test case..." echo "----------------------------------------" start_time=(date +%s)
bash ${BUILD_SH} --run_example ${OP_NAME} eager --soc=${SOC} 2>&1 | tee ${TEST_LOG}
end_time=$(date +%s)
echo "Test compile time: $((end_time - start_time)) seconds"
else
echo ""
echo "[Step 3/4] Skipping test compilation (already compiled)"
fi

TEST_BIN="build/test_aclnn_${OP_NAME}"
if [[ ! -f "${TEST_BIN}" ]]; then
echo "[ERROR] Test binary not found: ${TEST_BIN}"
echo "FAIL" > ${RESULT_FILE}
exit 1
fi

echo ""
echo "[Step 4/4] Running mssanitizer..."
echo "----------------------------------------"
echo "Command: mssanitizer ${TOOLS_OPTS} --log-level=error --kernel-name=${KERNEL_NAME} -- ${TEST_BIN}"
echo ""

start_time=(date +%s) mssanitizer &#36;{TOOLS_OPTS} \ --log-level=error \ --kernel-name=&#36;{KERNEL_NAME} \ -- &#36;{TEST_BIN} > &#36;{MSSANITIZER_LOG} 2>&1 end_time=(date +%s)
echo "Mssanitizer time: $((end_time - start_time)) seconds"

MSSANITIZER_RESULT=$?

echo ""
echo "========================================"
echo "Test Summary"
echo "========================================"
echo "Operator: ${OP_NAME}"
echo "Kernel: ${KERNEL_NAME}"
echo "SoC: ${SOC}"
echo "Tools: ${TOOLS}"
echo ""
echo "Build log: ${BUILD_LOG}"
echo "Test log: ${TEST_LOG}"
echo "Mssanitizer log: ${MSSANITIZER_LOG}"
echo ""

ERROR_COUNT=$(grep -c "ERROR:" MSSANITIZERLOG2>/dev/null∣∣echo0)WARNINGCOUNT={MSSANITIZER_LOG} 2>/dev/null || echo 0) WARNING_COUNT=(grep -c "WARNING:" ${MSSANITIZER_LOG} 2>/dev/null || echo 0)

echo "Mssanitizer errors: ${ERROR_COUNT}"
echo "Mssanitizer warnings: ${WARNING_COUNT}"
echo ""

if [[ ${ERROR_COUNT} -eq 0 ]]; then
echo "[SUCCESS] All tests passed!"
echo "SUCCESS" > ${RESULT_FILE}
else
echo "[FAIL] Found ${ERROR_COUNT} errors!"
echo "FAIL" > ${RESULT_FILE}
exit 1
fi

likedislike
CANN-robotCANN-robot成员
8月4日 关闭了 issue
CANN-robotCANN-robot成员
8月4日 添加了label:resolved
s_weis_wei
8月19日 修改标题为 “[Bug-Report|缺陷反馈]: [工具检测] A5算子moe_compute_expert_tokens核内的流水竞争报错”,原标题为“[Bug-Report|缺陷反馈]: A5算子moe_compute_expert_tokens核内的流水竞争报错”