[PyOpenCL] “comparison of integers of different signs” Problem

2018-12-03 Thread Devin Ceartas
Also posted at: 
https://stackoverflow.com/questions/53576439/pyopencl-comparison-of-integers-of-different-signs-problem


I'm on a MacBook Pro with Intel graphics. I have extremely limited 
experience with C code.


There's not a lot of code here, but the actual problem is probably in 
the C/OpenCl code generated by the python module.


The compiler generates many repetitions of:

:819:47: warning: comparison of integers of different 
signs: 'unsigned long' and 'const psc_index_type' (aka 'const int')

if (psc_K * psc_LID_0 + psc_k < psc_offset_end)
~ ^ ~~

The code used is as follows:

import pyopencl as cl
import pyopencl.array
import pyopencl.algorithm
import numpy as np

platform = cl.get_platforms()
my_devices = platform[0].get_devices(device_type=cl.device_type.GPU)
ctx = cl.Context(devices=my_devices)
queue = cl.CommandQueue(ctx)

aryary = np.array([[10, 11, 12, 13, 14, 15, 16, 17], [1, 2, 3, 4, 0, 0, 
0, 0], [108, 0, 0, 0, 0, 0, 0, 0]], np.int32)

cl_aryary = cl.array.to_device(queue, aryary)
lenary = np.array([8, 4, 1], np.int32)
cl_lenary = cl.array.to_device(queue, lenary)

result = cl.algorithm.copy_if(
  cl_aryary,
  "sum_array([i], len[i]) == 108",
  extra_args=[('len', cl_lenary)],
  preamble='''
int sum_array(__global int *a, int num_elements);

int sum_array(__global int *a, int num_elements)
{
   int i, sum=0;
   for (i=0; iThere's not a lot of code here, but the actual problem is probably in 
the C/OpenCl code generated by the python module.


The compiler generates many repetitions of:

:819:47: warning: comparison of integers of different 
signs: 'unsigned long' and 'const psc_index_type' (aka 'const int')

if (psc_K * psc_LID_0 + psc_k < psc_offset_end)
~ ^ ~~
The code used is as follows:

import pyopencl as cl
import pyopencl.array
import pyopencl.algorithm
import numpy as np

platform = cl.get_platforms()
my_devices = platform[0].get_devices(device_type=cl.device_type.GPU)
ctx = cl.Context(devices=my_devices)
queue = cl.CommandQueue(ctx)

aryary = np.array([[10, 11, 12, 13, 14, 15, 16, 17], [1, 2, 3, 4, 0, 0, 
0, 0], [108, 0, 0, 0, 0, 0, 0, 0]], np.int32)

cl_aryary = cl.array.to_device(queue, aryary)
lenary = np.array([8, 4, 1], np.int32)
cl_lenary = cl.array.to_device(queue, lenary)

result = cl.algorithm.copy_if(
  cl_aryary,
  "sum_array([i], len[i]) == 108",
  extra_args=[('len', cl_lenary)],
  preamble='''
int sum_array(__global int *a, int num_elements);

int sum_array(__global int *a, int num_elements)
{
   int i, sum=0;
   for (i=0; iI've tried tweaking lots of things here but can't track down what is 
blocking this code from compiling, running and actually producing a 
result.


___
PyOpenCL mailing list
PyOpenCL@tiker.net
https://lists.tiker.net/listinfo/pyopencl


Re: [PyOpenCL] “comparison of integers of different signs” Problem

2018-12-03 Thread Sven Warris

Dear Devin,

I think this is because you are using an int to index an array. Using 
the index of an array is pointer arithmetic, which means with a[i] 
technically you are performing a+i.
And the pointer a is of type unsigned long and i of type int, which 
gives this warning of type conversion when comparing the two.


Try to change 'int i' into 'unsigned long i' and see what happens. 
Please note that 'sum' still needs to be an int.


Cheers,
Sven

Op 3-12-2018 om 21:08 schreef Devin Ceartas:


Also posted at: 
https://stackoverflow.com/questions/53576439/pyopencl-comparison-of-integers-of-different-signs-problem


I'm on a MacBook Pro with Intel graphics. I have extremely limited 
experience with C code.


There's not a lot of code here, but the actual problem is probably in 
the C/OpenCl code generated by the python module.


The compiler generates many repetitions of:

:819:47: warning: comparison of integers of different 
signs: 'unsigned long' and 'const psc_index_type' (aka 'const int')

if (psc_K * psc_LID_0 + psc_k < psc_offset_end)
~ ^ ~~

The code used is as follows:

import pyopencl as cl

import pyopencl.array
import pyopencl.algorithm
import numpy as np

platform = cl.get_platforms()
my_devices = platform[0].get_devices(device_type=cl.device_type.GPU)
ctx = cl.Context(devices=my_devices)
queue = cl.CommandQueue(ctx)

aryary = np.array([[10, 11, 12, 13, 14, 15, 16, 17], [1, 2, 3, 4, 0, 
0, 0, 0], [108, 0, 0, 0, 0, 0, 0, 0]], np.int32)

cl_aryary = cl.array.to_device(queue, aryary)
lenary = np.array([8, 4, 1], np.int32)
cl_lenary = cl.array.to_device(queue, lenary)

result = cl.algorithm.copy_if(
cl_aryary,
"sum_array([i], len[i]) == 108",
extra_args=[('len', cl_lenary)],
preamble='''
int sum_array(__global int *a, int num_elements);

|int sum_array(__global int *a, int num_elements) { int i, sum=0; for 
(i=0; i

''',
queue=queue
)

print(result)

There's not a lot of code here, but the actual problem is probably in 
the C/OpenCl code generated by the python module.


The compiler generates many repetitions of:

:819:47: warning: comparison of integers of different 
signs: 'unsigned long' and 'const psc_index_type' (aka 'const int')

if (psc_K * psc_LID_0 + psc_k < psc_offset_end)
~ ^ ~~
The code used is as follows:

import pyopencl as cl

import pyopencl.array
import pyopencl.algorithm
import numpy as np

platform = cl.get_platforms()
my_devices = platform[0].get_devices(device_type=cl.device_type.GPU)
ctx = cl.Context(devices=my_devices)
queue = cl.CommandQueue(ctx)

aryary = np.array([[10, 11, 12, 13, 14, 15, 16, 17], [1, 2, 3, 4, 0, 
0, 0, 0], [108, 0, 0, 0, 0, 0, 0, 0]], np.int32)

cl_aryary = cl.array.to_device(queue, aryary)
lenary = np.array([8, 4, 1], np.int32)
cl_lenary = cl.array.to_device(queue, lenary)

result = cl.algorithm.copy_if(
cl_aryary,
"sum_array([i], len[i]) == 108",
extra_args=[('len', cl_lenary)],
preamble='''
int sum_array(__global int *a, int num_elements);

|int sum_array(__global int *a, int num_elements) { int i, sum=0; for 
(i=0; i

''',
queue=queue
)

print(result)

I've tried tweaking lots of things here but can't track down what is 
blocking this code from compiling, running and actually producing a 
result.



___
PyOpenCL mailing list
PyOpenCL@tiker.net
https://lists.tiker.net/listinfo/pyopencl



___
PyOpenCL mailing list
PyOpenCL@tiker.net
https://lists.tiker.net/listinfo/pyopencl