Repository: Theano/Theano

Issue:
 libcuda_ndarray.so: cannot open shared object file 
I was trying to get the theano up and running on computation grid and I always got following error after import

```
>>> import theano
    ....
    libcuda_ndarray.so: cannot open shared object file 
```

After some googling I found following thread on google groups:
https://groups.google.com/forum/#!msg/theano-users/F0AuGH3g1CY/Sm0Rphqbp_8J

The issue is on Linux if `config.compiledir` flag contains colon (:) character. The compiler then cannot find the correct location of the compiled library. In my case it was really obscure bug, as the `%(platform)s-%(processor)s` substitution keys from `config.compiledir_format` contained colon as part of the grid's platform description.

The workaround is easy - set the compiledir to some safe value.
The fix should be easy as well, just sanitize the compiledir path.



Discussion:
Thanks for the report. We are pretty busy, do you want to contribute this
to Theano?

On Tue, Dec 1, 2015 at 4:53 AM, sutr90 notifications@github.com wrote:

> I was trying to get the theano up and running on computation grid and I
> always got following error after import
> 
> > > > import theano
> > > >     ....
> > > >     libcuda_ndarray.so: cannot open shared object file
> 
> After some googling I found following thread on google groups:
> https://groups.google.com/forum/#!msg/theano-users/F0AuGH3g1CY/Sm0Rphqbp_8J
> 
> The issue is on Linux if config.compiledir flag contains colon (:)
> character. The compiler then cannot find the correct location of the
> compiled library. In my case it was really obscure bug, as the
> %(platform)s-%(processor)s substitution keys from config.compiledir_format
> contained colon as part of the grid's platform description.
> 
> The workaround is easy - set the compiledir to some safe value.
> The fix should be easy as well, just sanitize the compiledir path.
> 
> —
> Reply to this email directly or view it on GitHub
> https://github.com/Theano/Theano/issues/3711.

Okay, I will try to do the necessary changes in upcoming week. I will let you know here on the progress.

Thanks!
Le 2015-12-12 11:22 AM, "sutr90" notifications@github.com a écrit :

> Okay, I will try to do the necessary changes in upcoming week. I will let
> you know here on the progress.
> 
> —
> Reply to this email directly or view it on GitHub
> https://github.com/Theano/Theano/issues/3711#issuecomment-164164901.

Hi @sutr90,

Are you still working on it? Can I take this up?

Hello @mronian,
sadly I haven't started yet. Feel free to fix it. ;)

@sutr90 Could you tell me how to reproduce the error on my local machine?

There probably isn't an easy way to test it without mocking the environment. The problem in my case was on the grid computer. The call to `platfom.platform()` returned string with colon in it.

The relevant code is in https://github.com/Theano/Theano/blob/master/theano/gof/compiledir.py the relevant function is the `short_platform`@71 and the dictionary `compiledir_format_dict`. I think that the contents of this dictionry should be stripped of platform specific prohibied characters (eg. ?/*:).

So the fix could be as easy as changing the return value of `short_platform` function.

For example:

```
return p.replace(':','-')
```


Resolving patch:
diff --git a/theano/gof/compiledir.py b/theano/gof/compiledir.py
--- a/theano/gof/compiledir.py
+++ b/theano/gof/compiledir.py
@@ -142,6 +142,11 @@ def short_platform(r=None, p=None):
     sr = '-'.join(sp)
     p = p.replace(r, sr)
 
+    p = p.replace(':', '-')
+    p = p.replace('?', '-')
+    p = p.replace('*', '-')
+    p = p.replace('/', '-')
+
     return p
 compiledir_format_dict['short_platform'] = short_platform()
 compiledir_format_keys = ", ".join(sorted(compiledir_format_dict.keys()))


Test patch: