Day: November 16, 2016

CUDA compilation error

mkdir -p ./bin 
/usr/bin/nvcc -I/usr/include -O2 -Xcompiler -fPIC -o bin/out/ProgramCU.o src/pba/ProgramCU.cu -c
src/pba/ProgramCU.cu(131): warning: statement is unreachable

src/pba/ProgramCU.cu(131): warning: statement is unreachable

/usr/include/string.h: In function ‘void* __mempcpy_inline(void*, const void*, size_t)’:
/usr/include/string.h:652:42: error: ‘memcpy’ was not declared in this scope
   return (char *) memcpy (__dest, __src, __n) + __n;
                                          ^
src/pba/ProgramCU.cu: In member function ‘void CuTexImage::BindTexture(textureReference&)’:
src/pba/ProgramCU.cu:41:80: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘size_t {aka long unsigned int}’ [-Wformat=]
     if(sz > MAX_TEXSIZE) fprintf(stderr, "cudaBindTexture: %d > %d\n", sz , MAX_TEXSIZE); 
                                                                                ^
src/pba/ProgramCU.cu: In function ‘bool ProgramCU::ShuffleCameraJacobian(CuTexImage&, CuTexImage&, CuTexImage&)’:
src/pba/ProgramCU.cu:2199:76: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘size_t {aka long unsigned int}’ [-Wformat=]
         fprintf(stderr, "datasize way too big %d, %d+...\n", szjc, (szjc)/ MAX_TEXSIZE); 
                                                                            ^
src/pba/ProgramCU.cu:2199:76: warning: format ‘%d’ expects argument of type ‘int’, but argument 4 has type ‘size_t {aka long unsigned int}’ [-Wformat=]
makefile:49: recipe for target 'bin/out/ProgramCU.o' failed
make: *** [bin/out/ProgramCU.o] Error 1

Fix: open the makefile and replace:

NVCC_FLAGS = -I$(CUDA_INC_PATH) -O2 -Xcompiler -fPIC

with:

NVCC_FLAGS = -I$(CUDA_INC_PATH) -O2 -D_FORCE_INLINES -Xcompiler -fPIC

Source: https://github.com/BVLC/caffe/issues/4046