Hi,
I'm trying to access GL textures from pyopencl. Here is my test program:
import sys, os, pygame
from OpenGL.GL import *
sys.path.append("extern/pyopencl/build/lib.linux-x86_64-2.6")
import pyopencl
pygame.init()
screen = pygame.display.set_mode((1024, 768), pygame.HWSURFACE |
pygame.OPENGL | pygame.DOUBLEBUF)
if pyopencl.have_gl():
context = pyopencl.create_some_context()
tex = glGenTextures(1)
glBindTexture(GL_TEXTURE_2D, tex)
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 256, 256, 0, GL_RGBA,
GL_UNSIGNED_BYTE, None)
cltex = pyopencl.GLTexture(context, pyopencl.mem_flags.READ_ONLY,
GL_TEXTURE_2D, 0, tex, 2)
It fails with error:
Traceback (most recent call last):
File "cl.py", line 14, in <module>
cltex = pyopencl.GLTexture(context, pyopencl.mem_flags.READ_ONLY,
GL_TEXTURE_2D, 0, tex, 2)
pyopencl.LogicError: clCreateFromGLTexture2D failed: invalid context
I thought that the problem might be in pyopencl's context creation,
which doesn't take the GL context into account. I tried to fix it by
adding appropriate CL_GL_CONTEXT_KHR, CL_GLX_DISPLAY_KHR and
CL_CONTEXT_PLATFORM props to the context, but then I got another error
"pyopencl.LogicError: clCreateFromGLTexture2D failed: invalid value". I
can run kernels just fine with my setup, but this GL stuff won't work.
What am I doing wrong?
I wrote this patch to facilitate the creation of an OpenCL context with
GL sharing capabilities.
I add the function gl_context_properties() which tries to detect a valid
OpenGL context. If found, an array of cl context properties is returned.
The current operating system and respective flags are automatically
detected, so the programmer does not have to think about it.
I modified the function create_some_context to try to add those flags
when creating a new context. In other words, if you call
create_some_context inside a yet valid OpenGL context, a GL sharing
environment should be automatically created. (MAC NOT TESTED)
Let me know if you think this patch could be useful, critiques and
suggestions are well accepted :)
--
Paolo Simone Gasparello
Greetings,
I've encountered a handful of bugs which are to small to warrant their own
threads, so I'm lumping them together in this one.
* CL_DRIVER_VERSION is apparenly inaccessible — there is no corresponding
member in pyopencl.device_info.
* pyopencl.Kernel.set_arg has the wrong signature in the doc at
<http://documen.tician.de/pyopencl/runtime.html#pyopencl.Kernel.set_arg>:
set_arg(self, arg). It should be set_arg(self, index, arg), or something
similar.
* pyopencl.Kernel.set_args is apparently not available in 0.91.5, but it
isn't marked as new in 0.92 at
<http://documen.tician.de/pyopencl/runtime.html#pyopencl.Kernel.set_args>.
* pyopencl.kernel_work_group_info.COMPILE_WORK_GROUP_SIZE doesn't work (in
0.91.5, at least):
>>> update_E_kernel.get_work_group_info(cl.kernel_work_group_info.COMPILE_WORK_GROUP_SIZE,
>>> cl_device)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: No to_python (by-value) converter found for C++ type: class
std::vector<unsigned __int64,class std::allocator<unsigned __int64> >
Note that this is x64 Windows, and pyopencl is self-built using Boost
1.43.0.
Generally yours,
Roman.
Hello,
I'm probably being dense, but I can't quite figure out use shared memory in
PyOpenCL. I attempted to allocate a shared buffer using cl.buffer(),
specifying the size but no hostbuf argument. The compiler, however,
complains of bad arguments when attempting to invoke the kernel. Here is
basically what I'm doing:
sharedBuffer = cl.Buffer(ctx, mf.READ_WRITE, size = sharedSize)
__kernel void computeAttractionOpt( <a bunch of __global args>, __local
float * shared)
prgOpt.computeAttractionOpt(queue, <bunch of args>, sharedBuffer)
I'm clearly missing something, but am too new to PyOpenCL/OpenCL to catch
it. Thanks =)
-Zach
Hi,
>> I tried running the gl_interop_demo.py and hit a wall right away again:
>> Traceback (most recent call last):
>> File "gl_interop_demo.py", line 74, in <module>
>> initialize()
>> File "gl_interop_demo.py", line 34, in initialize
>> props = [(ctx_props.PLATFORM, plats[0]), (ctx_props.GL_CONTEXT_KHR,
>> AttributeError: type object 'context_properties' has no attribute 'GL_CONTEXT_KHR'
>>
>> Which is true, there is no such variable defined in the class. There is only platform, to_string and mro defined.
>
> Try uncommenting the cl_ext.h header include in
> src/wrapper/wrap_cl.hpp. I'm reluctant to do this by default yet because
> Nvidia doesn't seem to ship that header.
I added the include at the Mac Include section around line 14 and made sure that it really was included (by first adding a wrong file name and see the compile fail). The compile works, but the situation is the very same as described before. None of the GL_* variables are defined inside context_properties.
Anything more I could try?
Cheers,
Holger
hi,
I was playing around with pyopencl lately after having no success of getting pycuda to work on Mac OS X with 64 bit python. So far, I am quite satisfied with it and I found it as easy to use as pycuda but conceptually easier to grasp. I am a little underwhelmed with the examples provided though.
While playing around, I ported and improved upon a pycuda demo from the pycuda wiki [1]. I suggest adding it to the examples folder because it gives a very interactive possibility to feel the speed difference opencl can make.
It can be found as the branch named mandelbrot_demo in the the following git repository:
http://www.widelands.org/~sirver/code/pyopencl.git.
[1] http://wiki.tiker.net/PyCuda/Examples/Mandelbrot
Thanks for the great work. Pyopencl is wonderful work.
Stay tuned for anther email, this time with a problem :(.
Cheers,
Holger
----------------------------------------
Dipl.-Phys. Holger Rapp
Institut für Mess- und Regelungstechnik
Universität Karlsruhe (TH)
Engler-Bunte-Ring 21
76131 Karlsruhe, Germany
Geb. 40.32, Zi. 232, zweite Etage
Tel: +49 (0)721 / 608-2341
Fax: +49 (0)721 / 661874
Mail: Rapp(a)mrt.uka.de
Web: www.mrt.uni-karlsruhe.de
----------------------------------------
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi,
I am trying to understand how to work with pyopencl at the moment. First
step was installing OpenCL 1.0 ATI-Stream-v2.1 (145) for Linux 64bit
(Ubuntu 10.4).
Then I tried running the example on the front page, with more output to
check the results. What I got is the following:
(I reduced the arrays to 10, so it is more convenient to read)
#the random numbers
print a
[ 0.47965848 0.65881491 0.58329076 0.35741428 0.15876208 0.86317623
0.59547591 0.94181222 0.95227844 0.95763934]
print b
[ 0.01067493 0.36993611 0.75886482 0.44881606 0.28016761 0.28990912
0.9158904 0.20052643 0.17973194 0.1536222 ]
#results as calculated by the kernel of the example:
print a_plus_b
[ 0.49033341 0. 0. 0. 0. 0. 0.
0. 0. 0. ]
#and the real results
print a + b
[ 0.49033341 1.02875102 1.34215558 0.80623031 0.43892968 1.15308535
1.51136637 1.14233863 1.13201034 1.11126149]
I tried pyopencl 0.91.5 and 0.92 beta, both gave me similar results. Is
there something wrong with the example? Is there something wrong with my
installation? (narray.py also just gives me one row of ones and the rest
is filled with zeroes)
Thank you for your time,
Malte
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
iEYEARECAAYFAkxFteMACgkQZ2ILQVnPodDX4gCgy06DCpCWMj8rrd66dYMyTiOX
FJ4AoPF7dEHus7k54kR7Wl/BbXTYkaYP
=M3uj
-----END PGP SIGNATURE-----
Am 20.07.2010 05:17, schrieb Andreas Kloeckner:
>> 3) To test OpenGL interoperability I changed examples/gl_interop_demo.py:
>>
>> ---------------
>> diff --git a/examples/gl_interop_demo.py b/examples/gl_interop_demo.py
>> index dd4bf3e..4495804 100644
>> --- a/examples/gl_interop_demo.py
>> +++ b/examples/gl_interop_demo.py
>> [snip]
>> --------------------------
>>
>> I didn't know how to make these changes platform independent.
>>
> Mostly applied. Actually, I tried to piece together something
> platform-independent based on your and Paolo's comments--can you please
> test the version in git? I'm guessing I broke it, but I'd like to fix it
> back up as soon as possible.
>
>
The recent git version of PyOpenCl with gl_interop_demo.py now works
on my System (Win 7 64bit, Python 2.6, VS 2008, AMD 5870), tested
with 32 and 64 bit versions
Gregor
Hi all,
I recently gave a tutorial on PyOpenCL at SciPy'10 [1], and 'please get
rid of @$@#%@!! boost' was a rather frequent complaint. So I got to
work, and it turned out that shipping the required part of Boost is a
pretty reasonable proposition--with the shipped boost bits, the binary
image only grows from 1 meg to 1.4 megs. (The source tarball does grow
by about a meg, but I figure that's fine.) To repeat: no separate Boost
installation is required any more for the (soon-to-be-released--I know
I'm late) git version. Note that the install documentation hasn't been
updated to reflect this yet.
[1] http://conference.scipy.org/scipy2010/tutorials.html#gpus
Enjoy,
Andreas