【开发工具】【stream】内存带宽测试工具(Stream)的使用

1,341 阅读3分钟

获取更多相关的嵌入式开发工具,可收藏系列博文,持续更新中:
【开发工具】嵌入式常用开发工具汇总帖

Stream简介

STREAM是一套综合性能测试程序集,通过fortran和C两种高级且高效的语言编写完成,由于这两种语言在数学计算方面的高效率, 使得 STREAM 测试例程可以充分发挥出内存的能力。 STREAM 测试得到的是可持续运行的内存带宽最大值,而并不是一般的硬件厂商提供的理论最大值。

Stream测试原理:

1.主要有四种数组的运算,测试到内存带宽的性能,分别是:数组的复制(Copy)、数组的尺度变换(Scale)、数组的矢量求和(Add)、数组的复合矢量求和(Triad)

2. 数组的值采用了双精度(8个字节)

Stream工具安装

  • 下载Stream工具(stream_5.10.tar.gz):stream_5.10.tar.gz-Linux文档类资源-CSDN下载

  • 解压缩

    tar -zxvf stream_5.10.tar.gz

    注:小技巧:Linux下一般压缩文件后缀为.tar.bz2和.tar.gz, 它们解压命令有两三个选项是一致的: xf(v),前者再加上j选项,后者再加上z选项。

  • 进入目录

    cd stream_5.10

  • 编译

    gcc -O3 -mcmodel=small -mtune=native -march=native -fopenmp -DSTREAM_ARRAY_SIZE=200000000 -DNTIMES=30 stream.c -o stream.o

    参数解析: -O3 ; 编译器编译优化级别; -mcmodel=small ;当单个Memory Array Size 大于2GB时需要设置此参数。 //新的gcc已经不支持‘-mcmodel=medium’参数了,可以改为“-mcmodel=large”、“-mcmodel=small”、“-mcmodel=tiny” -fopenmp; 适应多处理器环境;开启后,程序默认线程为CPU线程数, 也可以运行时也可以动态指定运行的进程数 : export OMP_NUM_THREADS=12 #12为自定义的要使用的处理器 -DSTREAM_ARRAY_SIZE=200000000;指定计算中a[],b[],c[]数组的大小, //这个参数是对测试结果影响最大,也是最需要关注的一个参数,它用来指定计算中a[],b[],c[]数组的大小,且数组的值采用了双精度(8个字节)。数组的维数 STREAM ARRAY_SIZE 定义时需要注意以下几点:

    //一、要充分考虑内存容量的需求,粗略估计是 STREAM ARRAY_SIZE × 8(双精度) × 3 (三个数组)<= 0.6*M;M 是用户的可用内存。 //二、要保证测试过程中,使用到的内存容量要大于处理器内的缓存,只有这样才会有内存的操作,而不仅仅是对处理器内缓存的操作。 //三、为了保证测试可以持续一段时间,测试过程中内存带宽可以达到一定的最大值, 从而避免得不到实际最大峰值的情况,如果四项测试中有完成时间小于20微秒的情况,就需要适当的增大测试数组的维度 STREAM ARRAY_SIZE。 -DNTIMES=30 ;执行的次数,并且从这些结果中选最优值。 -DOFFSET=4096 ;数组的偏移,一般可以不定义。

  • 运行

    ./stream.o

Ps:

编译可能出现的报错

gcc: error: unrecognized argument in option ‘-mcmodel=medium’

gcc: note: valid arguments to ‘-mcmodel=’ are: large small tiny

原因:

新的gcc已经不支持‘-mcmodel=medium’参数了,可以改为“-mcmodel=large”、“-mcmodel=small”、“-mcmodel=tiny”

Stream工具的使用

编译后执行测试

root@keda-PC:~/stream_5.10# ./stream.o 
-------------------------------------------------------------
STREAM version $Revision: 5.10 $
-------------------------------------------------------------
This system uses 8 bytes per array element.
-------------------------------------------------------------
Array size = 200000000 (elements), Offset = 0 (elements)
Memory per array = 1525.9 MiB (= 1.5 GiB).
Total memory required = 4577.6 MiB (= 4.5 GiB).
Each kernel will be executed 30 times.
 The *best* time for each kernel (excluding the first iteration)
 will be used to compute the reported bandwidth.
-------------------------------------------------------------
Number of Threads requested = 64
Number of Threads counted = 64
-------------------------------------------------------------
Your clock granularity/precision appears to be 1 microseconds.
Each test below will take on the order of 283742 microseconds.
   (= 283742 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:           10011.9     0.341517     0.319619     0.410092
Scale:          12862.1     0.263717     0.248792     0.308815
Add:            12651.1     0.399726     0.379415     0.448929
Triad:          12634.4     0.401277     0.379914     0.441468
-------------------------------------------------------------
Solution Validates: avg error less than 1.000000e-13 on all three arrays
-------------------------------------------------------------