Skip to content

Commit

Permalink
Merge pull request #4193 from silx-kit/opencl_image
Browse files Browse the repository at this point in the history
silx.opencl: Fixed deprecation warning upon texture creation
  • Loading branch information
t20100 authored Nov 12, 2024
2 parents 95eeb53 + fd49dbf commit 7b652bd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
14 changes: 11 additions & 3 deletions src/silx/opencl/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@

import os
import logging
from packaging.version import Version
import numpy
from .utils import get_opencl_code

Expand Down Expand Up @@ -757,18 +758,25 @@ def allocate_texture(ctx, shape, hostbuf=None, support_1D=False):
do not support 1D images, so 1D images are handled as 2D with one row
:param support_1D: force the image to be 1D if the shape has only one dim
"""
# TODO "shape" as optional parameter (kwarg) ?
if len(shape) == 1 and not (support_1D):
shape = (1,) + shape
return pyopencl.Image(
if hostbuf is None:
hostbuf = numpy.zeros(shape[::-1], dtype=numpy.float32)

if Version(pyopencl.version.VERSION_TEXT) >= Version("2024.3"):
texture_creation_function = pyopencl.create_image
else:
texture_creation_function = pyopencl.Image
return texture_creation_function(
ctx,
pyopencl.mem_flags.READ_ONLY | pyopencl.mem_flags.USE_HOST_PTR,
pyopencl.ImageFormat(
pyopencl.channel_order.INTENSITY, pyopencl.channel_type.FLOAT
),
hostbuf=numpy.zeros(shape[::-1], dtype=numpy.float32),
hostbuf=hostbuf,
)


def check_textures_availability(ctx):
"""
Check whether textures are supported on the current OpenCL context.
Expand Down
10 changes: 2 additions & 8 deletions src/silx/opencl/projection.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,14 +222,8 @@ def allocate_slice(self):
self.add_to_cl_mem({"d_slice": ary})

def allocate_textures(self):
self.d_image_tex = pyopencl.Image(
self.ctx,
mf.READ_ONLY | mf.USE_HOST_PTR,
pyopencl.ImageFormat(
pyopencl.channel_order.INTENSITY, pyopencl.channel_type.FLOAT
),
hostbuf=np.ascontiguousarray(self._tmp_extended_img.T),
)
hostbuf = np.ascontiguousarray(self._tmp_extended_img.T)
self.d_image_tex = self.allocate_texture(hostbuf.shape, hostbuf)

def transfer_to_texture(self, image):
image2 = image
Expand Down

0 comments on commit 7b652bd

Please sign in to comment.