andersbll / cudarray

CUDA-based NumPy
MIT License
233 stars 61 forks source link

Python compile failure #13

Closed karpathy closed 9 years ago

karpathy commented 9 years ago

Hi, thanks for putting this together it looks nice. I was trying to take it for a spin but python setup.py install failed with somewhat cryptic errors that I wasn't able to narrow down. I don't have a huge amount of experience with cython so I'm not sure where to look or where things went wrong. Copy-pasting the beginning of the error: (I'm on Ubuntu 12.04 with Python 2.7)

...
cythoning ./cudarray/wrap/array_data.pyx to ./cudarray/wrap/array_data.cpp

Error compiling Cython file:
------------------------------------------------------------
...
from libcpp cimport bool
cimport numpy as np

cdef extern from 'cudarray/common.hpp' namespace 'cudarray':
    ctypedef int bool_t;
                      ^
------------------------------------------------------------

cudarray/wrap/array_data.pxd:5:23: Syntax error in ctypedef statement

Error compiling Cython file:
------------------------------------------------------------
...
    @property
    def itemsize(self):
        return self.dtype.itemsize

cdef bool_t *bool_ptr(ArrayData a):
    ^
------------------------------------------------------------

cudarray/wrap/array_data.pyx:50:5: 'bool_t' is not a type identifier

Error compiling Cython file:
------------------------------------------------------------
...

cdef int *int_ptr(ArrayData a):
    return <int *> a.dev_ptr

cdef bool is_int(ArrayData a):
    ^
------------------------------------------------------------

cudarray/wrap/array_data.pyx:62:5: 'bool' is not a type identifier

Error compiling Cython file:
------------------------------------------------------------
...

cdef bool is_int(ArrayData a):
    return a.dtype == np.dtype('int32')

cdef bool is_float(ArrayData a):
    ^
------------------------------------------------------------

cudarray/wrap/array_data.pyx:66:5: 'bool' is not a type identifier

Error compiling Cython file:
------------------------------------------------------------
...
        self.dtype = dtype
        self.nbytes = size*dtype.itemsize
        self.owner = owner
        self.offset = offset
        if owner is None:
            cudaCheck(cudaMalloc(&self.dev_ptr, self.nbytes))
                                ^
------------------------------------------------------------

cudarray/wrap/array_data.pyx:16:33: Cannot take address of Python variable

Error compiling Cython file:
------------------------------------------------------------
...
        if owner is None:
            cudaCheck(cudaMalloc(&self.dev_ptr, self.nbytes))
        else:
            self.dev_ptr = owner.dev_ptr + offset*dtype.itemsize
        if np_data is not None:
            cudaCheck(cudaMemcpyAsync(self.dev_ptr, np.PyArray_DATA(np_data),
                                         ^
------------------------------------------------------------

cudarray/wrap/array_data.pyx:20:42: Cannot convert Python object to 'void *'

Error compiling Cython file:
------------------------------------------------------------
...
        if np_data is not None:
            cudaCheck(cudaMemcpyAsync(self.dev_ptr, np.PyArray_DATA(np_data),
                                      self.nbytes, cudaMemcpyHostToDevice))

    def to_numpy(self, np_array):
        cudaCheck(cudaMemcpy(np.PyArray_DATA(np_array), self.dev_ptr,
                                                           ^
------------------------------------------------------------

cudarray/wrap/array_data.pyx:24:60: Cannot convert Python object to 'void const *'

Error compiling Cython file:
------------------------------------------------------------
...
                             self.nbytes, cudaMemcpyDeviceToHost))
        return np_array

    def __dealloc__(self):
        if self.owner is None:
            cudaFree(self.dev_ptr)
                        ^
------------------------------------------------------------

cudarray/wrap/array_data.pyx:30:25: Cannot convert Python object to 'void *'

Error compiling Cython file:
------------------------------------------------------------
...
    def itemsize(self):
        return self.dtype.itemsize

cdef bool_t *bool_ptr(ArrayData a):
    return <bool_t *> a.dev_ptr
           ^
------------------------------------------------------------

cudarray/wrap/array_data.pyx:51:12: 'bool_t' is not a type identifier

Error compiling Cython file:
------------------------------------------------------------
...
cdef bool_t *bool_ptr(ArrayData a):
    return <bool_t *> a.dev_ptr

cdef float *float_ptr(ArrayData a):
    return <float *> a.dev_ptr
          ^
------------------------------------------------------------

cudarray/wrap/array_data.pyx:55:11: Python objects cannot be cast to pointers of primitive types

Error compiling Cython file:
------------------------------------------------------------
...
cdef float *float_ptr(ArrayData a):
    return <float *> a.dev_ptr

cdef int *int_ptr(ArrayData a):
    return <int *> a.dev_ptr
          ^
------------------------------------------------------------

cudarray/wrap/array_data.pyx:59:11: Python objects cannot be cast to pointers of primitive types
building 'cudarray.wrap.array_data' extension
andersbll commented 9 years ago

It looks like you are using an old version of Cython. CUDArray requires Cython >= 0.21. I'm surprised that you didn't get a proper error message as I thought the requirements in setup.py got checked.

Thank you for convnetjs - it's excellent for demonstrations! :)

karpathy commented 9 years ago

Doh, that worked just fine. If anyone else stumbles by here:

$ pip install -U cython

installed 0.22 for me, and then everything works fine. Thank you! (And glad you like convnetjs ;) )