Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Problem compiling CUDA

Subject: Problem compiling CUDA

From: mklcst Costola

Date: 29 Sep, 2009 07:36:08

Message: 1 of 13

Hi everybody, I have a problem compiling CUDA example files.

My pc has:
Vista 64
Matlab r2009b
Microsoft Visual Studio 2008 express

__________________________________________________________
>> mex fft2_cuda.c -IC:\CUDA\include -LC:\CUDA\lib -lcudart -lcufft
   Creating library C:\USERS\COMPUT~1\APPDATA\LOCAL\TEMP\MEX_MD~1\templib.x and object C:\USERS\COMPUT~1\APPDATA\LOCAL\TEMP\MEX_MD~1\templib.exp
fft2_cuda.obj : error LNK2019: unresolved external symbol cudaFree referenced in function mexFunction
fft2_cuda.obj : error LNK2019: unresolved external symbol cufftDestroy referenced in function mexFunction
fft2_cuda.obj : error LNK2019: unresolved external symbol cufftExecC2C referenced in function mexFunction
fft2_cuda.obj : error LNK2019: unresolved external symbol cufftPlan2d referenced in function mexFunction
fft2_cuda.obj : error LNK2019: unresolved external symbol cudaMemcpy referenced in function mexFunction
fft2_cuda.obj : error LNK2019: unresolved external symbol cudaMalloc referenced in function mexFunction
fft2_cuda.mexw64 : fatal error LNK1120: 6 unresolved externals
 
  C:\PROGRA~1\MATLAB\R2009B\BIN\MEX.PL: Error: Link of 'fft2_cuda.mexw64' failed.
 
??? Error using ==> mex at 221
Unable to complete successfully.

Subject: Problem compiling CUDA

From: Oliver Woodford

Date: 29 Sep, 2009 08:29:02

Message: 2 of 13

"mklcst Costola" <mklcst@gmail.com> wrote in message <h9sdd8$5kd$1@fred.mathworks.com>...
> Hi everybody, I have a problem compiling CUDA example files.
>
> My pc has:
> Vista 64
> Matlab r2009b
> Microsoft Visual Studio 2008 express
>
> __________________________________________________________
> >> mex fft2_cuda.c -IC:\CUDA\include -LC:\CUDA\lib -lcudart -lcufft
> Creating library C:\USERS\COMPUT~1\APPDATA\LOCAL\TEMP\MEX_MD~1\templib.x and object C:\USERS\COMPUT~1\APPDATA\LOCAL\TEMP\MEX_MD~1\templib.exp
> fft2_cuda.obj : error LNK2019: unresolved external symbol cudaFree referenced in function mexFunction
> fft2_cuda.obj : error LNK2019: unresolved external symbol cufftDestroy referenced in function mexFunction
> fft2_cuda.obj : error LNK2019: unresolved external symbol cufftExecC2C referenced in function mexFunction
> fft2_cuda.obj : error LNK2019: unresolved external symbol cufftPlan2d referenced in function mexFunction
> fft2_cuda.obj : error LNK2019: unresolved external symbol cudaMemcpy referenced in function mexFunction
> fft2_cuda.obj : error LNK2019: unresolved external symbol cudaMalloc referenced in function mexFunction
> fft2_cuda.mexw64 : fatal error LNK1120: 6 unresolved externals
>
> C:\PROGRA~1\MATLAB\R2009B\BIN\MEX.PL: Error: Link of 'fft2_cuda.mexw64' failed.
>
> ??? Error using ==> mex at 221
> Unable to complete successfully.

Does running the following function:
http://www.mathworks.com/matlabcentral/fileexchange/25314
then calling cuda_mex in place of mex work?

Oliver

Subject: Problem compiling CUDA

From: mklcst Costola

Date: 29 Sep, 2009 09:15:21

Message: 3 of 13

Sorry Oliver, how does it work?

Subject: Problem compiling CUDA

From: mklcst Costola

Date: 29 Sep, 2009 09:23:03

Message: 4 of 13

"mklcst Costola" <mklcst@gmail.com> wrote in message <h9sj79$8gm$1@fred.mathworks.com>...
> Sorry Oliver, how does it work?

I get this error:

Note that only Visual Studio compilers are supported.
Creating cudamexopts.bat based on mexopts.bat...
Creating cuda_mex.pl based on mex.pl...
??? Error using ==> fprintf
Invalid file identifier. Use fopen to generate a valid file identifier.

Error in ==> setup_cuda_mex at 73
    fprintf(fid_cuda_mex, '%s', line);

Subject: Problem compiling CUDA

From: Oliver Woodford

Date: 29 Sep, 2009 10:05:04

Message: 5 of 13

"mklcst Costola" wrote:
> > Sorry Oliver, how does it work?
>
> I get this error:
>
> Note that only Visual Studio compilers are supported.
> Creating cudamexopts.bat based on mexopts.bat...
> Creating cuda_mex.pl based on mex.pl...
> ??? Error using ==> fprintf
> Invalid file identifier. Use fopen to generate a valid file identifier.
>
> Error in ==> setup_cuda_mex at 73
> fprintf(fid_cuda_mex, '%s', line);

You'd need to ask the author what's wrong there.

Alternatively you could try the approach I outline here:
http://www.mathworks.com/matlabcentral/newsreader/view_thread/261866
It should work on Windows as well. You'll need to iron out any issues yourself, though.

Oliver

Subject: Problem compiling CUDA

From: Anthony

Date: 22 Oct, 2009 02:32:05

Message: 6 of 13

I had the exact same problem and I could not do anything to fix it despite spending hours over the past few days. I tried with both the VS2005 and VS2008 compilers. I have a 64-bit vista platform as well, I'm wondering if that may be related to the problem? Have you had any luck fixing it?

Subject: Problem compiling CUDA

From: Keerthi Kamal

Date: 30 Oct, 2009 18:25:20

Message: 7 of 13

"Anthony " <aerlinger@gmail.com> wrote in message <hbog75$gn2$1@fred.mathworks.com>...
> I had the exact same problem and I could not do anything to fix it despite spending hours over the past few days. I tried with both the VS2005 and VS2008 compilers. I have a 64-bit vista platform as well, I'm wondering if that may be related to the problem? Have you had any luck fixing it?

I do have the exact problem, Im running vista 64 bit, matlab r2008b 64 bit, vs2008 on a mac book pro with 9400M graphics card.

Subject: Problem compiling CUDA

From: Keerthi Kamal

Date: 31 Oct, 2009 18:49:02

Message: 8 of 13

"Anthony " <aerlinger@gmail.com> wrote in message <hbog75$gn2$1@fred.mathworks.com>...
> I had the exact same problem and I could not do anything to fix it despite spending hours over the past few days. I tried with both the VS2005 and VS2008 compilers. I have a 64-bit vista platform as well, I'm wondering if that may be related to the problem? Have you had any luck fixing it?

I fixed the problem, I went thorugh this page
http://julianapena.com/2009/09/how-to-install-and-configure-cuda-on-windows/
it says cuda 2.3 is not perfected for notebooks, so i installed cuda 2.2 toolkit. It runs fine.

Subject: Problem compiling CUDA

From: Thomas

Date: 13 Nov, 2009 03:01:30

Message: 9 of 13

Hi,
same problem for me.
I've got Windows7 64 bit, Matlab2008b, Cuda2.3 and I'm getting the same 6 unresolved externals.

"Oliver Woodford" <o.j.woodford.98@cantab.net> wrote in message <h9sm4g$ihm$1@fred.mathworks.com>...
> "mklcst Costola" wrote:
> >
> > I get this error:
> >
> > Note that only Visual Studio compilers are supported.
> > Creating cudamexopts.bat based on mexopts.bat...
> > Creating cuda_mex.pl based on mex.pl...
> > ??? Error using ==> fprintf
> > Invalid file identifier. Use fopen to generate a valid file identifier.
> >
> > Error in ==> setup_cuda_mex at 73
> > fprintf(fid_cuda_mex, '%s', line);

This is because you're not allowed to write to $matlabroot/bin/
I got the same error, so I created the file somewhere else and moved it there as administrator.
Unfortunately, I couldn't compile the example:
>> cuda_mex example.cu
WARNING: $ARCH (UNKNOWN) not set correctly [win64]
 
  C:\PROGRA~1\MATLAB\R2008B\BIN\CUDA_MEX.PL:
  Error: Using options file:
         C:\Users\tom\AppData\Roaming\MathWorks\MATLAB\R2008b\cudamexopts.bat
         You cannot use this file with the UNKNOWN architecture because it enables
         a compiler for a different architecture.
         Running mex -setup may resolve this problem.
 
??? Error using ==> cuda_mex at 213
Unable to complete successfully.

It doesn't seem to like the -win64 option passed to cuda_mex.pl

I then tried compiling the example with the nvmex.m / nvmex.pl combination that came with the MATLAB_CUDA_1.1 package but that wouldn't work either:
nvmex -f nvmexopts.bat example.cu -I"C:\Program Files\CUDA\include" -L"C:\Program Files\CUDA\lib" -lcufft -lcudart
Undefined subroutine &main::uuidgen called at C:\Program Files\MATLAB\R2008b\bin\nvmex.pl line 728.
??? Error using ==> nvmex at 206
Unable to complete successfully.

So I installed http://search.cpan.org/~caugustin/UUID-Tiny-1.02/lib/UUID/Tiny.pm to C:\Program Files\MATLAB\R2008b\sys\perl\win32\lib\UUID\, included a 'use UUID::Tiny;' at the top of nvmex.pl, added the following line above line 728:
my $uuid = create_UUID_as_string(UUID_V1);
and replaced uuidgen() with $uuid
This got me to the next error:
>> nvmex -f nvmexopts.bat example.cu -I"C:\Program Files\CUDA\include" -L"C:\Program Files\CUDA\lib" -lcufft -lcudart
uuid: 2e701816-d000-11de-82de-cbe830d9e0fc
WARNING: $ARCH (UNKNOWN) not set correctly [win64]
 
  C:\PROGRA~1\MATLAB\R2008B\BIN\NVMEX.PL:
  Error: Using options file:
         nvmexopts.bat
         You cannot use this file with the UNKNOWN architecture because it enables
         a compiler for a different architecture.
         Choose a file that is compatible with the UNKNOWN architecture.
 
??? Error using ==> nvmex at 206
Unable to complete successfully.

Which is where I gave up.

Any comments, thoughts or suggestions how to fix this mess?
Tom

Subject: Problem compiling CUDA

From: dsss

Date: 19 Nov, 2009 03:38:47

Message: 10 of 13

On Nov 12, 5:01 pm, "Thomas " <tgutz...@ee.uwa.edu.au> wrote:
> Hi,
>
> Any comments, thoughts or suggestions how to fix this mess?
> Tom

Use CUDA 2.2, not 2.3. I had similar problems, but now I can compile
the fft2_cuda.c routines... just not the .cu "accelerated" files
yet...I still have issues with the nvmex.pl command

Subject: Problem compiling CUDA

From: Oliver Woodford

Date: 19 Nov, 2009 09:50:16

Message: 11 of 13

"Thomas " wrote:
> Any comments, thoughts or suggestions how to fix this mess?

I use nvcc to compile each .cu to a .cpp file as follows:
nvcc -I"MATLABROOT/extern/include" --cuda file.cu --output-file temp_a34b7.cpp
(Replace MATLABROOT, file.cu and temp_a34b7.cpp with the correct thing for you.) I then use mex to compile the .cpp files, making sure to include the relevant libraries (and their paths). It works for me (with cuda 2.3 on both linux and Windows), but I haven't tried it extensively.

HTH,
Oliver

Subject: Problem compiling CUDA

From: dsss

Date: 19 Nov, 2009 20:01:30

Message: 12 of 13

On Nov 12, 5:01 pm, "Thomas " <tgutz...@ee.uwa.edu.au> wrote:
> Hi,
> same problem for me.
> I've got Windows7 64 bit, Matlab2008b, Cuda2.3 and I'm getting the same 6 unresolved externals.
> ??? Error using ==> nvmex at 206
> Unable to complete successfully.
>
> Which is where I gave up.
>
> Any comments, thoughts or suggestions how to fix this mess?
> Tom

I'm running into the same issues -- did you happen to try naming the
ARCH as AMD64 anywhere?

Subject: Problem compiling CUDA

From: dsss

Date: 19 Nov, 2009 20:28:08

Message: 13 of 13

On Nov 12, 5:01 pm, "Thomas " <tgutz...@ee.uwa.edu.au> wrote:
> Hi,
> same problem for me.
> I've got Windows7 64 bit, Matlab2008b, Cuda2.3 and I'm getting the same 6 unresolved externals.
>
> "Oliver Woodford" <o.j.woodford...@cantab.net> wrote in message <h9sm4g$ih...@fred.mathworks.com>...
> > "mklcst Costola" wrote:
>
> > > I get this error:
>
> > > Note that only Visual Studio compilers are supported.
> > > Creating cudamexopts.bat based on mexopts.bat...
> > > Creating cuda_mex.pl based on mex.pl...
> > > ??? Error using ==> fprintf
> > > Invalid file identifier.  Use fopen to generate a valid file identifier.
>
> > > Error in ==> setup_cuda_mex at 73
> > >     fprintf(fid_cuda_mex, '%s', line);
>
> This is because you're not allowed to write to $matlabroot/bin/
> I got the same error, so I created the file somewhere else and moved it there as administrator.
> Unfortunately, I couldn't compile the example:>> cuda_mex example.cu
>
> WARNING: $ARCH (UNKNOWN) not set correctly [win64]
>
>   C:\PROGRA~1\MATLAB\R2008B\BIN\CUDA_MEX.PL:  
>   Error: Using options file:
>          C:\Users\tom\AppData\Roaming\MathWorks\MATLAB\R2008b\cudamexopts.bat
>          You cannot use this file with the UNKNOWN architecture because it enables
>          a compiler for a different architecture.
>          Running mex -setup may resolve this problem.
>
> ??? Error using ==> cuda_mex at 213
> Unable to complete successfully.
>
> It doesn't seem to like the -win64 option passed to cuda_mex.pl
>
> I then tried compiling the example with the nvmex.m / nvmex.pl combination that came with the MATLAB_CUDA_1.1 package but that wouldn't work either:
> nvmex -f nvmexopts.bat example.cu  -I"C:\Program Files\CUDA\include" -L"C:\Program Files\CUDA\lib" -lcufft -lcudart
> Undefined subroutine &main::uuidgen called at C:\Program Files\MATLAB\R2008b\bin\nvmex.pl line 728.
> ??? Error using ==> nvmex at 206
> Unable to complete successfully.
>
> So I installedhttp://search.cpan.org/~caugustin/UUID-Tiny-1.02/lib/UUID/Tiny.pmto C:\Program Files\MATLAB\R2008b\sys\perl\win32\lib\UUID\, included a 'use UUID::Tiny;' at the top of nvmex.pl, added the following line above line 728:
> my $uuid = create_UUID_as_string(UUID_V1);
> and replaced uuidgen() with $uuid
> This got me to the next error:>> nvmex -f nvmexopts.bat example.cu  -I"C:\Program Files\CUDA\include" -L"C:\Program Files\CUDA\lib" -lcufft -lcudart
>
> uuid: 2e701816-d000-11de-82de-cbe830d9e0fc
> WARNING: $ARCH (UNKNOWN) not set correctly [win64]
>
>   C:\PROGRA~1\MATLAB\R2008B\BIN\NVMEX.PL:  
>   Error: Using options file:
>          nvmexopts.bat
>          You cannot use this file with the UNKNOWN architecture because it enables
>          a compiler for a different architecture.
>          Choose a file that is compatible with the UNKNOWN architecture.
>
> ??? Error using ==> nvmex at 206
> Unable to complete successfully.
>
> Which is where I gave up.
>
> Any comments, thoughts or suggestions how to fix this mess?
> Tom

I'm putzing through this, so I'll document a bit:

need to change line 156 to:
    ($main::matlabroot = $main::cmd_name) =~ s%\\bin\\nvmex.pl$%%;

Now, my error is:
nvcc fatal : Cannot find compiler 'cl.exe' in PATH

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us