4.5.3. CPU-BPU-DDR 压力测试
4.5.3.1. 测试原理
CPU-BPU-DDR 压力
1. CPU DDR 压力
测试
目标 :使用stressapptest工具模拟 高 负载 环境,进行 大量 计算、数据处理 和 内存 操作,测试 系统 在 多线程 并发 任务 下 的 性能。 测试
目的 :验证 CPU 在长时间 高 负载 下 的 稳定性 与 性能,确保 CPU 和 DDR 能 在 高负荷 运行 时 维持 正常 工作,避免 崩溃、过热 或 性能 下降 等 问题。 stressapptest CPU 压测
原理: CPU 压测主要 通过 多线程 并发 执行 一些 计算 密集型 的 任务 来 实现,这些 任务 包括:计算 密集型 任务、多线程 并行执行 等。 线程
创建: stressapptest通过pthread_create()来创建 多个 线程,每个 线程 执行 计算 任务,线程 的 数量 通常 由 用户 通过 -C 参数 指定。
for (int i = 0; i < num_threads; i++) { pthread_create(&threads[i], NULL, cpu_stress_function, (void*)i); }
计算
密集型 任务:每个 线程 会 执行 一些 计算 密集型 的 操作,例如 浮点数 计算、内存 读写 等,这会 消耗 CPU 资源。
void* cpu_stress_function(void* arg) { while (true) { // Perform some CPU-intensive calculations double a = 3.14159265358979; for (int i = 0; i < 1000000; i++) { a = a * a * 3.14159; // Simulate a calculation } } return NULL; }
线程
同步 和 管理:通过 pthread_join()等函数 确保 线程 的 正确 执行 和 同步。
stressapptest DDR 压测
原理: DDR 内存 的压力 测试 主 涉及 大量 的 内存 分配、访问 和 数据交换,通过 高 内存 使用、频繁 的 内存 读写操作、以及 内存 带宽 的 消耗 来 进行。 内存
分配: 在 内存 压力 测试 中, stressapptest 会 根据 -M 参数(例如 -M 8192 )来 分配 指定 大小 的 内存。
void* allocate_memory(size_t size) { void* ptr = malloc(size); // 分配指定大小的内存 if (ptr == NULL) { perror("Memory allocation failed"); exit(1); } return ptr; }
内存
读写操作 : stressapptest 会 在 分配 的 内存 区域 中 进行 大量 的 读取 和 写入,以下 是 一个 简单 的 内存 读写操作 的 例子:
void stress_memory(void* ptr, size_t size) { volatile char* data = (volatile char*)ptr; for (size_t i = 0; i < size; i++) { data[i] = (char)(i % 256); // 写入数据 char temp = data[i]; // 读取数据 } }
线程
访问 内存: stressapptest 使用 多线程 来 增加 内存 压力。多个 线程 并发 地 对 内存 进行 访问,模拟 高 负载 下 内存 的 使用 情况。
命令
分析:运行 压测 脚本 后,运行 如下 命令: stressapptest -s "$stime" -M "$memory_size" -f /tmp/sat.io1 -f /tmp/sat.io2 -i "$io_threads" -m 8 -C 2 -W-s "$stime": 这个参数 指定 了 测试 的 持续时间。 -M "$memory_size”: 这个参数 指定 了 内存 使用量,在 源码 中,-M 参数 用于 控制 内存 的 分配 大小。 -f /tmp/sat.io1 -f /tmp/sat.io2: -f 参数用于 指定 文件 用于 I/O 测试。 -i "$io_threads": 该参数 指定 了 用于 I/O 操作 的 线程 数。 -m 8: 这个参数 控制 内存 压力 的 强度。 -C 2: 这个参数 指定 了 进行 压力 测试 时 使用 的 CPU 核心 数。 -W: 这个参数 启用 了 写 操作,意味着 不仅 进行 内存 的 读取,还会 进行 写入 操作。
2. BPU 压力
测试
目标: 通过运行 run-portion.sh脚本,并利用 tc_hbdk3工具调整 -b ( BPU 核心 )和 -p( BPU 负载 比例 )参数,模拟 不同 的 BPU 负载 场景,确保 BPU 在 高 负载 下 依然 能够 稳定 工作 并 达到 预期 性能。 测试
目的 :确保 BPU 在执行 计算 任务 时,能够 输出 与 预期 相符 的 正确 结果,检查 BPU 长时间 高 负载 运行 下 仍 能 稳定 工作,不 出现 崩溃 或 错误。 tc_hbdk3 BPU 压测
原理: 通过加载 包含 大量 计算 任务 的 模型,利用 BPU 进行 加速 计算,从而 实现 对 BPU 的 压力 测试。 命令
分析: 运行压测 脚本 后,运行 如下 命令: tc_hbdk3 -t $1 -b $2 -f $HBM_FILE -i $SRC_FILE -n $MODEL_NAME -o $OUTPUT_0_0,$OUTPUT_0_1,$OUTPUT_1_0,$OUTPUT_1_1 -g 0 -c 0-t $1 : 传递 $portion 参数
的 值,可以 灵活 地 控制 压力 测试 的 强度,并且 可以 根据 不同 的 测试 需求 来 选择 合适 的 负载 水平。 -b $2 : 选择
使用 的 BPU 核心 数。 -f $HBM_FILE:-f 参数
指定 了 HBM 文件。 -i $SRC_FILE: 该
文件 包含 模型 推理 或 训练 时 使用 的 输入 数据,程序 会 从中 读取数据 并 传递 给 BPU 进行 计算。 -n $MODEL_NAME: -n 参数
指定 了 要 加载 和 运行 的 模型 名称 -o $OUTPUT_0_0 : 这些
输出 文件 用于 保存 计算结果 或 日志 数据。
4.5.3.2. 准备工作
1. 开始
2. 确认
01_cpu_bpu_ddr/
├── models
│ └── HBDK3_MODEL_2K
│ ├── input_0_feature_1x1088x2048x3_ddr_native.bin
│ ├── run.sh
│ └── x5
│ └── gen_I2004_ForTest2k_1x1088x2048x3.hbm
├── scripts
│ ├── run-portion.sh
│ ├── stop_test.sh
│ ├── stress_test.sh
│ └── stressapptest
└── tc_hbdk3
4.5.3.3. 测试方法
压测
./stress_test.sh -h
Usage: ./stress_test.sh [options]
Options:
-t <time> Set the test duration (e.g., 2h for hours, 30m for minutes; default: 48h).
-m <size> Set the memory size for stress test in MB (default: 100).
-i <threads> Set the I/O threads for stress test (default: 4).
-b <bpu_core> Specify the BPU core to use (default: 0).
-p <portion> Set the BPU portion value (default: 100).
-o <directory> Set the output directory for logs (default: ../../log).
-h, --help Show this help message and exit.
Example:
./stress_test.sh -t 24h -m 200 -i 8 -p 80
各
t <time>: 用于设置 压力 测试 的 持续时间 , 时间 格式 可以 是 小时(如 2h)或 分钟(如 30m),默认值 为 48 小时。 m <size>: 用于设置 压力 测试 中 内存 的 大小(单位: MB),默认值 为 100MB。 i <threads>: 用于设置 I/O 线程 的 数量,默认值 为 4 。 b <bpu_core>: 用于指定 BPU(基于 处理单元)核心 的 编号,默认值 为 0 。 p <portion>: 用于设置 BPU 负载 的 比例,默认值 为 100 (即满 负载)。 o <directory>: 用于设置 日志 输出 的 目录,默认值 为 ../../log。 h, --help: 显示帮助 信息 并 退出 脚本。
示例:
例如,使用./stress_test.sh -t 24h -m 200 -i 8 -p 80 来
确保
cd /app/platform_samples/chip_base_test/01_cpu_bpu_ddr/scripts
./stress_test.sh
压测hrut_somstatus 命令
Running stress test with the following configuration:
Stress Time: 48h hours (2880 seconds)
Memory Size: 100 MB
I/O Threads: 4
BPU Core: 0
BPU Portion: 100%
Output directory: /app/platform_samples/chip_base_test/log
Starting CPU stress test...
nohup: redirecting stderr to stdout
Starting BPU stress test...
=====================1=====================
temperature-->
DDR : 84.0 (C)
83087
BPU : 82.9 (C)
CPU : 83.7 (C)
cpu frequency-->
min(M) cur(M) max(M)
cpu0: 300 1500 1500
cpu1: 300 1500 1500
cpu2: 300 1500 1500
cpu3: 300 1500 1500
cpu4: 300 1500 1500
cpu5: 300 1500 1500
cpu6: 300 1500 1500
cpu7: 300 1500 1500
bpu status information---->
min(M) cur(M) max(M) ratio
bpu0: 500 1000 1000 98
ddr frequency information---->
min(M) cur(M) max(M)
ddr: 266 4266 4266
GPU gc8000 frequency information---->
min(M) cur(M) max(M)
gc8000: 200 1000 1000
hrut_somstatus 命令
temperature:代表当前 DDR、 BPU、 CPU 的 温度。 cpu frequency:分别代表 CPU 0-7 的 最小 运行 频率、当前 运行 频率 和 最大 运行 频率( MHZ)。 bpu status information:代表 BPU 的最小、当前 和 最大 运行 频率,其中 ratio 代表 BPU 当前 占用率。
执行 top 命令CPU 的

其中
%CpuX : user/system idle [ 进度条 ]
%CpuX:表示 CPU 核心编号,例如 %Cpu0 表示 第 0 核心。 user:该核心 的 CPU 时间 中,有 多少 比例 是 用于 执行 用户 空间 的 进程(如 应用程序、进程 等)。 system:该核心 的 CPU 时间 中,有 多少 比例 是 用于 执行 内核 空间 的 进程(内核 操作)。 idle:该核心 有 多少 时间 是 空闲 的, cpu0 当前 空闲 为 1 。 进度条:显示该 核心 的 负载 情况。每个 进度条 的 长度 反映 了 CPU 的 负载 强度。
例如
4.5.3.4. 测试指标
测试程序/app/platform_samples/chip_base_test/log 目录bpu-stressX.log 和 cpu-stressX.log 两份
能
稳定 运行 48 小时,不 出现 重启 或 挂 死 的 情况。 使用
以下 命令 检查 日志 文件 中 是否 存在 fail、error、timeout等异常 打印。
cd "/app/platform_samples/chip_base_test/log/" && grep -iE 'error|fail|timeout' bpu-stress*.log cpu-stress*.log
执行
TOP命令查看 CPU、 BPU 占 比 情况,正常 状态 应 稳定 保持 在 98-100% 区间。
测试结果
输入
cd "/app/platform_samples/chip_base_test/log/" && grep -iE 'error|fail|timeout' bpu-stress*.log cpu-stress*.log
显示
cpu-stress1.log:1970/01/01-02:11:11(UTC) Stats: Completed: 80944.00M in 14.24s 5685.54MB/s, with 0 hardware incidents, 0 errors
cpu-stress1.log:1970/01/01-02:11:11(UTC) Status: PASS - please verify no corrected errors
cpu-stress2.log:1970/01/01-00:10:29(UTC) Stats: Completed: 3300956.00M in 589.29s 5601.62MB/s, with 0 hardware incidents, 0 errors
cpu-stress2.log:1970/01/01-00:10:29(UTC) Status: PASS - please verify no corrected errors
cpu-stress3.log:1970/01/01-00:34:09(UTC) Stats: Completed: 236090.00M in 44.79s 5270.69MB/s, with 0 hardware incidents, 0 errors
cpu-stress3.log:1970/01/01-00:34:09(UTC) Status: PASS - please verify no corrected errors
打印信息