silx
silx copied to clipboard
OpenCL 64bit atomic operation support
trafficstars
Some devices report they are not supporting 64bit atomic operation but do which is much better than those which report they can but actually fail.
This snippet of code performs the actual test
def check_atomic64(device):
try:
ctx = pyopencl.Context(devices=[device])
except:
return False, f"Unable to create context on {device}"
else:
queue = pyopencl.CommandQueue(ctx)
src = """
#pragma OPENCL EXTENSION cl_khr_fp64: enable
#pragma OPENCL EXTENSION cl_khr_int64_base_atomics : enable
kernel void check_atomic64(global long* ary){
long res = atom_inc(ary);
}
"""
try:
prg = pyopencl.Program(ctx, src).build()
except Exception as err:
return False, f"{type(err)}: {err}"
a = numpy.zeros(1, numpy.int64)
d = cla.to_device(queue, a)
prg.check_atomic64(queue, (1024,), (32,), d.data).wait()
value = d.get()[0]
return value==1024, f"Got the proper value 1024=={value}"
Does it make sense to make it available as part of silx ?
The equivalent could be provided for 32bits atomics...
@pierrepaleo suggests to have this check as part of the ocl object initialization.