diff --git a/grudge/execution.py b/grudge/execution.py index 5be80e9f26651b24b8b24900bfed8201ccc7ad1a..fae28410b99d539425c361612ebefbc20af7ebac 100644 --- a/grudge/execution.py +++ b/grudge/execution.py @@ -483,7 +483,7 @@ class BoundOperator(object): + sep + str(self.eval_code)) - def __call__(self, queue, profile_data=None, **context): + def __call__(self, queue, profile_data=None, log_quantities=None, **context): import pyopencl.array as cl_array def replace_queue(a): @@ -512,7 +512,8 @@ class BoundOperator(object): new_context[name] = with_object_array_or_scalar(replace_queue, var) return self.eval_code.execute( - ExecutionMapper(queue, new_context, self), profile_data=profile_data) + ExecutionMapper(queue, new_context, self), profile_data=profile_data, + log_quantities=log_quantities) # }}} diff --git a/grudge/symbolic/compiler.py b/grudge/symbolic/compiler.py index a85c8926a790b5aa15d73d687f0b733cc5602fb6..439731f641ce7e49957614dfd1e7e3f141dd234e 100644 --- a/grudge/symbolic/compiler.py +++ b/grudge/symbolic/compiler.py @@ -477,7 +477,7 @@ class Code(object): return argmax2(available_insns), discardable_vars - def execute(self, exec_mapper, pre_assign_check=None, profile_data=None): + def execute(self, exec_mapper, pre_assign_check=None, profile_data=None, log_quantities=None): if profile_data is not None: from time import time start_time = time() @@ -505,6 +505,11 @@ class Code(object): del context[name] mapper_method = getattr(exec_mapper, insn.mapper_method) + if log_quantities is not None: + from pytools.log import time_and_count_function + mapper_method = time_and_count_function(mapper_method, + log_quantities["timer"], + log_quantities["counter"]) assignments, new_futures = mapper_method(insn) for target, value in assignments: diff --git a/test/test_mpi_communication.py b/test/test_mpi_communication.py index 7777d14d912b7c8585996e589ec0b2a156296a2c..70883b5bc7a1ccc85c7bd10b1de308ef1858253c 100644 --- a/test/test_mpi_communication.py +++ b/test/test_mpi_communication.py @@ -170,11 +170,19 @@ def mpi_communication_entrypoint(): from pytools.log import LogManager, \ add_general_quantities, \ - add_run_info - log_filename = None + add_run_info, \ + IntervalTimer, EventCounter + # log_filename = None + log_filename = 'grudge_log.dat' logmgr = LogManager(log_filename, "w", comm) add_run_info(logmgr) add_general_quantities(logmgr) + log_quantities = {"timer": IntervalTimer("insn_timer", + "Time spent evaluating instructions"), + "counter": EventCounter("insn_counter", + "Number of instructions evaluated")} + for quantity in log_quantities.values(): + logmgr.add_quantity(quantity) # print(sym.pretty(op.sym_operator())) bound_op = bind(vol_discr, op.sym_operator()) @@ -183,6 +191,7 @@ def mpi_communication_entrypoint(): def rhs(t, w): val, rhs.profile_data = bound_op(queue, profile_data=rhs.profile_data, + log_quantities=log_quantities, t=t, w=w) return val rhs.profile_data = {}