【发布时间】:2015-09-08 00:53:53
【问题描述】:
我尝试将矩阵[1 2 3 4 ; 5 6 7 8 ; 9 10 11 12 ] 以列主要格式存储为x,首先使用cublasSetMatrix 将其复制到NVIDIA GPU d_x 中的矩阵,然后复制d_x到y 使用cublasGetMatrix()。
#include<stdio.h>
#include"cublas_v2.h"
int main()
{
cublasHandle_t hand;
float x[][3] = { {1,5,9} , {2,6,10} , {3,7,11} , {4,8,12} };
float y[4][3] = {};
float *d_x;
printf("X\n");
for( int i=0 ; i<4 ; i++ )
{
printf("Row %i:",i+1);
for( int j = 0 ; j<3 ; j++ )
{
printf(" %f",x[i][j]);
}
putchar('\n');
}
printf("Y\n");
for( int i=0 ; i<4 ; i++ )
{
printf("Row %i:",i+1);
for( int j = 0 ; j<3 ; j++ )
{
printf(" %f",y[i][j]);
}
putchar('\n');
}
cublasCreate( &hand );
cudaMalloc( &d_x,sizeof(d_x) );
cublasSetMatrix( 3,4,sizeof(float),x,3,d_x,3 );
cublasGetMatrix( 3,4,sizeof(float),d_x,3,y,3 );
printf("X\n");
for( int i=0 ; i<4 ; i++ )
{
printf("Row %i:",i+1);
for( int j = 0 ; j<3 ; j++ )
{
printf(" %f",x[i][j]);
}
putchar('\n');
}
printf("Y\n");
for( int i=0 ; i<4 ; i++ )
{
printf("Row %i:",i+1);
for( int j = 0 ; j<3 ; j++ )
{
printf(" %f",y[i][j]);
}
putchar('\n');
}
cudaFree( d_x );
cublasDestroy( hand );
return 0;
}
复制后的输出显示y用0s填充。
是否有任何 cublas 函数调用失败?
或/和
是否将错误的参数传递给cublas 函数?
另外,请解释每个函数参数的用途。
在 Fedora 21 x86_64 上使用 GeForce GTX 650 和 CUDA 6.5。
【问题讨论】: