From e67f839ae296ebdb53bd6a6e41fc9fcb79ad397f Mon Sep 17 00:00:00 2001 From: Matthias Diener Date: Mon, 5 May 2025 20:26:54 -0500 Subject: [PATCH 1/2] add profiling executor --- arraycontext/impl/pyopencl/__init__.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/arraycontext/impl/pyopencl/__init__.py b/arraycontext/impl/pyopencl/__init__.py index 84d5f483..a6bf9727 100644 --- a/arraycontext/impl/pyopencl/__init__.py +++ b/arraycontext/impl/pyopencl/__init__.py @@ -241,12 +241,15 @@ def _tag_axis(ary): return self._rec_map_container(_tag_axis, array) +class MyProfilingExecutor: + def __call__... + def call_loopy(self, t_unit, **kwargs): try: executor = self._loopy_transform_cache[t_unit] except KeyError: orig_t_unit = t_unit - executor = self.transform_loopy_program(t_unit).executor(self.context) + executor = MyProfilingExecutor(self.transform_loopy_program(t_unit).executor(self.context) self._loopy_transform_cache[orig_t_unit] = executor del orig_t_unit From b1fe028c63a56d61a7e6d386094c6ed158e513d4 Mon Sep 17 00:00:00 2001 From: Matthias Diener Date: Tue, 6 May 2025 15:08:01 -0500 Subject: [PATCH 2/2] full impl --- arraycontext/impl/pyopencl/__init__.py | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/arraycontext/impl/pyopencl/__init__.py b/arraycontext/impl/pyopencl/__init__.py index a6bf9727..36721013 100644 --- a/arraycontext/impl/pyopencl/__init__.py +++ b/arraycontext/impl/pyopencl/__init__.py @@ -56,6 +56,26 @@ # {{{ PyOpenCLArrayContext + +class PyOpenCLProfilingExecutor: + def __init__(self, actx, executor): + self.executor = executor + self.t_unit = executor.t_unit + self.actx = actx + + def __call__(self, queue, **kwargs): + if self.actx.profile_kernels: + import pyopencl as cl + start_evt = cl.enqueue_marker(queue) + + evt, result = self.executor(queue, **kwargs) + + if self.actx.profile_kernels: + self.actx._add_profiling_events(start_evt, evt, t_unit.entrypoint) + + return evt, result + + class PyOpenCLArrayContext(ArrayContext): """ A :class:`ArrayContext` that uses :class:`pyopencl.array.Array` instances @@ -241,15 +261,13 @@ def _tag_axis(ary): return self._rec_map_container(_tag_axis, array) -class MyProfilingExecutor: - def __call__... - def call_loopy(self, t_unit, **kwargs): try: executor = self._loopy_transform_cache[t_unit] except KeyError: orig_t_unit = t_unit - executor = MyProfilingExecutor(self.transform_loopy_program(t_unit).executor(self.context) + executor = PyOpenCLProfilingExecutor(self, + self.transform_loopy_program(t_unit).executor(self.context)) self._loopy_transform_cache[orig_t_unit] = executor del orig_t_unit