@@ -284,22 +284,6 @@ def __init__(
284284 if allocator is not None and use_memory_pool is not None :
285285 raise TypeError ("may not specify both allocator and use_memory_pool" )
286286
287- self .profile_kernels = profile_kernels
288-
289- if profile_kernels :
290- import pyopencl as cl
291- if not queue .properties & cl .command_queue_properties .PROFILING_ENABLE :
292- raise RuntimeError ("Profiling was not enabled in the command queue. "
293- "Please create the queue with "
294- "cl.command_queue_properties.PROFILING_ENABLE." )
295-
296- # List of ProfileEvents that haven't been transferred to profiled
297- # results yet
298- self ._profile_events : list [ProfileEvent ] = []
299-
300- # Dict of kernel name -> list of kernel execution times
301- self ._profile_results : dict [str , list [int ]] = {}
302-
303287 self .using_svm = None
304288
305289 if allocator is None :
@@ -348,8 +332,29 @@ def __init__(
348332
349333 self ._force_svm_arg_limit = _force_svm_arg_limit
350334
335+ self ._enable_profiling (profile_kernels )
336+
351337 # {{{ Profiling functionality
352338
339+ def _enable_profiling (self , enable : bool ) -> None :
340+ # List of ProfileEvents that haven't been transferred to profiled
341+ # results yet
342+ self ._profile_events : list [ProfileEvent ] = []
343+
344+ # Dict of kernel name -> list of kernel execution times
345+ self ._profile_results : dict [str , list [int ]] = {}
346+
347+ if enable :
348+ import pyopencl as cl
349+ if not self .queue .properties & cl .command_queue_properties .PROFILING_ENABLE :
350+ raise RuntimeError ("Profiling was not enabled in the command queue. "
351+ "Please create the queue with "
352+ "cl.command_queue_properties.PROFILING_ENABLE." )
353+ self .profile_kernels = True
354+
355+ else :
356+ self .profile_kernels = False
357+
353358 def _wait_and_transfer_profile_events (self ) -> None :
354359 """Wait for all profiling events to finish and transfer the results
355360 to *self._profile_results*."""
0 commit comments