使用CUDA和MATLAB的Makefile

时间:2015-04-17 06:07:25

标签: matlab cuda makefile

我试图在以下网址上运行源代码: https://code.google.com/p/deep-learning-faces/source/checkout

我在安装了MATLAB和CUDA 6的服务器上运行它,但是当我这样做时

make all 

它返回以下错误:

make: *** No rule to make target `fft2_cuda.mexa64', needed by `all'.  Stop.

Makefile的外观如下:

# 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 -lcufft -Wl,-rpath,$(CUDAHOME)/lib
CFLAGS      = -fPIC -D_GNU_SOURCE -pthread -fexceptions
COPTIMFLAGS = -O3 -funroll-loops -msse2

# Define installation location for MATLAB.
export MATLAB = /usr/local/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)

顺便说一下,做

which matlab

返回

/usr/local/bin/matlab

所以,我尝试将MATLAB目录更改为Makefile中的目录,但它也没有。

有人可以帮帮我吗?

2 个答案:

答案 0 :(得分:1)

fft_cuda文件是否构建了.c?我认为.SUFFIXES规范中缺少一部分。我认为它应该有效地简化Makefile:

# Everything up until the .SUFFIXES line is OK, but then:
.SUFFIXES: .c .cu $(MEXEXT)

.c$(MEXEXT):
    $(MEX) CFLAGS='$(CFLAGS)' COPTIMFLAGS='$(COPTIMFLAGS)' $< \
        $(INCLUDEDIR) $(INCLUDELIB)

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

答案 1 :(得分:1)

看起来该repo中的Matlab_Cuda_1.1 dir不包含Mathlab CUDA插件源。

可在此处找到它们的副本:https://code.google.com/p/projektarbeitcuda/source/browse/#svn%2Ftrunk%2Freference%2Fsrc%2FMatlab_CUDA_1.1

获取文件并将其放入Matlab_Cuda_1.1目录。

此外,在构建之前不要忘记检查并调整Makefile(CUDAHOME,MATLAB,MEX,MEXEXT)开头的路径,以便它们指向系统中的正确位置。