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?
Hi
We have recently acquired an NVIDIA Tesla s2050 device for image processing
at work.
I have used PyOpenCL before on my laptop and know the basics. After
installing PyOpenCL on the host server (hosting the s2050 device)
successfully I get the following result when trying to create a context:
Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41)
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyopencl as cl
>>> cl.create_some_context()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.6/dist-packages/pyopencl/__init__.py", line
327, in create_some_context
platforms = get_platforms()
pyopencl.LogicError: clGetPlatformIDs failed: invalid/unknown error code
As a sanity check I installed PyCUDA as well on the same machine and again I
get an error:
Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41)
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pycuda.autoinit
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File
"/usr/local/lib/python2.6/dist-packages/pycuda-0.94.2-py2.6-linux-x86_64.egg/pycuda/autoinit.py",
line 4, in <module>
cuda.init()
pycuda._driver.RuntimeError: cuInit failed: no device
Does anyone know what else I can try, other than installing the latest
NVIDIA development drivers and the latest CUDA toolkit? (which I have done)
Riaan
Hey guys,
I'm trying to pass a structure to PyOpenCL (using the struct module and the
pack routine) but everytime i try to pass it as an arguement I get invalid
arg size error.
I've coded up an example which fails in this way
https://github.com/enjalot/adventures_in_opencl/blob/master/experiments/str…
what am I missing?
also, the struct in this example is 16bytes on most machines, what if i just
do "ffi" (12 bytes), do i need to pad it on the python side? I was a bit
confused about the struct module documentation on alignment
--
Ian Johnson
http://enja.org
Dnia 2011-03-20 06:04 Andreas Kloeckner napisał(a):
>Hi Nithin, Bryan, all,
>
>On Wed, 23 Feb 2011 01:00:05 +0530, nithin s <nithin19484(a)gmail.com> wrote:
>> Wow.. thats quite a bit of work. .. though I must admit on first
>> inspection of the kernel code it was evident that as the kernel goes
>> up and down tree there is a great deal of waiting.
>>
>> Any how I don't quite have the energy to get another version working
>> in the near future. I'm leaving it to the community to use the code or
>> not.
>
>Thanks very much for submitting this code.
>
>PyCUDA and PyOpenCL now both have a scan implementation. I did not end
>up using your code, but instead I ended up stealing directly from
>thrust.
>
>http://documen.tician.de/pycuda/array.html#module-pycuda.scan
>http://documen.tician.de/pyopencl/array.html#module-pyopencl.scan
>
>The code for both is actually one and the same file, using 'glue' called
>py{opencl,cuda}._cluda...
>
I have looked briefly at the code.
Congratulations and sorry for my inability to finish it myself.
Does it mean that my changes (from branch scan-from-tomasz) is dead
and I can purge all those details form my memory and my notes?
Regards.
Tomasz Rybak.
Hi Nithin, Bryan, all,
On Wed, 23 Feb 2011 01:00:05 +0530, nithin s <nithin19484(a)gmail.com> wrote:
> Wow.. thats quite a bit of work. .. though I must admit on first
> inspection of the kernel code it was evident that as the kernel goes
> up and down tree there is a great deal of waiting.
>
> Any how I don't quite have the energy to get another version working
> in the near future. I'm leaving it to the community to use the code or
> not.
Thanks very much for submitting this code.
PyCUDA and PyOpenCL now both have a scan implementation. I did not end
up using your code, but instead I ended up stealing directly from
thrust.
http://documen.tician.de/pycuda/array.html#module-pycuda.scanhttp://documen.tician.de/pyopencl/array.html#module-pyopencl.scan
The code for both is actually one and the same file, using 'glue' called
py{opencl,cuda}._cluda...
Andreas
Is PyOpenCL Python 3 compatible?
I did a quick grep in the source for Python 3 and some comments indicate
some preparation. It would be cool to use pyopencl from within Blender which
is currently python 3.2 only
Thanks
--
Ian Johnson
http://enja.org
Hello.
I have compiled the latest version of PyOpenCL and it does not work:
$ python test_wrapper.py
Traceback (most recent call last):
File "test_wrapper.py", line 20, in <module>
import pyopencl.array as cl_array
File "/usr/lib/pymodules/python2.6/pyopencl/array.py", line 34, in
<module>
import pyopencl.elementwise as elementwise
File "/usr/lib/pymodules/python2.6/pyopencl/elementwise.py", line 33, in
<module>
from pyopencl.tools import context_dependent_memoize
File "/usr/lib/pymodules/python2.6/pyopencl/tools.py", line 35, in
<module>
import pyopencl.array as cl_array
AttributeError: 'module' object has no attribute 'array'
Problem does not occur in dbc087df471ec2adc8eb88a35f45ba3829c6d168,
but appears in ffee8b44e499f66782d13a9a8c7d1f875af2ebdb and is also
present in 37d22e29a57d49e0cccc796ee685241ca8798fe8.
Best regards.
Look at this example:
#test_map.py
import pyopencl as cl
import numpy as np
import numpy.linalg as la
ctx = cl.create_some_context()
queue = cl.CommandQueue(ctx)
ary = np.arange(3*4*5).reshape(3,4,5, order="C").astype(np.float32)
mf = cl.mem_flags
flags = mf.READ_WRITE | mf.COPY_HOST_PTR | mf.ALLOC_HOST_PTR
buf = cl.Buffer(ctx, flags, hostbuf = ary)
queue.finish()
ar2 = np.empty_like(ary)
cl.enqueue_read_buffer(queue, buf, ar2)
print la.norm(ary-ar2), ary.strides, ar2.strides
(ar3, e) = cl.enqueue_map_buffer(queue, buf, cl.map_flags.READ, 0,
ary.shape, ary.dtype, "C")
print la.norm(ary-ar3), ary.strides, ar3.strides
ary is created with C-order, enqueue_map_buffer is told to return in
C-order, but in fact it return in Fortran order. Changing order="C" to
order="F" during ary creation makes this example work.
--
Maxim