silx icon indicating copy to clipboard operation
silx copied to clipboard

OpenCL 64bit atomic operation support

Open kif opened this issue 3 years ago • 1 comments
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 ?

kif avatar Jan 31 '22 15:01 kif

The equivalent could be provided for 32bits atomics...

kif avatar Jan 31 '22 15:01 kif

@pierrepaleo suggests to have this check as part of the ocl object initialization.

t20100 avatar Jun 07 '23 12:06 t20100