Hi all,
I ve been trying to use the cublas library functions and I have several doubts at a very basic level. In all likelihood these will be very simple… But bear with me…
i) I read that CUBLAS is independent of CUDA and it gives its own functions for allocating memory, transferring data to the GPU etc… But CUBLAS will still work with Vectors or matrices that were allocated and transferred using the basic CUDA functions (cudaMalloc, cudaMemcpy) right…?
ii) Can the CUBLAS functions return a value to a variable on the host, or should I allocate and declare a variable on the device to hold the return value of the function?
iii) What does storage spacing between the elements of an array actually mean? Aren’t elements of an array stored contiguously in memory… In that case would storage spacing be 0.?
[codebox]
#define IDX2C(i,j,ld) (((j )*(ld)) + (i))
int main()
{
int i, array_size = 10;
float *arr1;
float *d_arr2;
arr1 = (float *)malloc(array_size * sizeof(float));
cublasInit();
cudaMalloc( (void**) &d_arr1, array_size*sizeof(float));
for(i=0; i<array_size; i++)
{
arr1[IDX2C(0,i,1)] = i;
}
for (i=0; i<array_size; i++)
{
printf("%f ", arr1[i]);
}
cudaMemcpy(d_arr1, arr1, array_size*sizeof(float), cudaMemcpyHostToDevice);
cublasSscal (array_size, 2.0, d_arr1,sizeof(float));
cudaMemcpy(arr1, d_arr1,array_size*sizeof(float), cudaMemcpyDeviceToHost);
printf(“\n\n”);
for (i=0; i<array_size; i++)
{
printf("%f ", arr1[i]);
}
cublasShutdown();
}[/codebox]
This was the program that i tried to get to run. Just declaring an array and double it using cublasSscal. Could anyone spot what my error is??
Apologies once again if my doubts are too basic…
Thanks,
Avinash