Repository: Theano/Theano

Issue:
Cannot load libwarpctc.so
Even so `warp-ctc` root path provided by `ctc.root`, compilation will fail until `LD_LIBRARY_PATH` is set explicitly.

`('The following error happened while compiling the node', GpuConnectionistTemporalClassification{compute_grad=True}(GpuContiguous.0, /placeholder, /placeholder), '\n', 'libwarpctc.so: cannot open shared object file: No such file or directory')`


Discussion:
I just merged a PR that do some updates to the CTC code. Can you update to
the dev again and try without modifing LD_LIBRARY_PATH?

Also, can you give me your value of ctc.root and the output of "ls
YOUR_CTC_ROOT".

On Mon, Aug 14, 2017 at 8:54 AM reith <notifications@github.com> wrote:

> Even so warp-ctc root path provided by ctc.root, compilation will fail
> until LD_LIBRARY_PATH is set explicitly.
>
> ('The following error happened while compiling the node',
> GpuConnectionistTemporalClassification{compute_grad=True}(GpuContiguous.0,
> /placeholder, /placeholder), '\n', 'libwarpctc.so: cannot open shared
> object file: No such file or directory')
>
> —
> You are receiving this because you are subscribed to this thread.
> Reply to this email directly, view it on GitHub
> <https://github.com/Theano/Theano/issues/6304>, or mute the thread
> <https://github.com/notifications/unsubscribe-auth/AALC-4xr-7jzamXkUKpN7VgZbMpyHNPjks5sYENugaJpZM4O2U-3>
> .
>

Still happens.

```
$ python -c "import theano; print theano.config.ctc.root"
Using cuDNN version 5110 on context None
Mapped name None to device cuda: GeForce GTX 1080 Ti (0000:02:00.0)
/home/reith/deepspeech/warp-ctc/
```

```
/home/reith/deepspeech/warp-ctc/:
CMakeLists.txt  LICENSE  README.md  README.zh_cn.md  build  doc  include  src  tensorflow_binding  tests  torch_binding

/home/reith/deepspeech/warp-ctc/build:
CMakeCache.txt  CMakeFiles  Makefile  cmake_install.cmake  libwarpctc.so  test_cpu  test_gpu
```
Hello, @reith , could you run the following code in Python interpreter and post the result ?
```python
import theano.tensor.nnet.ctc as ctc
print(ctc.ctc_available())
print(ctc.ctc_available.path)
```
Hi,

```
>>> print(ctc.ctc_available())
True
>>> print(ctc.ctc_available.path)
/home/reith/deepspeech/warp-ctc/build

```
Ok, it's really weird.

Can you post the entire error message ? Also, as it's a compilation error, Theano should have write an output file (check for a line that starts with `You can find the C code in this temporary file: ...` in console output to get the output file path). Could you post this file as attachment ?
It's not a compilation error. It finely compiles against `libwarpctc` but It cannot be used later because It does not exist in library path. I cannot see where `ctc_available.path` is used, surely It must be added to LD_LIBRARY_PATH or provided by other means to theano.
Ok, I see.

`ctc_available.path` is used for compilation (`g++ -l<ctc_available.path> ...`), but indeed it's not automatically added to LD_LIBRARY_PATH later.

It may be an issue to resolve. @nouiz @abergeron ?

Resolving patch:
diff --git a/theano/gpuarray/ctc.py b/theano/gpuarray/ctc.py
--- a/theano/gpuarray/ctc.py
+++ b/theano/gpuarray/ctc.py
@@ -13,7 +13,7 @@
 from theano.tensor.nnet.ctc import ctc_available
 
 import os
-import os.path
+import sys
 from . import pygpu
 
 
@@ -54,6 +54,14 @@ def c_lib_dirs(self):
             lib_dirs += [ctc_available.path]
         return lib_dirs
 
+    def c_compile_args(self):
+        if ctc_available.path is not None:
+            if sys.platform != 'darwin' and ' ' in ctc_available.path:
+                return ['-Wl,-rpath,"' + ctc_available.path + '"']
+            else:
+                return ['-Wl,-rpath,' + ctc_available.path]
+        return []
+
     def c_libraries(self):
         return ["warpctc", "gpuarray"]
 
diff --git a/theano/tensor/nnet/ctc.py b/theano/tensor/nnet/ctc.py
--- a/theano/tensor/nnet/ctc.py
+++ b/theano/tensor/nnet/ctc.py
@@ -1,5 +1,6 @@
 from __future__ import (division, absolute_import, print_function)
 import os
+import sys
 import theano.tensor as T
 from theano import config
 from theano import gof
@@ -126,6 +127,14 @@ def c_lib_dirs(self):
             lib_dirs += [ctc_available.path]
         return lib_dirs
 
+    def c_compile_args(self):
+        if ctc_available.path is not None:
+            if sys.platform != 'darwin' and ' ' in ctc_available.path:
+                return ['-Wl,-rpath,"' + ctc_available.path + '"']
+            else:
+                return ['-Wl,-rpath,' + ctc_available.path]
+        return []
+
     def c_libraries(self):
         return ["warpctc"]
 


Test patch: