Skip to content

Commit

Permalink
address pylint>=3.2 issues (#757)
Browse files Browse the repository at this point in the history
* address pylint>=3.2 issues

* use name instead of number

* Minor tweaks to pylint fixes

---------

Co-authored-by: Andreas Kloeckner <[email protected]>
  • Loading branch information
matthiasdiener and inducer authored May 17, 2024
1 parent e421c82 commit f5e1b7b
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 61 deletions.
6 changes: 4 additions & 2 deletions pyopencl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -979,7 +979,8 @@ def image_init(self, context, flags, format, shape=None, pitches=None,
else:
raise ValueError("images cannot have more than three dimensions")

desc = ImageDescriptor()
desc = ImageDescriptor() \
# pylint: disable=possibly-used-before-assignment

desc.image_type = image_type
desc.shape = shape # also sets desc.array_size
Expand Down Expand Up @@ -1354,7 +1355,8 @@ def svmptr_as_buffer(self, ctx: Context, *, flags: Optional[int] = None,
svm_old_init = SVM.__init__

def svm_init(self, mem):
svm_old_init(self, mem)
if get_cl_header_version() >= (2, 0):
svm_old_init(self, mem)

self.mem = mem

Expand Down
4 changes: 3 additions & 1 deletion pyopencl/algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -1225,7 +1225,9 @@ def __call__(self, queue, n_objects, *args, **kwargs):
info_record.compressed_indices = cl.array.empty(
queue, (n_objects + 1,), index_dtype, allocator=allocator)
info_record.compressed_indices[0] = 0
compress_events[name] = compress_kernel(

compress_events[name] = compress_kernel( \
# pylint: disable=possibly-used-before-assignment
info_record.starts,
compressed_counts,
info_record.nonempty_indices,
Expand Down
2 changes: 2 additions & 0 deletions pyopencl/bitonic_sort.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,8 @@ def sort_b_prepare_wl(self, argsort, key_dtype, idx_dtype, shape, axis):
elif inc >= 0:
letter = "B2"
ninc = 1
else:
raise AssertionError("Should not happen")

nthreads = size >> ninc

Expand Down
116 changes: 60 additions & 56 deletions pyopencl/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,96 +348,98 @@ def _monkeypatch_svm_docstrings():

# {{{ PooledSVM

PooledSVM.__doc__ = """
An object representing a :class:`SVMPool`-based allocation of
:ref:`svm`. Analogous to :class:`~pyopencl.SVMAllocation`, however once
this object is deleted, its associated device memory is returned to the
pool from which it came.
PooledSVM.__doc__ = ( # pylint: disable=possibly-used-before-assignment
"""An object representing a :class:`SVMPool`-based allocation of
:ref:`svm`. Analogous to :class:`~pyopencl.SVMAllocation`, however once
this object is deleted, its associated device memory is returned to the
pool from which it came.
.. versionadded:: 2022.2
.. versionadded:: 2022.2
.. note::
.. note::
If the :class:`SVMAllocator` for the :class:`SVMPool` that allocated an
object of this type is associated with an (in-order)
:class:`~pyopencl.CommandQueue`, sufficient synchronization is provided
to ensure operations enqueued before deallocation complete before
operations from a different use (possibly in a different queue) are
permitted to start. This applies when :class:`release` is called and
also when the object is freed automatically by the garbage collector.
If the :class:`SVMAllocator` for the :class:`SVMPool` that allocated an
object of this type is associated with an (in-order)
:class:`~pyopencl.CommandQueue`, sufficient synchronization is provided
to ensure operations enqueued before deallocation complete before
operations from a different use (possibly in a different queue) are
permitted to start. This applies when :class:`release` is called and
also when the object is freed automatically by the garbage collector.
Is a :class:`pyopencl.SVMPointer`.
Is a :class:`pyopencl.SVMPointer`.
Supports structural equality and hashing.
Supports structural equality and hashing.
.. automethod:: release
.. automethod:: release
Return the held memory to the pool. See the note about synchronization
behavior during deallocation above.
Return the held memory to the pool. See the note about synchronization
behavior during deallocation above.
.. automethod:: enqueue_release
.. automethod:: enqueue_release
Synonymous to :meth:`release`, for consistency with
:class:`~pyopencl.SVMAllocation`. Note that, unlike
:meth:`pyopencl.SVMAllocation.enqueue_release`, specifying a queue
or events to be waited for is not supported.
Synonymous to :meth:`release`, for consistency with
:class:`~pyopencl.SVMAllocation`. Note that, unlike
:meth:`pyopencl.SVMAllocation.enqueue_release`, specifying a queue
or events to be waited for is not supported.
.. automethod:: bind_to_queue
.. automethod:: bind_to_queue
Analogous to :meth:`pyopencl.SVMAllocation.bind_to_queue`.
Analogous to :meth:`pyopencl.SVMAllocation.bind_to_queue`.
.. automethod:: unbind_from_queue
.. automethod:: unbind_from_queue
Analogous to :meth:`pyopencl.SVMAllocation.unbind_from_queue`.
"""
Analogous to :meth:`pyopencl.SVMAllocation.unbind_from_queue`.
""")

# }}}

# {{{ SVMAllocator

SVMAllocator.__doc__ = """
.. versionadded:: 2022.2
SVMAllocator.__doc__ = ( # pylint: disable=possibly-used-before-assignment
"""
.. versionadded:: 2022.2
.. automethod:: __init__
.. automethod:: __init__
:arg flags: See :class:`~pyopencl.svm_mem_flags`.
:arg queue: If not specified, allocations will be freed
eagerly, irrespective of whether pending/enqueued operations
are still using the memory.
:arg flags: See :class:`~pyopencl.svm_mem_flags`.
:arg queue: If not specified, allocations will be freed
eagerly, irrespective of whether pending/enqueued operations
are still using the memory.
If specified, deallocation of memory will be enqueued
with the given queue, and will only be performed
after previously-enqueue operations in the queue have
completed.
If specified, deallocation of memory will be enqueued
with the given queue, and will only be performed
after previously-enqueue operations in the queue have
completed.
It is an error to specify an out-of-order queue.
It is an error to specify an out-of-order queue.
.. warning::
.. warning::
Not specifying a queue will typically lead to undesired
behavior, including crashes and memory corruption.
See the warning in :ref:`svm`.
Not specifying a queue will typically lead to undesired
behavior, including crashes and memory corruption.
See the warning in :ref:`svm`.
.. automethod:: __call__
.. automethod:: __call__
Return a :class:`~pyopencl.SVMAllocation` of the given *size*.
"""
Return a :class:`~pyopencl.SVMAllocation` of the given *size*.
""")

# }}}

# {{{ SVMPool

SVMPool.__doc__ = remove_common_indentation("""
A memory pool for OpenCL device memory in :ref:`SVM <svm>` form.
*allocator* must be an instance of :class:`SVMAllocator`.
SVMPool.__doc__ = ( # pylint: disable=possibly-used-before-assignment
remove_common_indentation("""
A memory pool for OpenCL device memory in :ref:`SVM <svm>` form.
*allocator* must be an instance of :class:`SVMAllocator`.
.. versionadded:: 2022.2
.. versionadded:: 2022.2
.. automethod:: __init__
.. automethod:: __call__
.. automethod:: __init__
.. automethod:: __call__
Return a :class:`PooledSVM` of the given *size*.
""") + _MEMPOOL_IFACE_DOCS
Return a :class:`PooledSVM` of the given *size*.
""") + _MEMPOOL_IFACE_DOCS)

# }}}

Expand Down Expand Up @@ -1363,6 +1365,8 @@ def vec_arg_factory(typename, name):
parsed_arg = arg
elif isinstance(arg, tuple):
parsed_arg = ScalarArg(self.parse_type(arg[0]), arg[1])
else:
raise TypeError("unexpected argument type: %s" % type(arg))

parsed_args.append(parsed_arg)

Expand Down
4 changes: 2 additions & 2 deletions test/test_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -1146,12 +1146,12 @@ def test_slice(ctx_factory):
a = a_gpu.get()
b = b_gpu.get()

start_offset = 0

if queue.device.platform.name == "Intel(R) OpenCL":
pytest.skip("Intel CL regularly crashes on this test case "
"-- https://github.com/conda-forge/"
"intel-compiler-repack-feedstock/issues/7")
else:
start_offset = 0

from random import randrange
for _i in range(20):
Expand Down
3 changes: 3 additions & 0 deletions test/test_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ def do_test(cl_obj, info_cls, func=None, try_attr_form=True):
& cl.command_queue_properties.PROFILING_ENABLE):
profiling = True
props = cl.command_queue_properties.PROFILING_ENABLE
else:
profiling = False

queue = cl.CommandQueue(ctx,
properties=props)
do_test(queue, cl.command_queue_info)
Expand Down

0 comments on commit f5e1b7b

Please sign in to comment.