4.5.11. DDR 带宽测试
4.5.11.1. 测试原理
DDR( Double Data Rate)内存
1. Copy(拷贝)操作:
for (j=0; j<STREAM_ARRAY_SIZE; j++)
c[j] = a[j];
这个
操作 将 数组 a[] 的 数据 复制到 数组 c[]。它 只 涉及 内存 的 读取 和 写入,因此 它 测量 的 是 单纯 的 内存 带宽。
2. Scale(缩放)操作:
for (j=0; j<STREAM_ARRAY_SIZE; j++)
b[j] = scalar * c[j];
这个
操作 将 数组 c[] 的 每个 元素 乘以 一个 常数 scalar,然后 将 结果 存储 到 数组 b[] 中。这一 操作 通过 读取 c[] 和 写入 b[] 来 测量 带宽。
3. Add(加法)操作:
for (j=0; j<STREAM_ARRAY_SIZE; j++)
c[j] = a[j] + b[j];
该
操作 将 数组 a[] 和 b[] 中 的 对应 元素 相加,并 将 结果 存储 到 数组 c[] 中。这是 一种 读取 两个 数组 并 写入 到 另 一个 数组 的 操作。
4. Triad(三元组)操作:
for (j=0; j<STREAM_ARRAY_SIZE; j++)
a[j] = b[j] + scalar * c[j];
这是
一个 更 复杂 的 操作,它 将 数组 b[] 中 的 元素 与 数组 c[] 中 的 元素 按照 常数 scalar 进行 三元组 加法,并 将 结果 存储 到 数组 a[] 中。
4.5.11.2. 准备工作
1. 确认 DDR 类型hrut_somstatus 查看 DDR 状态
root@buildroot:/# cat /sys/class/socinfo/ddr_type
lpddr4
root@buildroot:/# hrut_somstatus
=====================1=====================
temperature-->
DDR : 54.1 (C)
BPU : 53.4 (C)
CPU : 53.5 (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 0
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
手动
root@buildroot:/# echo userspace >/sys/class/devfreq/soc\:ddrc-freq/governor
root@buildroot:/# echo 4266000000 >/sys/class/devfreq/soc\:ddrc-freq/userspace/set_freq
2. 确认
root@buildroot:/# cd app/samples/platform_samples/chip_base_test/09_ddr_bandwidth
root@buildroot:/# cp /opt/arm-gnu-toolchain-11.3.rel1-x86_64-aarch64-none-linux-gnu/aarch64-none-linux-gnu/lib64/libgomp.a .
root@buildroot:/# /opt/arm-gnu-toolchain-11.3.rel1-x86_64-aarch64-none-linux-gnu/bin/aarch64-none-linux-gnu-gcc -O3 -fopenmp -DNTIMES=100 stream.c -L./ -lgomp -o stream
4.5.11.3. 测试方法
确保
cd /app/platform_samples/chip_base_test/09_ddr_bandwidth
./stream
等待 10 秒左右
-------------------------------------------------------------
STREAM version $Revision: 5.10 $
-------------------------------------------------------------
This system uses 8 bytes per array element.
-------------------------------------------------------------
Array size = 10000000 (elements), Offset = 0 (elements)
Memory per array = 76.3 MiB (= 0.1 GiB).
Total memory required = 228.9 MiB (= 0.2 GiB).
Each kernel will be executed 100 times.
The *best* time for each kernel (excluding the first iteration)
will be used to compute the reported bandwidth.
-------------------------------------------------------------
Number of Threads requested = 8
Number of Threads counted = 8
-------------------------------------------------------------
Your clock granularity/precision appears to be 1 microseconds.
Each test below will take on the order of 19433 microseconds.
(= 19433 clock ticks)
Increase the size of the arrays if this shows that
you are not getting at least 20 clock ticks per test.
-------------------------------------------------------------
WARNING -- The above is only a rough guideline.
For best results, please be sure you know the
precision of your system timer.
-------------------------------------------------------------
Function Best Rate MB/s Avg time Min time Max time
Copy: 9504.6 0.017268 0.016834 0.017501
Scale: 12742.9 0.012639 0.012556 0.012778
Add: 11429.7 0.021100 0.020998 0.021241
Triad: 11437.3 0.021061 0.020984 0.021313
-------------------------------------------------------------
Solution Validates: avg error less than 1.000000e-13 on all three arrays
-------------------------------------------------------------
关键
测试Copy,Scale,Add,Triad 四项

Copy (复制): 它
先 访问 一个 内存 单元 读出 其中 的 值,再 将 值 写入 到 另 一个 内存 单元。 测试
描述:在 Copy 测试 中,系统 将 一个 数组 的 内容 复制到 另 一个 数组,这是 内存 带宽 的 最 基本 测试,主要 考察 的 是 系统 在 执行 内存 到 内存 的 简单 数据 复制 时 的 性能。 带宽
结果: 9504.6 MB/s
Scale (乘法): 先
从 内存 单元 读出 其中 的 值,作 一个 乘法 运算,再 将 结果 写入 到 另 一个 内存 单元。 测试
描述: Scale 不仅 涉及 内存 带宽,还 需要 CPU 执行 计算 任务,因此 更能 体现 处理器 和 内存 之间 的 协作 性能。 带宽
结果: 12742.9 MB/s
Add (加法): 先
从 内存 单元 读出 两个 值,做 加法 运算,再 将 结果 写入 到 另 一个 内存 单元。 测试
描述: Add 测试 模拟 了 两个 数组 相加 并 将 结果 存储 到 第三个 数组 中,这 测试 了 CPU 和 内 存在 并行操作 时 的 带宽 需求。 带宽
结果: 11429.7 MB/
Triad (组合
操作): 将 Copy、 Scale、 Add 三种操作 组合 起来 进行 测。具体操作 方式 是:先 从 内存 单元 中读 两个 值 a、 b ,对 其 进行 乘加 混合 运算( a + 因子 * b ) ,将 运算 结果 写入 到 另 一个 内存 单元 测试
描述: Triad 不仅 涉及 两个 数组 相加,还 将 结果 与 另 一个 数组 进行 缩放,是 一个 同时 进行 计算、加法 和 内存 访问 的 复合 操作。 带宽
结果: 11437.3 MB/s
输出
结果 中 的 数值 的 含义: Best Rate MB/s(最佳
速率): 在操作 中 达到 的 最高 内存 传输速率,以兆 字节 / 秒( MB/s)为 单位。表示 峰值 性能。 Avg time(平均
时间): 每次操作 的 平均 时间,以 秒 为 单位,表示 性能 的 平均 延迟时间。 Min time(最小
时间): 操作的 最 短时间,以 秒 为 单位,表示 在 某 一次 操作 中 的 最佳 性能。 Max time(最大
时间): 操作的 最长 时间,以 秒 为 单位,表示 某 一次 复制 操作 中 的 最差 性能。
4.5.11.4. 测试指标
DDR 带宽
带宽 (MB/s) = 内存时钟频率 (MHz) * 2 * 总线宽度 (bit) / 8
x5 平台
带宽 (MB/s) = 4266 MHz * 4 Byte = 17064 MB/s
分数标准
实际 DDR 带宽
分数标准 = ddr_score(17064) * 0.6 = 10238.4
测试结果
以Triad 操作