Compiling CUBLAS in VS2005

First of all I should inform you that I am a newbie in gpu computing. :rolleyes:

I managed to run some .cu samples. Now I want to try cublas, I took the following code from CUBLAS Library user guide.

[codebox]#include <stdio.h>

#include <stdlib.h>

#include <math.h>

#include “cublas.h”

#define IDX2F(i,j,ld) ((((j)-1)*(ld))+((i)-1))

void modify (float *m, int ldm, int n, int p, int q, float alpha,

float beta)

{

cublasSscal (n-p+1, alpha, &m[IDX2F(p,q,ldm)], ldm);

cublasSscal (ldm-p+1, beta, &m[IDX2F(p,q,ldm)], 1);

}

#define M 6

#define N 5

int main (void)

{

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 EXIT_FAILURE;

}

for (j = 1; j <= N; j++) {

for (i = 1; i <= M; i++) {

a[IDX2F(i,j,M)] = (i-1) * M + j;

}

}

cublasInit();

stat = cublasAlloc (M*N, sizeof(a), (void*)&devPtrA);

if (stat != CUBLAS_STATUS_SUCCESS) {

printf (“device memory allocation failed”);

return EXIT_FAILURE;

}

cublasSetMatrix (M, N, sizeof(*a), a, M, devPtrA, M);

modify (devPtrA, M, N, 2, 3, 16.0f, 12.0f);

cublasGetMatrix (M, N, sizeof(*a), devPtrA, M, a, M);

cublasFree (devPtrA);

cublasShutdown();

for (j = 1; j <= N; j++) {

for (i = 1; i <= M; i++) {

printf (“%7.0f”, a[IDX2F(i,j,M)]);

}

printf (“\n”);

}

return EXIT_SUCCESS;

}[/codebox]

However, the following errors occur,

Error 7 error LNK2019: unresolved external symbol _cublasAlloc@12 referenced in function _main CUDA1.cu.obj

Error 4 error LNK2019: unresolved external symbol _cublasFree@4 referenced in function _main CUDA1.cu.obj

Error 5 error LNK2019: unresolved external symbol _cublasGetMatrix@28 referenced in function _main CUDA1.cu.obj

Error 8 error LNK2019: unresolved external symbol _cublasInit@0 referenced in function _main CUDA1.cu.obj

Error 6 error LNK2019: unresolved external symbol _cublasSetMatrix@28 referenced in function _main CUDA1.cu.obj

Error 3 error LNK2019: unresolved external symbol _cublasShutdown@0 referenced in function _main CUDA1.cu.obj

Error 2 error LNK2019: unresolved external symbol _cublasSscal@16 referenced in function “void __cdecl modify(float *,int,int,int,int,float,float)” (?

modify@@YAXPAMHHHHMM@Z) CUDA1.cu.obj

Error 9 fatal error LNK1120: 7 unresolved externals C:\Documents and Settings\Administrator\Desktop\gpu_deneme\cublass\Debug\cublass.exe

What should I do?

Thanks

hi,

you have to link cublas library if you are working with Visual Studio open up project properties > linking > input
and input “cublas.lib”,

this should work.

Thanks a lot. it worked :)

Thanks a lot. I have been trying to solve this error for one day.