Hi,
I’m a newbie to cuda and trying to learn. I’m on Macbook pro with 8600Gs Nvidia and with CUDA 2.2 working (the examples are working including simpleCUBLAS). So I want to write a function in C and compile it to use it in Matlab as a .mexmaci. So I found some interesting guesses here ( http://forums.nvidia.com/index.php?showtop…amp;hl=mex+code ) and the unix file here ( http://developer.nvidia.com/object/matlab_cuda.html ), modified the makefile as follows:
[codebox]# Define installation location for CUDA and compilation flags compatible
with the CUDA include files.
CUDAHOME = /usr/local/cuda
INCLUDEDIR = -I$(CUDAHOME)/include
INCLUDELIB = -L$(CUDAHOME)/lib -lcuda -lcudart -lcufft -Wl,-rpath,$(CUDAHOME)/lib
CFLAGS = -Xcompiler -fPIC -D_GNU_SOURCE -pthread -fexceptions #-Xcompiler -pthread -fexceptions
COPTIMFLAGS = -O3 #-funroll-loops -msse2
Define installation location for MATLAB.
export MATLAB = /Applications/MATLAB_R2007b/
#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 = sgemm_cu.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)
[/codebox]
then saved the code in this thread (http://forums.nvidia.com/index.php?showtopic=69566&hl=mex+code) as sgemm_cu.c and tried compiling in matlab 7.5.0 but I get the error:
[codebox]>> unix ‘Make’
/Applications/MATLAB_R2007b//bin/mex CFLAGS=‘-Xcompiler -fPIC -D_GNU_SOURCE -pthread -fexceptions ’ COPTIMFLAGS=’-O3 ’ sgemm_cu.c \
-I/usr/local/cuda/include -L/usr/local/cuda/lib -lcuda -lcudart -lcufft -Wl,-rpath,/usr/local/cuda/lib
nvcc fatal : Unknown option ‘pthread’
mex: compile of ‘sgemm_cu.c’ failed.
Make: *** [sgemm_cu.mexmaci] Error 1
[/codebox]
So what did I do, I tried commenting out (yes I don’t know exactly what I’m doing) the part -pthread -fexceptions in the makefile and the file got compiled but then I tried using the compiled function and Matlab just crashes with no advice. So I decided to check the report to see what it was referring to and there’s some error regarding _cublasInit .
I checked if I had put cuda folder in the Set Path of matlab and it’s ok, so can somebody please help me out giving me a clue on where the error is?
thanks in advance
Francesco