Repository: Theano/Theano

Issue:
Error: arithmetic on a pointer to void
I am trying to train a Keras model on Mac OS X, and for some reason I end up with an error from Theano. The following error does not occur on Ubuntu, but occurs on Mac OS X:

```
Problem occurred during compilation with the command line below:
/usr/bin/clang++ -dynamiclib -g -O3 -fno-math-errno -Wno-unused-label -Wno-unused-variable -Wno-write-strings -march=haswell -DNPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION -m64 -fPIC -undefined dynamic_lookup -I/usr/local/lib/python2.7/site-packages/numpy/core/include -I/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/include/python2.7 -I/usr/local/lib/python2.7/site-packages/theano/gof -L/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib -fvisibility=hidden -o /Users/valencra/.theano/compiledir_Darwin-16.4.0-x86_64-i386-64bit-i386-2.7.13-64/tmpN8HLdA/c6acccb2fd68eac67ca5b0f0fb9ad9bb.so /Users/valencra/.theano/compiledir_Darwin-16.4.0-x86_64-i386-64bit-i386-2.7.13-64/tmpN8HLdA/mod.cpp
/Users/valencra/.theano/compiledir_Darwin-16.4.0-x86_64-i386-64bit-i386-2.7.13-64/tmpN8HLdA/mod.cpp:894:21: warning: comparison of array 'outputs' equal to a null pointer is always false [-Wtautological-pointer-compare]
                if (outputs == NULL) {
                    ^~~~~~~    ~~~~
/Users/valencra/.theano/compiledir_Darwin-16.4.0-x86_64-i386-64bit-i386-2.7.13-64/tmpN8HLdA/mod.cpp:919:54: error: arithmetic on a pointer to void
                                    PyArray_DATA(V3) + data_offset,
                                    ~~~~~~~~~~~~~~~~ ^
1 warning and 1 error generated.

Traceback (most recent call last):
  File "osr.py", line 351, in <module>
    osr.train_osr_model()
  File "osr.py", line 83, in train_osr_model
    nb_worker=1)
  File "/usr/local/lib/python2.7/site-packages/keras/engine/training.py", line 1454, in fit_generator
    self._make_train_function()
  File "/usr/local/lib/python2.7/site-packages/keras/engine/training.py", line 767, in _make_train_function
    **self._function_kwargs)
  File "/usr/local/lib/python2.7/site-packages/keras/backend/theano_backend.py", line 969, in function
    return Function(inputs, outputs, updates=updates, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/keras/backend/theano_backend.py", line 955, in __init__
    **kwargs)
  File "/usr/local/lib/python2.7/site-packages/theano/compile/function.py", line 326, in function
    output_keys=output_keys)
  File "/usr/local/lib/python2.7/site-packages/theano/compile/pfunc.py", line 486, in pfunc
    output_keys=output_keys)
  File "/usr/local/lib/python2.7/site-packages/theano/compile/function_module.py", line 1795, in orig_function
    defaults)
  File "/usr/local/lib/python2.7/site-packages/theano/compile/function_module.py", line 1661, in create
    input_storage=input_storage_lists, storage_map=storage_map)
  File "/usr/local/lib/python2.7/site-packages/theano/gof/link.py", line 699, in make_thunk
    storage_map=storage_map)[:3]
  File "/usr/local/lib/python2.7/site-packages/theano/gof/vm.py", line 1063, in make_all
    impl=impl))
  File "/usr/local/lib/python2.7/site-packages/theano/gof/op.py", line 924, in make_thunk
    no_recycling)
  File "/usr/local/lib/python2.7/site-packages/theano/gof/op.py", line 828, in make_c_thunk
    output_storage=node_output_storage)
  File "/usr/local/lib/python2.7/site-packages/theano/gof/cc.py", line 1190, in make_thunk
    keep_lock=keep_lock)
  File "/usr/local/lib/python2.7/site-packages/theano/gof/cc.py", line 1131, in __compile__
    keep_lock=keep_lock)
  File "/usr/local/lib/python2.7/site-packages/theano/gof/cc.py", line 1586, in cthunk_factory
    key=key, lnk=self, keep_lock=keep_lock)
  File "/usr/local/lib/python2.7/site-packages/theano/gof/cmodule.py", line 1155, in module_from_key
    module = lnk.compile_cmodule(location)
  File "/usr/local/lib/python2.7/site-packages/theano/gof/cc.py", line 1489, in compile_cmodule
    preargs=preargs)
  File "/usr/local/lib/python2.7/site-packages/theano/gof/cmodule.py", line 2304, in compile_str
    (status, compile_stderr.replace('\n', '. ')))
Exception: ('The following error happened while compiling the node', Split{4}(InplaceDimShuffle{1,0,2}.0, TensorConstant{2}, TensorConstant{(4,) of 256}), '\n', "Compilation failed (return status=1): /Users/valencra/.theano/compiledir_Darwin-16.4.0-x86_64-i386-64bit-i386-2.7.13-64/tmpN8HLdA/mod.cpp:894:21: warning: comparison of array 'outputs' equal to a null pointer is always false [-Wtautological-pointer-compare].                 if (outputs == NULL) {.                     ^~~~~~~    ~~~~. /Users/valencra/.theano/compiledir_Darwin-16.4.0-x86_64-i386-64bit-i386-2.7.13-64/tmpN8HLdA/mod.cpp:919:54: error: arithmetic on a pointer to void.                                     PyArray_DATA(V3) + data_offset,.                                     ~~~~~~~~~~~~~~~~ ^. 1 warning and 1 error generated.. ", '[*1 -> Split{4}(<TensorType(float32, 3D)>, TensorConstant{2}, TensorConstant{(4,) of 256}), *1::1, *1::2, *1::3]')
```

For reference, here is the script that I use to train the model: _https://github.com/valencra/Optical-Speech-Recognizer/blob/master/osr.py_

Please note that the error occurs when the function **osr.train_osr_model()** is called.



Discussion:
The problem seems to stem from installing Theano and Keras from their github repositories, like so:

```
pip install git+git://github.com/Theano/Theano.git
pip install git+git://github.com/fchollet/keras.git
```

I fixed it by uninstalling Theano and Keras, followed by installing them directly with pip:

```
pip uninstall Theano
pip uninstall keras
pip install Theano
pip install keras
```

There might have been issues with the bleeding edge versions of either Theano or Keras. Hope this helps others as well.
I'll reopen as this isn't fixed in the master of Theano. It should be fixed there.

Can you give me the output of:

g++ --version

and

clang --version

to help us understand why you have a problem, but not @abergeron on Mac.
**g++ --version** yields:
```
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/c++/4.2.1
Apple LLVM version 8.0.0 (clang-800.0.42.1)
Target: x86_64-apple-darwin16.4.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
```
**clang --version** yields:
```
Apple LLVM version 8.0.0 (clang-800.0.42.1)
Target: x86_64-apple-darwin16.4.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
```


Resolving patch:
diff --git a/theano/gpuarray/dnn.py b/theano/gpuarray/dnn.py
--- a/theano/gpuarray/dnn.py
+++ b/theano/gpuarray/dnn.py
@@ -1994,7 +1994,8 @@ def make_node(self, hidden_size, num_layers, ddesc, input_mode,
         hidden_size = as_i32(hidden_size)
         num_layers = as_i32(num_layers)
 
-        assert 5000 < version() < 5200, "Constants only work for cudnn 5, 5.1"
+        if version() < 5005:
+            raise RuntimeError("cudnn RNN require cudnn v5 final or higher.")
 
         if input_mode == 'linear':
             input_mode = as_i32(0)
diff --git a/theano/tensor/basic.py b/theano/tensor/basic.py
--- a/theano/tensor/basic.py
+++ b/theano/tensor/basic.py
@@ -3781,7 +3781,7 @@ def R_op(self, inputs, eval_points):
         return self.make_node(eval_points[0], *inputs[1:]).outputs
 
     def c_code_cache_version(self):
-        return (1,)
+        return (2,)
 
     def c_support_code(self):
         return """
@@ -3897,7 +3897,7 @@ def c_code(self, node, name, inputs, outputs, sub):
                                     ndim, split_dims,
                                     %(x_typenum)s,
                                     PyArray_STRIDES(%(x)s),
-                                    PyArray_DATA(%(x)s) + data_offset,
+                                    PyArray_BYTES(%(x)s) + data_offset,
                                     %(x_itemsize)s,
                                     PyArray_FLAGS(%(x)s),
                                     NULL);


Test patch: