سؤال

Im trying to use the cublasSaxpy function from cublas.

Look at the code:

#include <cublas_v2.h>

float *dev_B;
float *dev_tmp;

cublasStatus_t stat ;
cublasHandle_t handle ;
...
...
stat = cublasCreate(&handle);
if(stat != CUBLAS_STATUS_SUCCESS)
{
    cout << "CUBLAS Initialization failed!" << endl;
    exit(EXIT_FAILURE);
}
...
...
stat = cublasSetVector(N, sizeof(float), vB, N, dev_B, N);
if(stat != CUBLAS_STATUS_SUCCESS)
{
    cout << "CUBLAS setting vector failed" << endl;
    exit(EXIT_FAILURE);
}

stat = cublasSetVector(N, sizeof(float), nullvec, N, dev_tmp, N);
if(stat != CUBLAS_STATUS_SUCCESS)
{
    cout << "CUBLAS setting vector failed" << endl;
    exit(EXIT_FAILURE);
}
...
...
stat = cublasSaxpy(handle, N, 1.0f, dev_B, 1, dev_tmp, 1);

So, I'm using the eclipse nsight from CUDA 5.0 RC1. I didn't build the project because I didn't finish it, but the IDE gives me a read underline in the saxpy operation:

Invalid arguments '
Candidates are:
enum {cublas_api.h:3039} cublasSaxpy_v2(cublasContext *, int, const float *, const float *, int, float *, int)
هل كانت مفيدة؟

المحلول

In the CUBLAS V2 API, all scalar real arguments are passed by reference, not by value. The correct call for saxpy would be something like:

const float alpha = 1.0f;
stat = cublasSaxpy(handle, N, &alpha, dev_B, 1, dev_tmp, 1);

This is clearly discussed in the documentation.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top