Discussion:
[PyCUDA] Device memory pool
Graham Mills
2014-04-18 20:18:07 UTC
Permalink
Hi,

I am attempting to use a memory pool for some gpu array calculations, using PyCUDA 2013.1 with python 3.x and CUDA 5.5. The trouble is I can't find an appropriate integer type with which to call .allocate on a DeviceMemoryPool object. All numpy integers as well as the native python integer return the error:


Boost.Python.ArgumentError: Python argument types in
DeviceMemoryPool.allocate(numpy.uint32)
did not match C++ signature:
allocate(boost::shared_ptr<(anonymous namespace)::context_dependent_memory_pool<(anonymous namespace)::device_allocator> >, unsigned long)


I'm not entirely clear yet on how the device memory pool works; am I doing something wrong? Does the associated boost module not work with the unified python 3 integer type?

Thanks,
Graham
Andreas Kloeckner
2014-04-19 18:54:41 UTC
Permalink
Hi Graham,

Graham Mills <13gm10 at queensu.ca> writes:
> I am attempting to use a memory pool for some gpu array calculations,
> using PyCUDA 2013.1 with python 3.x and CUDA 5.5. The trouble is I
> can't find an appropriate integer type with which to call .allocate on
> a DeviceMemoryPool object. All numpy integers as well as the native
> python integer return the error:
>
>
> Boost.Python.ArgumentError: Python argument types in
> DeviceMemoryPool.allocate(numpy.uint32)
> did not match C++ signature:
> allocate(boost::shared_ptr<(anonymous namespace)::context_dependent_memory_pool<(anonymous namespace)::device_allocator> >, unsigned long)
>
> I'm not entirely clear yet on how the device memory pool works; am I
> doing something wrong? Does the associated boost module not work with
> the unified python 3 integer type?

I'm not sure that's it, as there are tests for DeviceMemoryPool in
PyCUDA's test suite [1], and they pass in Python 3. If you could try and
put together a minimal reproducer, I'd be happy to take a look.

Andreas

[1] https://github.com/inducer/pycuda/blob/master/test/test_driver.py#L343
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 810 bytes
Desc: not available
URL: <http://lists.tiker.net/pipermail/pycuda/attachments/20140419/c1c07f46/attachment.sig>
Graham Mills
2014-04-20 19:02:39 UTC
Permalink
Andreas,

Thanks for the quick reply.I was able to track that problem down to a syntax error, but I've run into a problem launching kernels on gpu arrays allocated from the device memory pool, as in the following code:

import numpy
import pycuda.autoinit
import pycuda.gpuarray as gpua
from pycuda.tools import DeviceMemoryPool as DMP

pool=DMP()

test=gpua.GPUArray((1,2),dtype=numpy.float32,allocator=pool.allocate)

print(test)

# [[ nan nan]]

print( int( test.gpudata))

# 30066083328

print( test.allocator)

# <bound method DeviceMemoryPool.allocate of <pycuda._driver.DeviceMemoryPool object at 0x2909e68>>

# attempting to launch a kernel returns an error
test.fill(3.)


The error I get is as follows (depending on the kernel and the way it is launched)

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.2/dist-packages/pycuda-2013.1.1-py3.2-linux-x86_64.egg/pycuda/gpuarray.py", line 516, in fill
value, self.gpudata, self.mem_size)
File "/usr/local/lib/python3.2/dist-packages/pycuda-2013.1.1-py3.2-linux-x86_64.egg/pycuda/driver.py", line 475, in function_prepared_async_call
arg_buf = pack(func.arg_format, *args)
struct.error: required argument is not an integer


Manually specifying the allocator in the same way with pycuda.driver.mem_alloc seems to work fine, though. Do you know what it might be?

Graham
________________________________________
From: Andreas Kloeckner [lists at informa.tiker.net]
Sent: Saturday, April 19, 2014 2:54 PM
To: Graham Mills; pycuda at tiker.net
Subject: Re: [PyCUDA] Device memory pool

Hi Graham,

Graham Mills <13gm10 at queensu.ca> writes:
> I am attempting to use a memory pool for some gpu array calculations,
> using PyCUDA 2013.1 with python 3.x and CUDA 5.5. The trouble is I
> can't find an appropriate integer type with which to call .allocate on
> a DeviceMemoryPool object. All numpy integers as well as the native
> python integer return the error:
>
>
> Boost.Python.ArgumentError: Python argument types in
> DeviceMemoryPool.allocate(numpy.uint32)
> did not match C++ signature:
> allocate(boost::shared_ptr<(anonymous namespace)::context_dependent_memory_pool<(anonymous namespace)::device_allocator> >, unsigned long)
>
> I'm not entirely clear yet on how the device memory pool works; am I
> doing something wrong? Does the associated boost module not work with
> the unified python 3 integer type?

I'm not sure that's it, as there are tests for DeviceMemoryPool in
PyCUDA's test suite [1], and they pass in Python 3. If you could try and
put together a minimal reproducer, I'd be happy to take a look.

Andreas

[1] https://github.com/inducer/pycuda/blob/master/test/test_driver.py#L343
Andreas Kloeckner
2014-07-19 04:02:12 UTC
Permalink
Dear Graham,

Graham Mills <13gm10 at queensu.ca> writes:
> Thanks for the quick reply.I was able to track that problem down to a syntax error, but I've run into a problem launching kernels on gpu arrays allocated from the device memory pool, as in the following code:
>
> import numpy
> import pycuda.autoinit
> import pycuda.gpuarray as gpua
> from pycuda.tools import DeviceMemoryPool as DMP
>
> pool=DMP()
>
> test=gpua.GPUArray((1,2),dtype=numpy.float32,allocator=pool.allocate)
>
> print(test)
>
> # [[ nan nan]]
>
> print( int( test.gpudata))
>
> # 30066083328
>
> print( test.allocator)
>
> # <bound method DeviceMemoryPool.allocate of <pycuda._driver.DeviceMemoryPool object at 0x2909e68>>
>
> # attempting to launch a kernel returns an error
> test.fill(3.)
>
>
> The error I get is as follows (depending on the kernel and the way it is launched)
>
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> File "/usr/local/lib/python3.2/dist-packages/pycuda-2013.1.1-py3.2-linux-x86_64.egg/pycuda/gpuarray.py", line 516, in fill
> value, self.gpudata, self.mem_size)
> File "/usr/local/lib/python3.2/dist-packages/pycuda-2013.1.1-py3.2-linux-x86_64.egg/pycuda/driver.py", line 475, in function_prepared_async_call
> arg_buf = pack(func.arg_format, *args)
> struct.error: required argument is not an integer
>
>
> Manually specifying the allocator in the same way with pycuda.driver.mem_alloc seems to work fine, though. Do you know what it might be?

Sorry for the extremely belated reply, but for the record, I am unable
to reproduce this issue.

Andreas
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 810 bytes
Desc: not available
URL: <http://lists.tiker.net/pipermail/pycuda/attachments/20140718/2efb9775/attachment.sig>
Loading...