Hi I just installed CUDA. I have a GeForce 8400GS and I installed CUDA 2.2 on a 64-bit Ubuntu machine. I just compiled an ran the Example 2 program in the CUBLAS manual. This is the first program I have tried.
I compiled it using
gcc main.c -o main -I/usr/local/cuda/include/ -L/usr/local/cuda/lib/ -lcublas -lcublasemu
When I ran the code I got the following message “device memory allocation failed”
The program is as follows:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <cublas.h>
#define M 6
#define N 5
#define IDX2C(i,j,ld) (((j)*(ld))+(i))
void modify (float *m, int ldm, int n, int p, int q, float alpha,float beta)
{
cublasSscal (n-p, alpha, &m[IDX2C(p,q,ldm)], ldm);
cublasSscal (ldm-p, beta, &m[IDX2C(p,q,ldm)], 1);
}
int main(int argc, char *argv[])
{
int i, j;
cublasStatus stat;
float* devPtrA;
float* a = 0;
a = (float *)malloc (M * N * sizeof (*a));
if (!a) {
printf ("host memory allocation failed");
return 1;
}
for (j = 0; j < N; j++) {
for (i = 0; i < M; i++) {
a[IDX2C(i,j,M)] = i * M + j + 1;
}
}
cublasInit();
stat = cublasAlloc (M*N, sizeof(*a), (void**)&devPtrA);
if (stat != CUBLAS_STATUS_SUCCESS) {
printf ("device memory allocation failed");
return 1;
}
cublasSetMatrix (M, N, sizeof(*a), a, M, devPtrA, M);
modify (devPtrA, M, N, 1, 2, 16.0f, 12.0f);
cublasGetMatrix (M, N, sizeof(*a), devPtrA, M, a, M);
cublasFree (devPtrA);
cublasShutdown();
for (j = 0; j < N; j++) {
for (i = 0; i < M; i++) {
printf ("%7.0f", a[IDX2C(i,j,M)]);
}
printf ("\n");
}
return 0;
}
I am not sure what to make of this error, so any help would be greatly appreciated.