Problem with "cutil.h" under MEX

A strange behavior occurs when cutil.h methods are called from a cuda-Matlab MEX file.
To demonstrate it here, I took the simple example of fft_cuda.
I added #include “cutil.h” and from within the main function I called one of the cutil.h methods by:

unsigned int timer = 0;
CUT_SAFE_CALL(cutStartTimer(timer));

Compiling it returns no special problems, but on runtime I get the error:
??? Invalid MEX-file ‘C:\cuda\fft_cuda_2.mexw32’: The specified module could not be found.

I suspect it fails to find the cutil dll or lib, but this does not help me in solving the problem.

I compile the attached .cu file using:

nvmex -f nvmexopts.bat -IC:\cuda\include -IC:\CUDA\bin -IC:\CUDA\common\inc -LC:\cuda\lib -LC:\CUDA\common\lib -LC:\CUDA\bin -lcufft -lcudart -lcutil32D -lcutil32 -lglut32 fft_cuda_2.cu

I included all the libraries I could think of for the -I and -L switches, and still it doesn’t help. Interestingly enough, the problem does not persist with other libraries such as the opengl glut32, the cufft and others, only with the cutil one (as far as I observed).

cutil has many methods that I need to use, right now I’m really stuck… <img src=‘http://hqnveipbwb20/public/style_emoticons/<#EMO_DIR#>/crying.gif’ class=‘bbc_emoticon’ alt=’:’(’ />

Any ideas?

Thanks!
Y.
fft_cuda_2.rar (2.13 KB)

The cufft and cublas libraries are located in the “bin” directory of the CUDA Toolkit path, which (I believe) gets added to your %PATH% environment variable. However, by default the cutil libraries are located in the subdirectories for the different build variants below the CUDA SDK “bin” path, and this doesn’t get added to your %PATH%. Since the directories in the %PATH% envrionment variable are among those searched when the OS looks for DLLs, I suspect that would explain the behavior that you are seeing. You can try any of these:

a.) copy your cutil.dll to the “bin” directory of the CUDA Toolkit (i.e., where your nvcc.exe and the working cufft.dll is located) or some other location that is in your %PATH% environment variable

b.) Add the path to your cutil.dll to your %PATH% environment variable

c.) Copy cutill.dll to the directory containing the executable that you are running - presumably that would be MATLAB in this case.

Google “dynamic link library search order” for more info.

Hope this helps…

Jeremy Furtek

Thank you, that worked!