我怎么知道,犰狳在我的ARM上使用openblas?

时间:2017-09-07 12:59:41

标签: armadillo openblas

我怎么知道,犰狳正在我的ARM上使用openblas?

  1. 背景

    我正在用armadillo编写一个程序,我安装了openblas,并使用交叉编译器来编译它。我希望犰狳和openblas的程序比仅使用犰狳更快。但他们同时运行。 所以,在我的armv7板上,我怎么知道犰狳正在使用openblas?

  2. 环境

    PC:ubuntu16.04 交叉编译器:arm-linux-g ++ borad:ARM v7

  3. 编译器命令:

    1. 仅限犰狳:
  4. arm-linux-g++ -mtune=cortex-a7 -std=c++11 -I/home/sgks/SGKS6802_LinuxSDK/sdk_build/system/01_software/armadillo-8.100.0_install/include -L/opt/sgks/rootfs/usr/lib -L/home/sgks/SGKS6802_LinuxSDK/sdk_build/system/01_software/armadillo-8.100.0_install/lib -o ./cmake-build-debug/armadillo_test ./main.cpp -larmadillo -O3

       2. with armadillo and openblas:
    

    arm-linux-g++ -mtune=cortex-a7 -std=c++11 -I/home/sgks/SGKS6802_LinuxSDK/sdk_build/system/01_software/armadillo-8.100.0_install/include -I/home/sgks/SGKS6802_LinuxSDK/sdk_build/system/01_software/OpenBLAS-0.2.20-install-arm/include -L/home/sgks/SGKS6802_LinuxSDK/sdk_build/system/01_software/armadillo-8.100.0_install/lib -L/home/sgks/SGKS6802_LinuxSDK/sdk_build/system/01_software/OpenBLAS-0.2.20-install-arm/lib -o ./cmake-build-debug/armadillo_test ./main.cpp -DARMA_DONT_USE_WRAPPER -lopenblas -O3

    1. 测试代码: `

      包括

      包括

      使用命名空间arma; int main() {     clock_t start,stop;     双dur;     fmat weigth_layer1(2801,2642,fill :: randu);     fmat weigth_layer2(2643,2645,fill :: randu);     fmat weigth_layer3(2646,2527,fill :: randu);     fmat weigth_layer4(2528,607,fill :: randu);

      fmat input(1, 2801, fill::randu);
      fmat layer1_output(1,2643);
      fmat layer2_output(1,2646);
      fmat layer3_output(1,2528);
      fmat layer4_output(1,607);
      
      //************************* layer1 *************************
      start = clock();
      layer1_output(0,span(0,2641)) = input * weigth_layer1;
      layer1_output(0,2642) = 1.0; //bias
      layer1_output.elem(find(layer1_output < 0 )) -= layer1_output.elem(find(layer1_output < 0 )); //Relu
      
      cout << "layer1: " << layer1_output.n_cols << endl;
      
      //************************* layer2 *************************
      
      layer2_output(0,span(0,2644)) = layer1_output * weigth_layer2;
      layer2_output(0,2645) = 1.0; //bias
      cout << "layer2: " << layer2_output.n_cols << endl;
      
      layer2_output.elem(find(layer2_output < 0 )) -= layer2_output.elem(find(layer2_output < 0 )); //Relu
      
      
      //************************* layer3 *************************
      
      layer3_output(0,span(0,2526)) = layer2_output * weigth_layer3;
      layer3_output(0,2527) = 1.0;
      cout << "layer3: " << layer3_output.n_cols << endl;
      
      layer3_output.elem(find(layer3_output < 0 )) -= layer3_output.elem(find(layer3_output < 0 )); //Relu
      
      //************************* layer4 *************************
      
      layer4_output = layer3_output * weigth_layer4;
      cout << "layer4: " << layer4_output.n_cols << endl;
      
      
      stop = clock();
      dur = stop - start;
      printf("time : %f\n", dur / CLOCKS_PER_SEC);
      
      return 0;
      

      }

    2. `

      PS:代码格式错误,sry为此,stackoverflow不支持markdown?

2 个答案:

答案 0 :(得分:1)

如果OpenBlas安装正确并且lib路径正确,则应该是使用的路径。您可以在Armadillo中查看配置:

arma::arma_config cfg;
if( cfg.blas)
    std::cout << "BLAS enabled: "<< std::endl;

另一种测试方法是在编译和比较性能时禁用BLAS(在这种情况下,它将使用模拟函数)。 NB!在包含犰狳之前添加此定义。

#define ARMA_DONT_USE_BLAS
#include <armadillo>

答案 1 :(得分:0)

您还可以检查armadillo库文件是否引用了openblas:例如,这是我使用ldd命令的输出:

ldd /usr/lib/libarmadillo.so
linux-vdso.so.1 (0x0000007f9fe80000)
libblas.so.3 => /usr/lib/aarch64-linux-gnu/libblas.so.3 (0x0000007f9fdb0000)
liblapack.so.3 => /usr/lib/aarch64-linux-gnu/liblapack.so.3 (0x0000007f9f8d4000)
libarpack.so.2 => /usr/lib/aarch64-linux-gnu/libarpack.so.2 (0x0000007f9f884000)
libsuperlu.so.5 => /usr/lib/aarch64-linux-gnu/libsuperlu.so.5 (0x0000007f9f81c000)
libstdc++.so.6 => /usr/lib/aarch64-linux-gnu/libstdc++.so.6 (0x0000007f9f689000)
libm.so.6 => /lib/aarch64-linux-gnu/libm.so.6 (0x0000007f9f5cf000)
libgcc_s.so.1 => /lib/aarch64-linux-gnu/libgcc_s.so.1 (0x0000007f9f5ab000)
libc.so.6 => /lib/aarch64-linux-gnu/libc.so.6 (0x0000007f9f452000)
libopenblas.so.0 => /usr/lib/aarch64-linux-gnu/libopenblas.so.0 (0x0000007f9ed8a000)
/lib/ld-linux-aarch64.so.1 (0x0000007f9fe55000)
libgfortran.so.4 => /usr/lib/aarch64-linux-gnu/libgfortran.so.4 (0x0000007f9ec86000)
libpthread.so.0 => /lib/aarch64-linux-gnu/libpthread.so.0 (0x0000007f9ec5a000)