Skip to content

Compiling with CUDA 5

phvu edited this page Mar 14, 2013 · 2 revisions

CUDA 5 came up with many differences from the older versions. This page describes the minimal steps in order to compile deepnet with CUDA 5. Probably it is not the optimal or canonical way, but following those steps is sufficient to make it work on Debian 32 bit.

Compiling cudamat

Open cudamat/Makefile and add a new line at the beginning of the file:

CUDA_LIB = '/usr/local/cuda-5.0/lib'

This is to specify the path to CUDA 5 library. Optionally, you can also specify the -gencode option to have CUDA code for different versions of CUDA architecture, but it is not strictly required. More information about -gencode can be found in the CUDA NVCC manual.

So your cudamat/Makefile file might end up like this:

CUDA_LIB = /usr/local/cuda-5.0/lib

cudamat:
	nvcc -O -gencode=arch=compute_10,code=sm_10 \
			-gencode=arch=compute_20,code=sm_20 \
			-gencode=arch=compute_30,code=sm_30 \
		--ptxas-options=-v --compiler-options '-fPIC' -o libcudamat.so --shared cudamat.cu cudamat_kernels.cu -lcublas -L$(CUDA_LIB)
	nvcc -O -gencode=arch=compute_10,code=sm_10 \
			-gencode=arch=compute_20,code=sm_20 \
			-gencode=arch=compute_30,code=sm_30 \
			--ptxas-options=-v --compiler-options '-fPIC' -o libcudalearn.so --shared learn.cu learn_kernels.cu -lcublas -L$(CUDA_LIB)


clean:
	rm *.linkinfo *.pyc *.so

Compiling cudamat_conv

Changes in C++ CUDA code

  • Find and replace cutil_inline.h by helper_cuda.h in all C++ files.
  • Find and replace cutilCheckMsg by getLastCudaError in all C++ files. The reason is in CUDA 5, the cutil library (which is not intended to be used outside NVIDIA SDK sample projects) has been re-organized in some helper classes.
  • Add #include <helper_image.h> into include/cudaconv2/conv_util.cuh and include/nvmatrix/nvmatrix.cuh. This is for MIN and MAX macros.
  • Optionally, you can change lines 30 to 34 of include/common/matrix.h to be like this:
#ifdef NUMPY_INTERFACE
#include <Python.h>
#include <arrayobject.h>
#endif
#include <matrix_funcs.h>

This is just to make sure Python.h is included first. However this is not mandatory.

Changes in Makefiles

  • Copy common-gcc-cuda-4.0.mk and name it common-gcc-cuda-5.0.mk. Open the new file with your favorite editor and make some changes:
  • On line 24:
SM_VERSIONS   := 10 11 12 13 20 21 30 35
  • Line 53, 54, 55:
LIBDIR     := $(ROOTDIR)/lib
COMMONDIR  := $(ROOTDIR)/samples/common
SHAREDDIR  := $(ROOTDIR)
  • Line 332 (just comment it):
#LIB += -lcutil_$(LIB_ARCH)$(LIBSUFFIX) -lshrutil_$(LIB_ARCH)$(LIBSUFFIX)
  • Open cudamat_conv/Makefiles and make some changes:
  • Line 19:
GENCODE_ARCH := -gencode=arch=compute_20,code=\\"sm_20,compute_20\\" -gencode=arch=compute_30,code=\\"sm_30,compute_30\\"
  • Line 30:
include common-gcc-cuda-5.0.mk
  • And the last step is to update paths specified in cudamat_conv/build.sh, like this:
#!/bin/sh

export CUDA_SDK_PATH=/usr/local/cuda-5.0/
export CUDA_INSTALL_PATH=/usr/local/cuda-5.0/
export PYTHON_INCLUDE_PATH=/usr/include/python2.6/
export NUMPY_INCLUDE_PATH=/usr/include/python2.6/numpy/
#export ATLAS_LIB_PATH=/usr/lib/atlas-base/atlas
make $*

Depending on your Python version, you might have different values for PYTHON_INCLUDE_PATH and NUMPY_INCLUDE_PATH.

If you installed CUDA 5 in some customized location ( /usr/local/cuda-5.0 in my case), then it is always useful to have a symbolic link /usr/local/cuda which links to /usr/local/cuda-5.0.

Now, you are ready to build the whole library with CUDA 5, as instructed in the INSTALL file.