Are there any examples of using level 2 CUBLAS routines ?

I am trying an example using cublasStrsv. The cublas call seems to succeed, however when request the results vector, get the error CUBLAS_STATUS_MAPPING_ERROR.

I am a bit unsure about the required format of the input Matrix. In the example below, I am just filling in every element of a N x N matrix. So the number of subdiagonals and superdiagonals should be N-1.

Any ideas why my test fails ?

#define TEST_SIZE 10

void testStrsv(void)

{

float * a;

float * b;

float alpha = 1.0;

float beta = 1.0;

float * x;

float * y;

float * devPtrX;

float * devPtrY;

float * devPtrA;

```
//y = alpha * A * x + (beta * y)
printf("\nStrsv\n");
a = (float *)malloc(TEST_SIZE * TEST_SIZE * sizeof(a));
x = (float *)malloc(TEST_SIZE * sizeof(x));
y = (float *)malloc(TEST_SIZE * sizeof(y));
stat = cublasAlloc(TEST_SIZE * TEST_SIZE,sizeof(a),(void**)&devPtrA);
if(stat != CUBLAS_STATUS_SUCCESS)
printf("1. Error %d\n",stat);
stat = cublasAlloc(TEST_SIZE,sizeof(x),(void**)&devPtrY);
if(stat != CUBLAS_STATUS_SUCCESS)
printf("2. Error %d\n",stat);
stat = cublasAlloc(TEST_SIZE,sizeof(y),(void**)&devPtrX);
if(stat != CUBLAS_STATUS_SUCCESS)
printf("3. Error %d\n",stat);
for (int i=0;i<TEST_SIZE;i++)
{
for (int j=0;j<TEST_SIZE;j++)
a[IDX2F(i,j,TEST_SIZE)] = i * TEST_SIZE + j + 1;
}
for (int i=0;i<TEST_SIZE;i++)
{
x[i] = 1;
y[i] = 1;
}
stat = cublasSetVector(TEST_SIZE,sizeof(a),x,1,devPtrX,1);
stat = cublasSetVector(TEST_SIZE,sizeof(a),y,1,devPtrY,1);
stat = cublasSetMatrix(TEST_SIZE,TEST_SIZE,sizeof(a),a,1,devPtrA,1)
```

;

```
cublasSgbmv('N', //trans - 'N' = operation is A, 'T' = operation is A'
TEST_SIZE, //number of rows
TEST_SIZE, //number of columns
TEST_SIZE -1, //number of sub diagonals of A
TEST_SIZE -1, //number of super diagonals of A
alpha,
a,
TEST_SIZE + TEST_SIZE - 1, //leading dimemsion of A
x,
1,
beta,
y,
1);
stat = cublasGetError();
if(stat != CUBLAS_STATUS_SUCCESS)
printf("4. Error %d\n",stat);
stat = cublasGetVector(TEST_SIZE,sizeof(y),devPtrY,1,y,1);
if(stat != CUBLAS_STATUS_SUCCESS)
printf("5. Error %d\n",stat);
for (int i=0;i<TEST_SIZE;i++)
printf("%f ",y[i]);
cublasFree(devPtrA);
cublasFree(devPtrX);
cublasFree(devPtrY);
free(a);
free(x);
free(y);
```

}