【问题标题】:dgemm nvblas gpu offloaddgemm nvblas gpu 卸载
【发布时间】:2019-01-02 17:14:22
【问题描述】:

我有一个执行矩阵乘法的测试应用程序,并尝试使用 nvblas 卸载到 gpu。

#include <armadillo>
#include <iostream>
using namespace arma;
using namespace std;
int main(int argc, char *argv[]) {
    int m = atoi(argv[1]);
    int k = atoi(argv[2]);
    int n = atoi(argv[3]);
    int t = atoi(argv[4]);
    std::cout << "m::" << m << "::k::" << k << "::n::" << n << std::endl;
    mat A;
    A = randu<mat>(m, k);
    mat B;
    B = randu<mat>(k, n);
    mat C;
    C.zeros(m, n);
    cout << "norm c::" << arma::norm(C, "fro") << std::endl;
    tic();
    for (int i = 0; i < t; i++) {
      C = A * B;
    }
    cout << "time taken ::" << toc()/t << endl;
    cout << "norm c::" << arma::norm(C, "fro") << std::endl;
  }

我将代码编译如下。

CPU

g++ testmm.cpp -I$ARMADILLO_INCLUDE_DIR -lopenblas -L$OPENBLAS_ROOT/lib/ --std=c+11 -o a.cpu.out

GPU

g++ testmm.cpp -I$ARMADILLO_INCLUDE_DIR -lopenblas -L$OPENBLAS_ROOT/lib/ --std=c+11 -lnvblas -L$CUDATOOLKIT_HOME/lib64 -o a.cuda.out

当我使用 4096 4096 4096 运行 a.cpu.out 和 a.cuda.out 时,它们都需要大约 11 秒的时间。我没有看到 a.gpu.out 的时间减少。在 nvblas.conf 中,我将所有内容都保留为默认值,除了 (a) 更改 openblas (b)auto_pin 内存启用的路径。我看到 nvblas.log 说使用“设备 0”而没有其他输出。 nvidia-smi 没有显示 gpu 活动的任何增加,而 nvprof 显示了一堆 cudaMalloc、cudamemcpy、查询设备功能等。但是不存在任何 gemm 调用。

a.cuda.out 上的 ldd 显示它与 nvblas、cublas、cudart 和 cpu openblas 库链接。我在这里犯了什么错误吗?

【问题讨论】:

    标签: armadillo nvblas


    【解决方案1】:

    那里的链接顺序有问题。当我对 gpu 执行以下操作时,问题得到了解决。

    GPU

    g++ testmm.cpp -lnvblas -L$CUDATOOLKIT_HOME/lib64 -I$ARMADILLO_INCLUDE_DIR -lopenblas -L$OPENBLAS_ROOT/lib/ --std=c+11 -o a.cuda.out
    

    通过上述方法,当我转储符号表时,我看到以下输出。

    nm a.cuda.out | grep -is dgemm
                 U cblas_dgemm
                 U dgemm_@@libnvblas.so.9.1 <-- this shows correct linking and ability to offload to gpu.
    

    如果链接不正确,会出现如下链接问题。

    nm a.cuda.out | grep -is dgemm
                 U cblas_dgemm
                 U dgemm_  <-- there will not be a libnvblas here showing it is a problem.
    

    虽然ldd在上述两种情况下都会显示nvblas、cublas、cudart、openblas,但在执行程序时,dgemm始终是openblas。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-09-06
      • 2021-11-18
      • 2012-04-18
      • 2011-02-09
      • 2015-05-31
      • 2019-11-11
      • 2022-11-04
      • 2021-07-28
      相关资源
      最近更新 更多