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?
Hello all,
I am having problems with running PyOpenCL on Ubuntu 10.04 x64. With
nvidia drivers "devdriver_3.2_linux_64_260.19.21" installed, it
compiled without any problems, but execution of examples/demo.py
fails:
Traceback (most recent call last):
File "demo.py", line 1, in <module>
import pyopencl as cl
File "/usr/local/lib/python2.6/dist-packages/pyopencl-0.92-py2.6-linux-x86_64.egg/pyopencl/__init__.py",
line 3, in <module>
import pyopencl._cl as _cl
ImportError: /usr/local/lib/python2.6/dist-packages/pyopencl-0.92-py2.6-linux-x86_64.egg/pyopencl/_cl.so:
undefined symbol: clEnqueueReadBufferRect
I tried to install beta OpenCL 1.1 drivers
("devdriver_3.1_linux_64_258.19_opencl1.1"), but had the same error
(in addition, PyCuda programs did not work too, failing to find
cuMemAllocPitch_v2). Does anyone know what am I missing?
Best regards,
Bogdan
Hi all,
I've just finished coding up support for reductions on CL arrays in
pyopencl. The code is in git, under pyopencl.reduction. (Yay!
Pretty much feature parity with PyCUDA!)
I wrote this code using the Mako [1] templating engine. Writing the same
code without a templating engine would have been significantly clumsier.
Now of course, this makes the reduction code depend on Mako. The
question now is how to handle this dependency. Several options exist:
-----------------------------------------------------------------------
1. Make it a 'hard' dependency, installed by setup.py.
2. Make it a 'soft' dependency--the reduction code will fail on import
with a usable error message alerting the user that he needs to install
Mako.
3. Try to eliminate the dependency on any particular templating engine
by rewriting the code.
-----------------------------------------------------------------------
I'd be grateful for your feedback.
Thanks,
Andreas
[1] http://www.makotemplates.org/
Hi Jan,
On Mon, 22 Nov 2010 09:04:03 +0100, "Meinke, Jan" <j.meinke(a)fz-juelich.de> wrote:
> I have a problem with PyOpenCL using the ATI Stream SDK 2.2. I have a
> double precision ndarray a. I'm casting it to single precision using
>
> a.astype(np.float32) before I transfer it to the device. If I allocate
> the buffer a_dev using the COPY_HOST_PTR flag and
> hostbuf=a.astype(np.float32) everything works fine, but if I first
> allocate memory and then use enqueue_write_buffer to transfer the
> data, the first couple of entries on the device contain junk. Starting
> with a_dev[4] (32 bit) or a_dev[8] (64 bit) everything is correct
> again. The problem occurs no matter if the device is a CPU or GPU. It
> does not show up with the NVIDIA SDK.
Are both the computation and the transfer in the same command queue? Are
you passing 'True' for is_blocking? (Alternatively--do you wait for the
write to complete?) Can you post sample code to reproduce?
HTH,
Andreas
HiNew to pyOpenCL, I am trying to do simple maths on Raster data (using the pyopencl demo.py as ref). The code executes and generates the output raster file but the output is all 0. I am thinking its got something to do with raster going into numpy.array not into prg.ndvi. Can anyone please help me on this. Thanks All. Umair
F=[]F.append('b3_ref.tif')F.append('b4_ref.tif')
# For image processingfrom math import *import numpyimport pyopencl as clfrom osgeo import gdal from osgeo import gdalnumericfrom osgeo.gdal_array import *from osgeo.gdalconst import *
# Set output file format driverdriver = gdal.GetDriverByName('GTiff')
# Set output files Projection parameterstmp = gdal.Open(F[0])geoT = tmp.GetGeoTransform()proJ = tmp.GetProjection()del tmp
a = numpy.array(LoadFile(F[0]))b = numpy.array(LoadFile(F[1]))
ctx = cl.create_some_context()queue = cl.CommandQueue(ctx)
mf = cl.mem_flagsa_buf = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=a)b_buf = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=b)dest_buf = cl.Buffer(ctx, mf.WRITE_ONLY, b.nbytes)
prg = cl.Program(ctx, """ __kernel void ndvi(__global const float *a, __global const float *b, __global float *c) { int gid = get_global_id(0); c[gid] = (b[gid] - a[gid])/(b[gid] + a[gid]) ; } """).build()
prg.ndvi(queue, a.shape, None, a_buf, b_buf, dest_buf)
ndvi = numpy.empty_like(a)cl.enqueue_read_buffer(queue, dest_buf, ndvi).wait()
out= OpenArray(ndvi)out.SetGeoTransform(geoT)out.SetProjection(proJ)# Write output NDVI image file with projection informationdriver.CreateCopy('ndvi.tif',out)
Hi,
Just wanted to let you know that I successfully compiled PyOpenCL using
the IBM OpenCL SDK for the Cell Broadband Engine. Examples including my
own code run fine. I used IBM XL C for OpenCL, V0.2 (technology preview)
Version: 00.02.0000.0001.
Jan
------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------
Forschungszentrum Juelich GmbH
52425 Juelich
Sitz der Gesellschaft: Juelich
Eingetragen im Handelsregister des Amtsgerichts Dueren Nr. HR B 3498
Vorsitzender des Aufsichtsrats: MinDirig Dr. Karl Eugen Huthmacher
Geschaeftsfuehrung: Prof. Dr. Achim Bachem (Vorsitzender),
Dr. Ulrich Krafft (stellv. Vorsitzender), Prof. Dr.-Ing. Harald Bolt,
Prof. Dr. Sebastian M. Schmidt
------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------
Hi,
In the mandelbrot example of the pyopencl source, a np.uint16 type is
passed "directly" to a kernel as a ushort const.
Is it possible to do the same thing with an opencl floatn vector type
instead of a ushort ?
If so what would be the corresponding numpy type ?
I have tried passing directly a numpy.array of size n without success
: I get a crash. That doesn't surprise me as it probably tries to pass
a pointer instead of a value...
Thanks.
David.
Hi Bogdan,
Thomas Fai, a student in a class [1] I'm co-teaching, and I just came up
with the following direct CL translation of the PyCUDA example for
PyFFT. Since parts of the translation might be difficult to guess for
users who aren't familiar with PyOpenCL, I thought it might be useful if
you could include this example on PyFFT's page as well (or,
alternatively, add it to the package).
Thanks again for PyFFT!
Andreas
[1] http://cs.nyu.edu/courses/fall10/G22.2945-001/index.html
For me enqueue_map_buffer() returns (MemoryMap, event) instead of (array,
event). Am I doing something wrong? Or perhaps the documentation is
outdated? PyOpenCl version is 0.92