Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keras failed to compile with theano backend

I get the following error when I try the compile the example in the keras documentation.

/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;
                                          ^
ERROR (theano.sandbox.cuda): Failed to compile cuda_ndarray.cu: ('nvcc return status', 1, 'for cmd', 'nvcc -shared -O3 -m64 -Xcompiler -DCUDA_NDARRAY_CUH=mc72d035fdf91890f3b36710688069b2e,-DNPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION,-fPIC,-fvisibility=hidden -Xlinker -rpath,/home/chase/.theano/compiledir_Linux-4.4--generic-x86_64-with-Ubuntu-16.04-xenial-x86_64-3.5.1+-64/cuda_ndarray -I/usr/local/lib/python3.5/dist-packages/theano/sandbox/cuda -I/usr/lib/python3/dist-packages/numpy/core/include -I/usr/include/python3.5m -I/usr/local/lib/python3.5/dist-packages/theano/gof -o /home/chase/.theano/compiledir_Linux-4.4--generic-x86_64-with-Ubuntu-16.04-xenial-x86_64-3.5.1+-64/cuda_ndarray/cuda_ndarray.so mod.cu -L/usr/lib -lcublas -lpython3.5m -lcudart')

I am on Ubuntu 16.04. I am using CUDA 7.5 which I installed from the default repositories. I have used the CUDA to compile some of my own cuda programs as well as ArrayFire programs so I know CUDA is working.

Here is what I tried to compile...

from keras.models import Sequential

model = Sequential()
from keras.layers.core import Dense, Activation

model.add(Dense(output_dim=64, input_dim=100))
model.add(Activation("relu"))
model.add(Dense(output_dim=10))
model.add(Activation("softmax"))

model.compile(loss='categorical_crossentropy', optimizer='sgd', metrics=['accuracy'])
like image 912
chasep255 Avatar asked Mar 12 '23 09:03

chasep255


1 Answers

It appears there is an issue with GCC 5.3 and CUDA. I had to comment out the following changes in /usr/include/string.h and now it works.

https://fossies.org/diffs/glibc/2.22_vs_2.23/string/string.h-diff.html

like image 188
chasep255 Avatar answered Mar 19 '23 06:03

chasep255