I'm trying to access the memory associated with a GPUArray from within a
compiled extension built using Cython's memoryview feature. According to the
Cython documentation, it is possible to access C arrays using this feature;
however, when I attempt to do so using a GPUArray's pointer with a GPU (and
version of CUDA) that supports UVA, the extension segfaults. Does anyone have
any thoughts as to why this might be occurring?

Here is the Cython code for a sample extension that uses memoryviews:

cdef class Wrapper:
    cdef long n
    cdef void *ptr
    cdef double[:] view

    def __cinit__(self, unsigned long long addr, long n):
        self.n = n
        self.ptr = <void *>addr
        self.view = <double[:n]>self.ptr

    def __getitem__(self, int i):
        return self.view[i]

    def __setitem__(self, int i, double val):
        self.view[i] = val

When the above is compiled into an extension named my_ext using Cython 0.19.1
and Python 2.7.4 on Linux and passed the pointer associated with a numpy array 
of doubles
as follows, I can use it to access the array's contents:

import numpy as np
import my_ext
x = np.arange(10, dtype=np.double)
w = my_ext.Wrapper(x.ctypes.data, x.size)
print w[0]   # prints 0.0
w[0] = 100.0 
print w[0]   # prints 100.0

Attempting to do so with a GPUArray results in a segfault:

import pycuda.autoinit
import pycuda.gpuarray as gpuarray

x_gpu = gpuarray.arange(10, dtype=np.double)
w = my_ext.Wrapper(x.ptr, x.size)
print w[0]   # segfaults

I'm using pycuda 2013.1.1 built with CUDA 5.0.35.

-- 
Lev Givon
http://www.columbia.edu/~lev/
http://lebedov.github.com/

_______________________________________________
PyCUDA mailing list
[email protected]
http://lists.tiker.net/listinfo/pycuda

Reply via email to