Skip to content

Commit

Permalink
Warn about array arithmetic with inconsistent queues (gh-358)
Browse files Browse the repository at this point in the history
  • Loading branch information
inducer committed Sep 9, 2020
1 parent 3c04b61 commit bbf0817
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion pyopencl/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ def _dtype_is_object(t):
return False


class InconsistentOpenCLQueueWarning(UserWarning):
pass


class VecLookupWarner:
def __getattr__(self, name):
from warnings import warn
Expand Down Expand Up @@ -144,7 +148,11 @@ def elwise_kernel_runner(kernel_getter):

def kernel_runner(*args, **kwargs):
repr_ary = args[0]
queue = kwargs.pop("queue", None) or repr_ary.queue
queue = kwargs.pop("queue", None)
implicit_queue = queue is None
if implicit_queue:
queue = repr_ary.queue

wait_for = kwargs.pop("wait_for", None)

# wait_for must be a copy, because we modify it in-place below
Expand All @@ -171,6 +179,16 @@ def kernel_runner(*args, **kwargs):
actual_args.append(arg.base_data)
actual_args.append(arg.offset)
wait_for.extend(arg.events)

if (implicit_queue
and arg.queue is not None
and arg.queue != queue):
from warnings import warn

warn("Implicit queue in elementwise operation does not match "
"queue of a provided argument. This will become an "
"error in 2021.",
type=InconsistentOpenCLQueueWarning)
else:
actual_args.append(arg)
actual_args.append(repr_ary.size)
Expand Down

0 comments on commit bbf0817

Please sign in to comment.