ktaletsk / CuCalc

CUDA + CoCalc Docker container
34 stars 11 forks source link

fatal error: cudnn.h: No such file or directory #2

Open billpage opened 6 years ago

billpage commented 6 years ago

The following test for GPU functionality from the Theano tutorial:

import os
os.environ["MKL_THREADING_LAYER"] = "GNU"
os.environ["THEANO_FLAGS"] = "device=cuda,floatX=float32"
from theano import function, config, shared, tensor
import numpy
import time

vlen = 10 * 30 * 768  # 10 x #cores x # threads per core
iters = 1000

rng = numpy.random.RandomState(22)
x = shared(numpy.asarray(rng.rand(vlen), config.floatX))
f = function([], tensor.exp(x))
print(f.maker.fgraph.toposort())
t0 = time.time()
for i in range(iters):
    r = f()
t1 = time.time()
print("Looping %d times took %f seconds" % (iters, t1 - t0))
print("Result is %s" % (r,))
if numpy.any([isinstance(x.op, tensor.Elemwise) and
              ('Gpu' not in type(x.op).__name__)
              for x in f.maker.fgraph.toposort()]):
    print('Used the cpu')
else:
    print('Used the gpu')

Produces an error message:

Can not use cuDNN on context None: cannot compile with cuDNN. We got this error:
/tmp/try_flags_cgM6mq.c:4:19: fatal error: cudnn.h: No such file or directory
 #include <cudnn.h>
                   ^
compilation terminated.

Mapped name None to device cuda: GeForce GTX 980 Ti (0000:01:00.0)

Although the output indicates that the GPU was in fact used during the execution

[GpuElemwise{exp,no_inplace}(<GpuArrayType<None>(float32, vector)>), HostFromGpu(gpuarray)(GpuElemwise{exp,no_inplace}.0)]
Looping 1000 times took 1.333771 seconds
Result is [ 1.23178029  1.61879349  1.52278066 ...,  2.20771813  2.29967761
  1.62323296]
Used the gpu
billpage commented 6 years ago

Work-round:

Create a file named .theanorc in the project directory with the following contents:

[global]
floatX = float32
device = cuda

[dnn]
include_path=/usr/local/cuda/include/
library_path=/usr/local/cuda/lib64/
ktaletsk commented 6 years ago

@billpage I just had the same error when testing Theano and adding .theanorc helps. cuDNN is installed in a weird location. Need to find the way to preload .theanorc to the project folders.