我测试了执行矩阵乘法的应用程序,并尝试将负载转移到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.outGPU
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库链接。我在这里犯了什么错误吗?
发布于 2018-07-26 03:35:31
链接的顺序是一个问题。当我为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。
https://stackoverflow.com/questions/51526442
复制相似问题