【问题标题】:How do I know,armadillo is working with openblas on my ARM?我怎么知道,犰狳正在我的 ARM 上使用 openblas?
【发布时间】:2017-09-07 12:59:40
【问题描述】:

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

  1. 背景

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

  2. 环境

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

  3. 编译器命令:

    1. 仅适用于犰狳:

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; 主函数() { clock_t 开始,停止; 双杜; fmat weight_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;
    

    }

`

PS:代码格式不对,请问stackoverflow不支持markdown吗?

【问题讨论】:

    标签: armadillo openblas


    【解决方案1】:

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

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

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

    #define ARMA_DONT_USE_BLAS
    #include <armadillo>
    

    【讨论】:

    • 感谢您的回复!最后,我联系了openblas的作者,他们回复说,他们没有针对arm v7进行优化,我用你的第二种方式测试我的代码,确认openblas没有针对arm v7进行优化。
    【解决方案2】:

    您还可以检查 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)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多