Re: [PyOpenCL] Complex number arrays in OpenCL
by gwenael.guillaume＠ifsttar.fr

Hi Bodgan,
Thank you very much for your response.
If I understand well, I have to introduce '#include <pyopencl-complex.h>' in order to deal with complex arrays.
I have reordered the input complex multidimensional array as:
__constant float2 mat[][18] = {{(float2)(1.0f,0.0f), (float2)(1.0f,0.0f), (float2)(0.0f,0.0f), (float2)(0.0f,0.0f), (float2)(0.0f,0.0f), (float2)(0.0f,0.0f), (float2)(0.0f,0.0f), (float2)(0.0f,0.0f),
(float2) (0.0f,0.0f), (float2)(0.0f,0.0f), (float2)(0.0f,0.0f), (float2)(0.0f,0.0f), (float2)(0.0f,0.0f), (float2)(0.0f,0.0f), (float2)(0.0f,0.0f), (float2)(0.0f,0.0f),
(float2)(0.0f,0.0f), (float2)(0.0f,0.0f)},
{(float2)(3.0f,0.0f), (float2)(634.6f,0.0f), (float2)(0.0000000108775f,0.0f), (float2)(-348507f,0.0f), (float2)(0.000000164791f,0.0f), (float2)(0.000000-259223f,0.0f),
(float2)(0.000000121102f,0.0f), (float2)(240068f,0.0f), (float2)(0.72992f,0.0f), (float2)(166.082f,0.0f), (float2)(853.389f,0.0f), (float2)(1010.26f,0.0f),
(float2)(1341.72f,0.0f), (float2)(4030.4f,0.0f), (float2)(681.581f,15292.9f), (float2)(1708.44f,8400.45f), (float2)(439.62f,0.0f), (float2)(0.00000421131f,0.0f)}
};
I get the following errors:
- error: expected a ")
- error: expression must have a constant value
- error: expected a "}"
Am I doing something wrong in the definition of the array?
Kind regards,
Gwenaël
----- Mail original -----
> De: "Bogdan Opanchuk" <mantihor(a)gmail.com>
> À: "gwenael guillaume" <gwenael.guillaume(a)ifsttar.fr>
> Cc: "Pyopencl" <pyopencl(a)tiker.net>
> Envoyé: Mercredi 21 Mai 2014 09:41:18
> Objet: Re: [PyOpenCL] Complex number arrays in OpenCL
>
> Hi Gwenael,
>
> A common approach is to use `float2`/`double2` types on the OpenCL
> side and the corresponding numpy types `complex64`/`complex128`. The
> C
> types are structures with fields 'x' and 'y' of the corresponding
> floating point type. Unfortunately, there are no functions available
> in OpenCL itself that would treat these structures as complex
> numbers,
> and even the operators are intended for a different usage: `float2` *
> `float2` is not available, and `float2` + `float` adds the second
> argument to both `x` and `y` fields. But PyOpenCL has a header file
> with such functions defined, see
> https://github.com/pyopencl/pyopencl/blob/master/pyopencl/cl/pyopencl-com...
>
> Best regards,
> Bogdan
>
> On Wed, May 21, 2014 at 4:51 PM, <gwenael.guillaume(a)ifsttar.fr>
> wrote:
> > Hi,
> >
> > I am trying to translate a numpy array with complex numbers built
> > in the
> > Python part of my code into an array for its OpenCL part. Here is
> > the array
> > I obtain :
> > mat={{1f, 1f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f,
> > 0.f, 0.f,
> > 0.f, 0.f, 0.f, 0.f}, {3f, 634.6002f, 10877545.202f, -348506.5055f,
> > 1647910.5651f, -2592227.8312f, 1211024.4768f, 240068.1321f,
> > 0.72992f,
> > 166.0818f, 853.3891f, 1010.2639f, 1341.7248f, 4030.3953f,
> > (681.5814f,15292.8529f), (1708.439f,8400.4467f), 439.62f,
> > 0.0000421131454702f}};
> >
> > The complex numbers are the items in brackets (real part, imaginary
> > part). I
> > wonder if it is the good way for introducing complex numbers in
> > OpenCL.
> >
> > When treating an array without complex numbers, I call the array in
> > the
> > OpenCL script like this:
> > __constant float* arr = &(mat[matIndex][2]);
> > I do not find how to call such an array if it contains complex
> > numbers.
> >
> > Besides, I have to use special functions (as exponential for
> > instance) on
> > this array. Does the function exp can deal with complex numbers?
> >
> > GGUILLAUME
> >
> >
> > _______________________________________________
> > PyOpenCL mailing list
> > PyOpenCL(a)tiker.net
> > http://lists.tiker.net/listinfo/pyopencl
> >
>
5 years, 6 months

Complex number arrays in OpenCL
by gwenael.guillaume＠ifsttar.fr

Hi,
I am trying to translate a numpy array with complex numbers built in the Python part of my code into an array for its OpenCL part. Here is the array I obtain :
mat={{1f, 1f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f}, {3f, 634.6002f, 10877545.202f, -348506.5055f, 1647910.5651f, -2592227.8312f, 1211024.4768f, 240068.1321f, 0.72992f, 166.0818f, 853.3891f, 1010.2639f, 1341.7248f, 4030.3953f, (681.5814f,15292.8529f), (1708.439f,8400.4467f), 439.62f, 0.0000421131454702f}} ;
The complex numbers are the items in brackets (real part, imaginary part). I wonder if it is the good way for introducing complex numbers in OpenCL.
When treating an array without complex numbers, I call the array in the OpenCL script like this:
__constant float* arr = &(mat[matIndex][2]);
I do not find how to call such an array if it contains complex numbers.
Besides, I have to use special functions (as exponential for instance) on this array. Does the function exp can deal with complex numbers?
GGUILLAUME
5 years, 6 months

Re: [PyOpenCL] pillow images as USE_HOST_PTR hostbuf?
by CRV§ADER//KY

Hi Andreas,
sorry to pester - any news on this?
On 14 April 2014 08:25, CRV§ADER//KY <crusaderky(a)gmail.com> wrote:
> import pyopencl as cl
> from PIL import Image
>
> src = Image.open("test.jpg").convert('RGBA')
>
> ctx = cl.create_some_context()
> fmt = cl.ImageFormat(cl.channel_order.RGBA, cl.channel_type.UNORM_INT8)
>
> src_buf = cl.Image(ctx,
> flags=cl.mem_flags.READ_ONLY | cl.mem_flags.USE_HOST_PTR,
> format=fmt,
> shape=src.size,
> hostbuf=src
> )
>
>
>
> On 14 April 2014 07:34, CRV§ADER//KY <crusaderky(a)gmail.com> wrote:
>
>> It is in one of the messages above already
>> On 14 Apr 2014 01:55, "Andreas Kloeckner" <lists(a)informa.tiker.net>
>> wrote:
>>
>>> "CRV§ADER//KY" <crusaderky(a)gmail.com> writes:
>>> > sorry for the long wait.
>>> > ...nope, still doesn't work; same error as before.
>>>
>>> Can you send some self-contained code to reproduce this? That would help
>>> me get this working.
>>>
>>> Andreas
>>>
>>
>
5 years, 7 months

Re: [PyOpenCL] Barrier don't work
by CRV§ADER//KY

barrier only works inside a workgroup. You can't synchronize different
workgroups.
You left the workgroup size to None, which means that you're asking the
scheduler to try and figure out the optimal one for you. Which is almost
universally bad for performance, but in your case, it breaks functionality.
I see that A is populated correctly for:
a[2] = c[2] = 6
a[4] = c[4] = 9
a[6] = c[6] = 12
...which leads me to believe that your workgroup size is 2.
Also, what's N and N2?
Finally, nothing guarantees that get_global_id(0) won't overshoot N. If N =
10 (as I desume) and group size = 32 (typical for NVidia) or 64 (typical
for AMD GPU), you'll have plenty of workers writing out of bounds. You must
pass N as a parameter and add
if (gid >= N) {
return;
}
at the beginning of your kernel.
In your case, I think the scheduler decided to "play safe", since it can't
know if you implemented such safety in your code, and set the workgroup
size to 2 (the only power of 2 that evenly divides 10) so that you wouldn't
risk the above problem.
Cheers
Guido
On 13 May 2014 20:09, Franco Nicolas Bellomo <fnbellomo(a)gmail.com> wrote:
> Hi, I'm Franco, I'm study physic in Argentina and I'm new in PyOpenCl word.
>
> My problem in when I use barrier. This is my kernel:
>
> b_dev = cl.array.arange(queue, N2, dtype=np.float32)
> b_new_dev = cl.array.zeros(queue, N2, dtype=np.float32)
> a_dev = cl.array.zeros(queue, N2, dtype=np.float32)
>
> #kernel
> prg = cl.Program(ctx, """
> __kernel void twice(__global float *a, __global float *b, __global
> float *c)
> {
> int gid = get_global_id(0);
>
> __local float a_local[17];
>
> a_local[gid + 1] = b[gid] + b[gid + 1] + b[gid + 2];
> c[gid + 1] = a_local[gid + 1];
> barrier(CLK_LOCAL_MEM_FENCE);
> a[gid] = a_local[gid];
> }
> """).build()
> twice = prg.twice
>
> twice(queue, (N,), None, a_dev.data, b_dev.data, b_new_dev.data)
>
> print " b\n %s\n\n c\n %s\n vector A donde copio\n %s" %(b_dev,
> b_new_dev, a_dev)
>
>
> And generated this output:
>
> b
> [ 0. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11.]
>
> c
> [ 0. 3. 6. 9. 12. 15. 18. 21. 24. 27. 30. 0.]
> vector A donde copio
> [ 1.65503965e-24 4.59149455e-41 6.00000000e+00 4.59149455e-41
> 1.20000000e+01 0.00000000e+00 1.80000000e+01 0.00000000e+00
> 2.40000000e+01 0.00000000e+00 0.00000000e+00 0.00000000e+00
>
> Why the last vector is different to the seconds vector? What's I do bad?
>
> Thanks
>
> _______________________________________________
> PyOpenCL mailing list
> PyOpenCL(a)tiker.net
> http://lists.tiker.net/listinfo/pyopencl
>
5 years, 7 months

Barrier don't work
by Franco Nicolas Bellomo

Hi, I'm Franco, I'm study physic in Argentina and I'm new in PyOpenCl word.
My problem in when I use barrier. This is my kernel:
b_dev = cl.array.arange(queue, N2, dtype=np.float32)
b_new_dev = cl.array.zeros(queue, N2, dtype=np.float32)
a_dev = cl.array.zeros(queue, N2, dtype=np.float32)
#kernel
prg = cl.Program(ctx, """
__kernel void twice(__global float *a, __global float *b, __global float *c)
{
int gid = get_global_id(0);
__local float a_local[17];
a_local[gid + 1] = b[gid] + b[gid + 1] + b[gid + 2];
c[gid + 1] = a_local[gid + 1];
barrier(CLK_LOCAL_MEM_FENCE);
a[gid] = a_local[gid];
}
""").build()
twice = prg.twice
twice(queue, (N,), None, a_dev.data, b_dev.data, b_new_dev.data)
print " b\n %s\n\n c\n %s\n vector A donde copio\n %s" %(b_dev,
b_new_dev, a_dev)
And generated this output:
b
[ 0. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11.]
c
[ 0. 3. 6. 9. 12. 15. 18. 21. 24. 27. 30. 0.]
vector A donde copio
[ 1.65503965e-24 4.59149455e-41 6.00000000e+00 4.59149455e-41
1.20000000e+01 0.00000000e+00 1.80000000e+01 0.00000000e+00
2.40000000e+01 0.00000000e+00 0.00000000e+00 0.00000000e+00
Why the last vector is different to the seconds vector? What's I do bad?
Thanks
5 years, 7 months

Using all CPU cores
by Keith Brafford

When I run the particle animation demo with an Intel or AMD CPU context it
only seems to be using 1 processor core--the task manager shows no more
than 1 of the hyperthreads being pegged. If I increase the number of
particles it works, but it runs slower and doesn't try to use any of the
other 7 threads. Is there some trick to get it to seamlessly use all of
the compute devices that the context offers?
When I run it on the GPU it seems to use all of the devices naturally.
--Keith
5 years, 7 months

Very specific bug: round(float) fails on Ti780 with python only
by Kai Ruhl

I have a *very* specific bug in pyopencl: When I use round(88.9f) with
pyopencl from git (2014-04-08) on a Nvidia Ti780, it will give me 88.0
instead of 89.0.
- If I change the gfx card to my older GTX590, it will work.
- If I round doubles instead of floats, it works on both cards.
- If I write a test in C++, it works on both cards.
Can anyone with a Ti780 confirm this bug?
Side info: I have compiled pyopencl with ENABLE_GL=True and
CL_PRETEND_VERSION="1.1" due to missing clCreateSubDevices in nvidia OpenCL.
OS is Ubuntu 14.04.
My test is:
import pyopencl as cl
import numpy as np
ctx = cl.create_some_context()
que = cl.CommandQueue(ctx)
cl_prg = cl.Program(ctx, "__kernel void doit(__global float *a) { a[0] =
round(88.9f); }").build()
a = np.zeros(1, dtype=np.float32); A = cl.Buffer(ctx,
cl.mem_flags.READ_WRITE | cl.mem_flags.COPY_HOST_PTR, hostbuf=a)
cl_prg.doit(que, [1], None, A); que.finish()
cl.enqueue_copy(que, a, A)
print a[0]
5 years, 7 months

AWS Summit in Berlin
by Tomasz Rybak

Hello.
Just to remind - next week I'll be in Berlin on AWS Summit.
If anyone wants to meet, I'm in Berlin since Wednesday 2014-05-14
till Saturday 2014-05-17.
Best regards.
--
Tomasz Rybak GPG/PGP key ID: 2AD5 9860
Fingerprint A481 824E 7DD3 9C0E C40A 488E C654 FB33 2AD5 9860
http://member.acm.org/~tomaszrybak
5 years, 7 months