How to install cuda plugin in matlab in linux

Hi all ,

i have recently installed matlab 2010 in an opensuse 11.2 64bit. Now i want to install the cuda plugin. i have already installed the sdk toolkit. Now i am trying to make the plugin but i haven’t managed to .

i changed the makek file as following:

Define installation location for CUDA and compilation flags compatible

with the CUDA include files.

CUDAHOME = /usr/local/cuda
SDK_HOME = /home/$(USER)/NVIDIA_CUDA_SDK

INCLUDEDIR = -I$(CUDAHOME)/include -I$(SDK_HOME)/common/inc
INCLUDELIB = -L$(CUDAHOME)/lib -lcufft -lcudart -Wl,-rpath,$(CUDAHOME)/lib

CFLAGS = -fPIC -D_GNU_SOURCE -pthread -fexceptions
COPTIMFLAGS = -O3 -funroll-loops -msse2

Define installation location for MATLAB.

export MATLAB = /home/dimitris/MATLAB
#export MATLAB = /Applications/MATLAB_R2007b
MEX = $(MATLAB)/bin/mex
MEXEXT = .$(shell $(MATLAB)/bin/mexext)

nvmex is a modified mex script that knows how to handle CUDA .cu files.

NVMEX = ./nvmex

List the mex files to be built. The .mex extension will be replaced with the

appropriate extension for this installation of MATLAB, e.g. .mexglx or

.mexa64.

MEXFILES = fft2_cuda.mex
fft2_cuda_sp_dp.mex
ifft2_cuda.mex
Szeta.mex

all: $(MEXFILES:.mex=$(MEXEXT))

clean:
rm -f $(MEXFILES:.mex=$(MEXEXT))

.SUFFIXES: .cu .cu_o .mexglx .mexa64 .mexmaci

.c.mexglx:
$(MEX) CFLAGS=‘$(CFLAGS)’ COPTIMFLAGS=‘$(COPTIMFLAGS)’ $<
$(INCLUDEDIR) $(INCLUDELIB)

.cu.mexglx:
$(NVMEX) -f nvopts.sh $< $(INCLUDEDIR) $(INCLUDELIB)

.c.mexa64:
$(MEX) CFLAGS=‘$(CFLAGS)’ COPTIMFLAGS=‘$(COPTIMFLAGS)’ $<
$(INCLUDEDIR) $(INCLUDELIB)

.cu.mexa64:
$(NVMEX) -f nvopts.sh $< $(INCLUDEDIR) $(INCLUDELIB)

.c.mexmaci:
$(MEX) CFLAGS=‘$(CFLAGS)’ COPTIMFLAGS=‘$(COPTIMFLAGS)’ $<
$(INCLUDEDIR) $(INCLUDELIB)

.cu.mexmaci:
$(NVMEX) -f nvopts.sh $< $(INCLUDEDIR) $(INCLUDELIB)

And the error i get:

dimitris@soxp37148c:~/Desktop/Matlab_Cuda_1.1> make
./nvmex -f nvopts.sh Szeta.cu -I/usr/local/cuda/include -I/home/dimitris/NVIDIA_CUDA_SDK/common/inc -L/usr/local/cuda/lib64 -lcufft -lcudart -Wl,-rpath,/usr/local/cuda/lib64
./nvmex: line 1412: .: nvopts.sh: file not found
./nvmex: line 1425: .: nvopts.sh: file not found
./nvmex: line 931: -c: command not found

mex: compile of 'Szeta.cu' failed.

make: *** [Szeta.mexa64] Error 1
dimitris@soxp37148c:~/Desktop/Matlab_Cuda_1.1> make
./nvmex -f nvopts.sh Szeta.cu -I/usr/local/cuda/include -I/home/dimitris/NVIDIA_CUDA_SDK/common/inc -L/usr/local/cuda/lib -lcufft -lcudart -Wl,-rpath,/usr/local/cuda/lib
./nvmex: line 1412: .: nvopts.sh: file not found
./nvmex: line 1425: .: nvopts.sh: file not found
./nvmex: line 931: -c: command not found

mex: compile of 'Szeta.cu' failed.

make: *** [Szeta.mexa64] Error 1

Try this other method.
Generate an object file with nvcc, use the standard mex to link the right libraries.

From inside Matlab:

!nvcc -c SZeta.cu -Xcompiler -fPIC -I /usr/local/matlab/extern/include

mex SZeta.o -L /usr/local/cuda/lib64 -lcudart -lcufft

I open Matlab and i wrote :

!nvcc -c SZeta.cu -Xcompiler -fPIC -I /home/dimitris/MATLAB/extern/include

and i got:

gcc: SZeta.cu: No such file or directory

gcc: warning: ‘-x c++’ after last input file has no effect

gcc: no input files

You need to be in the directory where the file is located.

I am…

Sorry ,
everything it ok. spelling mistake. You had SZeta and it was Szeta. Thank you anyway.
Now if i want to write something do i have to do the same each time?
Have you any idea why it could’n be done with the makefile? Have you done it via the makefile? if so is it possible to send it to me ?

Thank you anyway for your help

The error is probably that you don’t have the directory in your PATH variable, change nvopts.sh to ./nvopts.sh and it should work…