Keras无法使用theano后端进行编译

时间:2016-05-07 02:40:47

标签: python cuda theano keras

当我在keras文档中尝试编译示例时,我收到以下错误。

/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')

我在Ubuntu 16.04上。我正在使用从默认存储库安装的CUDA 7.5。我使用CUDA编译了一些我自己的cuda程序以及ArrayFire程序,所以我知道CUDA正在工作。

这是我试图编译的内容......

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'])

1 个答案:

答案 0 :(得分:7)

GCC 5.3和CUDA似乎存在问题。我必须在/usr/include/string.h中注释掉以下更改,现在它可以正常工作。

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