首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >dgemm nvblas gpu卸载

dgemm nvblas gpu卸载
EN

Stack Overflow用户
提问于 2018-07-26 03:35:31
回答 1查看 416关注 0票数 0

我测试了执行矩阵乘法的应用程序,并尝试将负载转移到nvblas的gpu上。

代码语言:javascript
复制
#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

代码语言:javascript
复制
g++ testmm.cpp -I$ARMADILLO_INCLUDE_DIR -lopenblas -L$OPENBLAS_ROOT/lib/ --std=c+11 -o a.cpu.out

GPU

代码语言:javascript
复制
g++ testmm.cpp -I$ARMADILLO_INCLUDE_DIR -lopenblas -L$OPENBLAS_ROOT/lib/ --std=c+11 -lnvblas -L$CUDATOOLKIT_HOME/lib64 -o a.cuda.out

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

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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-07-26 03:35:31

链接的顺序是一个问题。当我为gpu执行以下操作时,问题得到了解决。

GPU

代码语言:javascript
复制
g++ testmm.cpp -lnvblas -L$CUDATOOLKIT_HOME/lib64 -I$ARMADILLO_INCLUDE_DIR -lopenblas -L$OPENBLAS_ROOT/lib/ --std=c+11 -o a.cuda.out

使用上面的代码,当我转储符号表时,我看到以下输出。

代码语言:javascript
复制
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.

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

代码语言:javascript
复制
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。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51526442

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档