Matlab 2007b and CUDA Can't compile CUDA example with Matlab

Hi,

If I compile an example with Visual C++ Express from the SDK I don’t have any problems, I can run it…

Now, I’m trying to use the CUDA plugin for Matlab ith Matlab2007b and Visual C++2005 Express edition, I can compile a mex file with no problem, but I can’t compile the example :

nvmex -f nvmexopts.bat Szeta.cu -IC:\cuda\include -LC:\cuda\lib -lcufft -lcudart

The result is

Szeta.cu 

"C:\Program Files\Microsoft Visual Studio 8\VC\INCLUDE\crtdefs.h", line 472: error:  

          invalid combination of type specifiers 

  typedef unsigned short wchar_t; 

  ^ 

"c:\cuda\include\common_functions.h", line 55: warning: dllexport/dllimport 

          conflict with "clock" (declared at line 176 of "C:\Program 

          Files\Microsoft Visual Studio 8\VC\INCLUDE\time.h"); 

          dllimport/dllexport dropped 

  extern __declspec(__host__) __declspec(__device__) clock_t clock(void); 

                                                             ^ 

1 error detected in the compilation of "C:\DOCUME~1\JEAN-B~1\LOCALS~1\Temp/tmpxft_00000f00_00000000-5.ii". 

 F:\MATLAB~1\BIN\NVMEX.PL: Error: Compile of 'Szeta.cu' failed.

I don’t know this kind of error…

Does anybody have an idea ?

Thanks,

JB

Have you downloaded the new Matlab plugin for 1.1?

The nvmexopts.bat is slightly different.

Yes I’m using v1.1

@echo off

rem MSVC80OPTS.BAT

rem

rem    Compile and link options used for building MEX-files

rem    using the Microsoft Visual C++ compiler version 8.0

rem

rem    $Revision: 1.1.10.2 $  $Date: 2006/06/23 19:04:53 $

rem

rem ********************************************************************

rem General parameters

rem ********************************************************************

set MATLAB=%MATLAB%

set VS80COMNTOOLS=%VS80COMNTOOLS%

set VSINSTALLDIR=C:\Program Files\Microsoft Visual Studio 8

set VCINSTALLDIR=%VSINSTALLDIR%\VC

set PATH=%VCINSTALLDIR%\BIN\;%VCINSTALLDIR%\PlatformSDK\bin;%VSINSTALLDIR%\Common7\IDE;%VSINSTALLDIR%\SDK\v2.0\bin;%VSINSTALLDIR%\Common7\Tools;%VSINSTALLDIR%\Common7\Tools\bin;%VCINSTALLDIR%\VCPackages;%MATLAB_BIN%;%PATH%

set INCLUDE=%VCINSTALLDIR%\ATLMFC\INCLUDE;%VCINSTALLDIR%\INCLUDE;%VCINSTALLDIR%\PlatformSDK\INCLUDE;%VSINSTALLDIR%\SDK\v2.0\include;%INCLUDE%

set LIB=%VCINSTALLDIR%\ATLMFC\LIB;%VCINSTALLDIR%\LIB;%VCINSTALLDIR%\PlatformSDK\lib;%VSINSTALLDIR%\SDK\v2.0\lib;%MATLAB%\extern\lib\win32;%LIB%

set MW_TARGET_ARCH=win32

rem ********************************************************************

rem Compiler parameters

rem ********************************************************************

set COMPILER=nvcc

set COMPFLAGS=-c -Xcompiler "/c /Zp8 /GR /W3 /EHsc- /Zc:wchar_t- /DMATLAB_MEX_FILE /nologo"

set OPTIMFLAGS=-Xcompiler "/MD /O2 /Oy- /DNDEBUG"

set DEBUGFLAGS=-Xcompiler "/MD /Zi /Fd"%OUTDIR%%MEX_NAME%%MEX_EXT%.pdb"

set NAME_OBJECT=-o

rem ********************************************************************

rem Linker parameters

rem ********************************************************************

set LIBLOC=%MATLAB%\extern\lib\win32\microsoft

set LINKER=link

rem set LINKER=nvcc

set LINKFLAGS=/dll /export:%ENTRYPOINT% /MAP /LIBPATH:"%LIBLOC%" libmx.lib libmex.lib libmat.lib /implib:%LIB_NAME%.x /MACHINE:X86 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib

set LINKOPTIMFLAGS=

set LINKDEBUGFLAGS=/DEBUG /PDB:"%OUTDIR%%MEX_NAME%%MEX_EXT%.pdb"

set LINK_FILE=

set LINK_LIB=

set NAME_OUTPUT=/out:"%OUTDIR%%MEX_NAME%%MEX_EXT%"

set RSP_FILE_INDICATOR=@

rem ********************************************************************

rem Resource compiler parameters

rem ********************************************************************

set RC_COMPILER=rc /fo "%OUTDIR%mexversion.res"

set RC_LINKER=

set POSTLINK_CMDS=del "%OUTDIR%%MEX_NAME%.map"

set POSTLINK_CMDS1=del %LIB_NAME%.x

set POSTLINK_CMDS2=mt -outputresource:"%OUTDIR%%MEX_NAME%%MEX_EXT%";2 -manifest "%OUTDIR%%MEX_NAME%%MEX_EXT%.manifest"

set POSTLINK_CMDS3=del "%OUTDIR%%MEX_NAME%%MEX_EXT%.manifest"

Thanks for your rapid answer,

JB

I see, the package updated is missing the new nvmexopts.bat needed for 1.1.

I will post the modified version later on the forum and update the whole package.

OK, thank you very much !
JB

This nvmexopts.bat will fix the error.

The compiler flags need an additional -D_WCHAR_T_DEFINED

@echo off

rem MSVC80OPTS.BAT

rem

rem    Compile and link options used for building MEX-files

rem    using the Microsoft Visual C++ compiler version 8.0

rem

rem    $Revision: 1.1.10.2 $  $Date: 2006/06/23 19:04:53 $

rem

rem ********************************************************************

rem General parameters

rem ********************************************************************

set MATLAB=%MATLAB%

set VS80COMNTOOLS=%VS80COMNTOOLS%

set VSINSTALLDIR=C:\Program Files\Microsoft Visual Studio 8

set VCINSTALLDIR=%VSINSTALLDIR%\VC

set PATH=%VCINSTALLDIR%\BIN\;%VCINSTALLDIR%\PlatformSDK\bin;%VSINSTALLDIR%\Common7\IDE;%VSINSTALLDIR%\SDK\v2.0\bin;%VSINSTALLDIR%\Common7\Tools;%VSINSTALLDIR%\Common7\Tools\bin;%VCINSTALLDIR%\VCPackages;%MATLAB_BIN%;%PATH%

set INCLUDE=%VCINSTALLDIR%\ATLMFC\INCLUDE;%VCINSTALLDIR%\INCLUDE;%VCINSTALLDIR%\PlatformSDK\INCLUDE;%VSINSTALLDIR%\SDK\v2.0\include;%INCLUDE%

set LIB=%VCINSTALLDIR%\ATLMFC\LIB;%VCINSTALLDIR%\LIB;%VCINSTALLDIR%\PlatformSDK\lib;%VSINSTALLDIR%\SDK\v2.0\lib;%MATLAB%\extern\lib\win32;%LIB%

set MW_TARGET_ARCH=win32

rem ********************************************************************

rem Compiler parameters

rem ********************************************************************

set COMPILER=nvcc

set COMPFLAGS=-c -D_WCHAR_T_DEFINED -Xcompiler "/c /Zp8 /GR /W3 /EHsc- /Zc:wchar_t- /DMATLAB_MEX_FILE /nologo"

set OPTIMFLAGS=-D_WCHAR_T_DEFINED -Xcompiler "/MD /O2 /Oy- /DNDEBUG"

set DEBUGFLAGS=-D_WCHAR_T_DEFINED -Xcompiler "/MD /Zi /Fd"%OUTDIR%%MEX_NAME%%MEX_EXT%.pdb"

set NAME_OBJECT=-o

rem ********************************************************************

rem Linker parameters

rem ********************************************************************

set LIBLOC=%MATLAB%\extern\lib\win32\microsoft

set LINKER=link

rem set LINKER=nvcc

set LINKFLAGS=/dll /export:%ENTRYPOINT% /MAP /LIBPATH:"%LIBLOC%" libmx.lib libmex.lib libmat.lib /implib:%LIB_NAME%.x /MACHINE:X86 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib

set LINKOPTIMFLAGS=

set LINKDEBUGFLAGS=/DEBUG /PDB:"%OUTDIR%%MEX_NAME%%MEX_EXT%.pdb"

set LINK_FILE=

set LINK_LIB=

set NAME_OUTPUT=/out:"%OUTDIR%%MEX_NAME%%MEX_EXT%"

set RSP_FILE_INDICATOR=@

rem ********************************************************************

rem Resource compiler parameters

rem ********************************************************************

set RC_COMPILER=rc /fo "%OUTDIR%mexversion.res"

set RC_LINKER=

set POSTLINK_CMDS=del "%OUTDIR%%MEX_NAME%.map"

set POSTLINK_CMDS1=del %LIB_NAME%.x

set POSTLINK_CMDS2=mt -outputresource:"%OUTDIR%%MEX_NAME%%MEX_EXT%";2 -manifest "%OUTDIR%%MEX_NAME%%MEX_EXT%.manifest"

set POSTLINK_CMDS3=del "%OUTDIR%%MEX_NAME%%MEX_EXT%.manifest"

Thank you very much, all it’s OK !

The package on the web is now up to date.

I have a similar problem with Matlab R2007b and plugin 1.1…

I can correctly execute the code mentioned below:

…but when I try to compile CUDA code like the one in the example:

I receive this message:

I’ve already done the setup of “nvmex” choosing M$ Visual Studio 8 but I always receive the same message. I don’t know how to use the plugin with Matlab. I don’t understand if compiling those programs is mandatory or I just need to replace fft2 and ifft2 files in mathlab with the ones i just created :D

On the pc I have:

CUDA SDK 1.1

CUDA 1.1 Toolkit

Microsoft Visual Studio 8 Express

Microsoft Platform SDK for Windows Server 2003 R2

Matlab R2007b

Thanks

Hi. I need helpppzzz.

I have a promblem too ;(

A have on PC:

WIN XP x32. ( ver 5.1.2600 Build 2600 SP2)
MATLAB Version 7.2.0.232 (R2006a)

instalated

cude Matlab_CUDA-1.1a.zip - 192.684BYTE
NVIDIA_CUDA_Toolkit_1.1_x86
NVIDIA_CUDA_SDK_1.1_x86
Visual Studio 8 (2005) ver 14.00.50727.42 for x86

problems:

1#
in Matlab

vmex -f nvmexopts.bat Szeta.cu -IC:\cuda\include -LC:\cuda\lib -lcufft -lcudart
Undefined subroutine &main::mexCatdir called at C:\MATLAB\R2006a\bin\nvmex.pl line 1373.
??? Error using ==> nvmex
Unable to complete successfully. External Image

mex fft2_cuda.c -IC:\CUDA\include -LC:\CUDA\lib -lcudart -lcufft

  • no error
    BUT :
    if try execute it than

   Segmentation violation detected at Tue Jan 08 23:38:03 2008

Configuration:
MATLAB Ver

Register State:
EAX = 00000000 EBX = 033db880
ECX = 00d18ffc EDX = 01296c0f
ESI = 00010000 EDI = 0129959f
EBP = 00d0e004 ES

etc

if mex mulMV.c -IC:\CUDA\include -LC:\CUDA\lib -lcublas

when from module mulMV.c
called cublasInit();

when try execute it (mulMV)

Error:
?? Invalid MEX-file ‘C:\MATLAB\R2006a\work\CUDAC\mulMV.mexw32’: C:\MATLAB\R2006a\work\CUDAC\mulMV.mexw32 its not programm for Win32.

Thanks all.

i get strange errors trying to compile the fft example

mex -f mexgcc.bat fft2_cuda.c -IC:\SDK\Nvidia\Cuda\include -LC:\SDK\nvidia\CUDA\lib -lcudart -lcufft
C:\temp\Local\mex_DC5DCE97-41D2-44A6-70A5-5633ACD9B3A3\fft2_cuda.obj:fft2_cuda.c:(.text+0x7a7): undefined reference to _cudaMalloc' C:\temp\Local\mex_DC5DCE97-41D2-44A6-70A5-5633ACD9B3A3\fft2_cuda.obj:fft2_cuda.c:(.text+0x7c3): undefined reference to _cudaMemcpy’
C:\temp\Local\mex_DC5DCE97-41D2-44A6-70A5-5633ACD9B3A3\fft2_cuda.obj:fft2_cuda.c:(.text+0x834): undefined reference to _cudaMemcpy' C:\temp\Local\mex_DC5DCE97-41D2-44A6-70A5-5633ACD9B3A3\fft2_cuda.obj:fft2_cuda.c:(.text+0x9ec): undefined reference to _cudaFree’
collect2: ld returned 1 exit status

C:\PROGFILE\R18B\BIN\MEX.PL: Error: Link of ‘fft2_cuda.mexw32’ failed.

latest nvidia sdk, tools, lib, everything blah, blah, blah, VS2k8 Exp, cygwin, Mingw, R2007b

i can compile/mex anything with mingw, inbuilt matlab compiler lcc, and vstudio2k8

when i grep through cuda.h i see references to cuMemAlloc but nothing to cudaMalloc?

have you an updated include file?

When I try. Ececute somedemo fft2_cuda.

Output

   Segmentation violation detected at Wed Jan 09 13:35:17 2008

Configuration:
MATLAB Version: 7.2.0.232 (R2006a)
MATLAB License: 161051
Operating System: Microsoft Windows XP
Window System: Version 5.1 (Build 2600: Service Pack 2)
Processor ID: x86 Family 15 Model 8 Stepping 2, AuthenticAMD
Virtual Machine: Java 1.5.0 with Sun Microsystems Inc. Java HotSpot™ Client VM mixed mode
Default Charset: windows-1251

Register State:
EAX = 00d0e7ec EBX = 033daac0
ECX = 00d0e808 EDX = 00000000
ESI = 00d0e79c EDI = 00d0e638
EBP = 00d0e008 ESP = 00d0dffc
EIP = 00000000 FLG = 00010202

Stack Trace:
[0] libmx.dll:_mxGetM(0x00d0e79c, 0x00d


etc.

Help :blink:

When I use mex file where


status = cublasInit ();

status = cublasGetError ();
if (status != CUBLAS_STATUS_SUCCESS) {
mexPrintf(“CUBLAS: error \n”);
} else {
mexPrintf(“CUBLAS: OK \n”);
exit(0);
}

compilation is OK. But execute output
CUBLAS: error \n

??? My Video Cart is GeForce 6100

Thanks

Thanks all

Your card does not support CUDA.
You need a G8x based card.

who are you responding to? thx

i have a 7300GT

I was responding to DS.Will, but it applies to you too. You cannot run CUDA on a 7300GT.

how do you get to be a hardware alpha/beta tester? we’re going to be doing image processing with a Red One camera which throws out 4k compressed frames and 2k uncompressed data. i’d like to see what kind of cutting edge stuff you got.

Thank you.

i reinstalled XP.

reinstalled Matlab 2007b ( work with only this version )

reinstalled Visual Studio 8

now nvmex works

and i bay GeForce 8800

i could run all the fft code using mex

mex fft2_cuda.c -ID:\Programming\CUDA\include -LD:\Programming\CUDA\lib -lcudart -lcufft
mex fft2_cuda_sp_dp.c -ID:\Programming\CUDA\include -LD:\Programming\CUDA\lib -lcudart -lcufft
mex ifft2_cuda.c -ID:\Programming\CUDA\include -LD:\Programming\CUDA\lib -lcudart -lcufft

and i cud run successfull the following code also

which Szeta
C:\Documents and Settings\CUDA\Desktop\CUDA\Szeta.m
tic; FS_2Dturb(128,1,1,1); toc;

CFL =

0.1017

Gsqav =

1.1995

Elapsed time is 8.506012 seconds.

tic; FS_vortex; toc;

ans =

512

Elapsed time is 216.061310 seconds.

but when i try to compile the CUDA source The following error is showing up that it could not open the file kernel32.lib…some body please help me as i am anew bie…

nvmex -f nvmexopts.bat Szeta.cu -ID:\Programming\CUDA\include -LD:\Programming\CUDA\lib -lcufft -lcudart
Szeta.cu
“d:\programming\cuda\include\common_functions.h”, line 55: warning:
dllexport/dllimport conflict with “clock” (declared at line 176 of
“D:\Programming\Microsoft Visual Studio 8\VC\INCLUDE\time.h”);
dllimport/dllexport dropped
extern __declspec(host) __declspec(device) clock_t clock(void) ;
^

tmpxft_0000096c_00000000-3.gpu
tmpxft_0000096c_00000000-7.gpu
tmpxft_0000096c_00000000-3.c
Microsoft ® Incremental Linker Version 8.00.50727.42
Copyright © Microsoft Corporation. All rights reserved.

C:\DOCUME~1\VACLAV~1\LOCALS~1\Temp\mex_6F498E69-70C6-48EE-0A85-415E0C0382C0\Szeta.obj
LINK : fatal error LNK1181: cannot open input file ‘kernel32.lib’

D:\MATHEM~1\MATLAB\R2007B\BIN\NVMEX.PL: Error: Link of ‘Szeta.mexw32’ failed.

??? Error using ==> nvmex at 206
Unable to complete successfully.

I will be grateful if someone help me out…

LINK : fatal error LNK1181: cannot

I have found the solution (at least for my machine, Matlab 2009a, Visual Studio 2008 (9.0) )

1st: The linker searches for some libraries, such as kernel32.lib, in %MATLAB%\extern\lib\win32\microsoft% (see nvmexopt.bat)
The libraries are in the MSVC SDK path in “C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin”
Copy all the files (*.lib) of the second (MSVC) to the first directory (MATLAB).

2nd: After that I encountered a problem with the mt command in the pre-last line of the nvmexopts.bat file
set POSTLINK_CMDS2=mt … bla bla
replace it with
set POSTLINK_CMDS2=“C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\mt.exe” … bla bla

3rd: One minor change is the path of the visual studio:
set VSINSTALLDIR=C:\Program Files\Microsoft Visual Studio 9.0
instead of Visual Studio 8.0
Of course, maybe somebody can give a more efficient solution.

I hope it will work for you!

Hello,

I did what you say and it works, I can compile with Matlab 2007b and Visual Studio 9.0
and I run the exemple to solve the Euler equation and I obtain the same results, therefore, It works.

However, Matlab continues giving me this fail with these warnings:

mex fft2_cuda.c -IC:\CUDA\include -LC:\CUDA\lib -lcudart -lcufft
Writing library for fft2_cuda.mexw32
c:\docume~1\josant~1\config~1\temp\mex_30a60ef5-40e7-4a67-9c81-c4e847b5aec2\fft2_cuda.obj .text: undefined reference to ‘_cudaMalloc@8’
c:\docume~1\josant~1\config~1\temp\mex_30a60ef5-40e7-4a67-9c81-c4e847b5aec2\fft2_cuda.obj .text: undefined reference to ‘_cudaMemcpy@16’
c:\docume~1\josant~1\config~1\temp\mex_30a60ef5-40e7-4a67-9c81-c4e847b5aec2\fft2_cuda.obj .text: undefined reference to ‘_cufftPlan2d@16’
c:\docume~1\josant~1\config~1\temp\mex_30a60ef5-40e7-4a67-9c81-c4e847b5aec2\fft2_cuda.obj .text: undefined reference to ‘_cufftExecC2C@16’
c:\docume~1\josant~1\config~1\temp\mex_30a60ef5-40e7-4a67-9c81-c4e847b5aec2\fft2_cuda.obj .text: undefined reference to ‘_cufftDestroy@4’
c:\docume~1\josant~1\config~1\temp\mex_30a60ef5-40e7-4a67-9c81-c4e847b5aec2\fft2_cuda.obj .text: undefined reference to ‘_cudaFree@4’

C:\ARCHIV~1\MATLAB\R2007B\BIN\MEX.PL: Error: Link of ‘fft2_cuda.mexw32’ failed.

??? Error using ==> mex at 208
Unable to complete successfully.

Although the fft2_cuda.mex32 is created in any case.
Is it something about the mex file?. About Matlab?

Thank you
:-)