Esempio n. 1
0
    def add_instrumentation(self, mgr, observer):
        mgr.set_constant("depositor", self.__class__.__name__)

        for key, value in self.log_constants.iteritems():
            mgr.set_constant(key, value)

        from pytools.log import IntervalTimer, EventCounter,\
                time_and_count_function

        self.deposit_timer = IntervalTimer(
                "t_deposit",
                "Time spent depositing")
        self.deposit_counter = EventCounter(
                "n_deposit",
                "Number of depositions")

        self.deposit_densities = time_and_count_function(
                self.deposit_densites,
                self.deposit_timer,
                self.deposit_counter,
                1+self.method.dimensions_velocity)

        self.deposit_j = time_and_count_function(
                self.deposit_j,
                self.deposit_timer,
                self.deposit_counter,
                self.method.dimensions_velocity)

        self.deposit_rho = time_and_count_function(
                self.deposit_rho,
                self.deposit_timer,
                self.deposit_counter)

        mgr.add_quantity(self.deposit_timer)
        mgr.add_quantity(self.deposit_counter)
Esempio n. 2
0
    def add_instrumentation(self, mgr, observer):
        mgr.set_constant("depositor", self.__class__.__name__)

        for key, value in self.log_constants.iteritems():
            mgr.set_constant(key, value)

        from pytools.log import IntervalTimer, EventCounter,\
                time_and_count_function

        self.deposit_timer = IntervalTimer("t_deposit",
                                           "Time spent depositing")
        self.deposit_counter = EventCounter("n_deposit",
                                            "Number of depositions")

        self.deposit_densities = time_and_count_function(
            self.deposit_densites, self.deposit_timer, self.deposit_counter,
            1 + self.method.dimensions_velocity)

        self.deposit_j = time_and_count_function(
            self.deposit_j, self.deposit_timer, self.deposit_counter,
            self.method.dimensions_velocity)

        self.deposit_rho = time_and_count_function(self.deposit_rho,
                                                   self.deposit_timer,
                                                   self.deposit_counter)

        mgr.add_quantity(self.deposit_timer)
        mgr.add_quantity(self.deposit_counter)
Esempio n. 3
0
    def get_module(self, discr, dtype):
        from hedge.backends.jit.flux import get_interior_flux_mod, get_boundary_flux_mod

        if not self.is_boundary:
            mod = get_interior_flux_mod(self.expressions, self.flux_var_info, discr, dtype)

            if discr.instrumented:
                from hedge.tools import time_count_flop, gather_flops

                mod.gather_flux = time_count_flop(
                    mod.gather_flux,
                    discr.gather_timer,
                    discr.gather_counter,
                    discr.gather_flop_counter,
                    len(self.expressions)
                    * gather_flops(discr, self.quadrature_tag)
                    * len(self.flux_var_info.arg_names),
                )

        else:
            mod = get_boundary_flux_mod(self.expressions, self.flux_var_info, discr, dtype)

            if discr.instrumented:
                from pytools.log import time_and_count_function

                mod.gather_flux = time_and_count_function(mod.gather_flux, discr.gather_timer)

        return mod
Esempio n. 4
0
    def instrument(self):
        discr = self.discr
        assert discr.instrumented

        from pytools.log import time_and_count_function
        from hedge.tools import time_count_flop

        from hedge.tools import diff_rst_flops, mass_flops

        if discr.quad_min_degrees:
            from warnings import warn
            warn("flop counts for quadrature may be wrong")

        self.diff_rst = \
                time_count_flop(
                        self.diff_rst,
                        discr.diff_timer,
                        discr.diff_counter,
                        discr.diff_flop_counter,
                        diff_rst_flops(discr))

        self.do_elementwise_linear = \
                time_count_flop(
                        self.do_elementwise_linear,
                        discr.el_local_timer,
                        discr.el_local_counter,
                        discr.el_local_flop_counter,
                        mass_flops(discr))

        self.lift_flux = \
                time_and_count_function(
                        self.lift_flux,
                        discr.lift_timer,
                        discr.lift_counter)
Esempio n. 5
0
    def get_module(self, discr, dtype):
        from hedge.backends.jit.flux import \
                get_interior_flux_mod, \
                get_boundary_flux_mod

        if not self.is_boundary:
            mod = get_interior_flux_mod(self.expressions, self.flux_var_info,
                                        discr, dtype)

            if discr.instrumented:
                from hedge.tools import time_count_flop, gather_flops
                mod.gather_flux = \
                        time_count_flop(
                                mod.gather_flux,
                                discr.gather_timer,
                                discr.gather_counter,
                                discr.gather_flop_counter,
                                len(self.expressions)
                                * gather_flops(discr, self.quadrature_tag)
                                * len(self.flux_var_info.arg_names))

        else:
            mod = get_boundary_flux_mod(self.expressions, self.flux_var_info,
                                        discr, dtype)

            if discr.instrumented:
                from pytools.log import time_and_count_function
                mod.gather_flux = time_and_count_function(
                    mod.gather_flux, discr.gather_timer)

        return mod
Esempio n. 6
0
    def instrument(self):
        discr = self.discr
        assert discr.instrumented

        from pytools.log import time_and_count_function
        from hedge.tools import time_count_flop

        from hedge.tools import diff_rst_flops, mass_flops

        if discr.quad_min_degrees:
            from warnings import warn
            warn("flop counts for quadrature may be wrong")

        self.diff_rst = \
                time_count_flop(
                        self.diff_rst,
                        discr.diff_timer,
                        discr.diff_counter,
                        discr.diff_flop_counter,
                        diff_rst_flops(discr))

        self.do_elementwise_linear = \
                time_count_flop(
                        self.do_elementwise_linear,
                        discr.el_local_timer,
                        discr.el_local_counter,
                        discr.el_local_flop_counter,
                        mass_flops(discr))

        self.lift_flux = \
                time_and_count_function(
                        self.lift_flux,
                        discr.lift_timer,
                        discr.lift_counter)
Esempio n. 7
0
    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()
            if profile_data == {}:
                profile_data['insn_eval_time'] = 0
                profile_data['future_eval_time'] = 0
                profile_data['busy_wait_time'] = 0
                profile_data['total_time'] = 0
        if log_quantities is not None:
            exec_sub_timer = log_quantities["exec_timer"].start_sub_timer()
        context = exec_mapper.context

        futures = []
        done_insns = set()

        while True:
            try:
                if profile_data is not None:
                    insn_start_time = time()
                if log_quantities is not None:
                    insn_sub_timer = \
                            log_quantities["insn_eval_timer"].start_sub_timer()

                insn, discardable_vars = self.get_next_step(
                    frozenset(list(context.keys())), frozenset(done_insns))

                done_insns.add(insn)
                for name in discardable_vars:
                    del context[name]

                mapper_method = getattr(exec_mapper, insn.mapper_method)
                if log_quantities is not None:
                    if isinstance(insn, RankDataSwapAssign):
                        from pytools.log import time_and_count_function
                        mapper_method = time_and_count_function(
                            mapper_method,
                            log_quantities["rank_data_swap_timer"],
                            log_quantities["rank_data_swap_counter"])

                assignments, new_futures = mapper_method(insn, profile_data)

                for target, value in assignments:
                    if pre_assign_check is not None:
                        pre_assign_check(target, value)
                    context[target] = value

                futures.extend(new_futures)
                if profile_data is not None:
                    profile_data['insn_eval_time'] += time() - insn_start_time
                if log_quantities is not None:
                    insn_sub_timer.stop().submit()
            except self.NoInstructionAvailable:
                if not futures:
                    # No more instructions or futures. We are done.
                    break

                # Busy wait for a new future
                if profile_data is not None:
                    busy_wait_start_time = time()
                if log_quantities is not None:
                    busy_sub_timer =\
                            log_quantities["busy_wait_timer"].start_sub_timer()

                did_eval_future = False
                while not did_eval_future:
                    for i in range(len(futures)):
                        if futures[i].is_ready():
                            if profile_data is not None:
                                profile_data['busy_wait_time'] +=\
                                        time() - busy_wait_start_time
                                future_start_time = time()
                            if log_quantities is not None:
                                busy_sub_timer.stop().submit()
                                future_sub_timer =\
                                            log_quantities["future_eval_timer"]\
                                                                .start_sub_timer()

                            future = futures.pop(i)
                            assignments, new_futures = future()

                            for target, value in assignments:
                                if pre_assign_check is not None:
                                    pre_assign_check(target, value)
                                context[target] = value

                            futures.extend(new_futures)
                            did_eval_future = True

                            if profile_data is not None:
                                profile_data['future_eval_time'] +=\
                                        time() - future_start_time
                            if log_quantities is not None:
                                future_sub_timer.stop().submit()
                            break

        if len(done_insns) < len(self.instructions):
            raise RuntimeError(
                "not all instructions are reachable"
                "--did you forget to pass a value for a placeholder?")

        if log_quantities is not None:
            exec_sub_timer.stop().submit()
        if profile_data is not None:
            profile_data['total_time'] = time() - start_time
            return (obj_array_vectorize(exec_mapper,
                                        self.result), profile_data)
        return obj_array_vectorize(exec_mapper, self.result)