silx icon indicating copy to clipboard operation
silx copied to clipboard

[OpenCL] pyopencl.array.zeros helper

Open pierrepaleo opened this issue 6 years ago • 0 comments

Follow-up of #2696/#2698.

Previously, pyopencl code used

d_array = pyopencl.array.zeros(queue, shape, dtype)

Because of the issues with pocl, this was replaced with

d_array = pyopencl.array.empty(queue, shape, dtype)
d_array.fill(0)

I see several issues:

  • More code for doing the same thing, so potentially more bugs
  • The code was changed because of an issue in a specific OpenCL implementation ; although this issue might be fixed in the future
  • Slight performances drop if memset is done by a kernel rather than a native instruction (EnqueueFillBuffer) outside of the class creation.

In order to have a more concise and future-proof code, I suggest to create a helper in the OpenclProcessing class. Something like

d_array = self.array_zeros(shape, dtype) # within self.queue

where array_zeros handles the case of "zeros()" vs "empty() + fill()" depending on the platform. If the pocl issue is fixed in the future, this function could be reverted to a simple alias to pyopencl.array.zeros().

pierrepaleo avatar Aug 01 '19 15:08 pierrepaleo