예제 #1
0
    def adaptive_autorange(
            self,
            threshold=0.1,
            max_run_time=10,
            callback: Optional[Callable[[int, float], NoReturn]] = None,
            min_run_time=0.01
    ):
        number = self._estimate_block_size(min_run_time=0.05)

        def time_hook() -> float:
            return self._timer.timeit(number)

        def stop_hook(times) -> bool:
            if len(times) > 3:
                return common.Measurement(
                    number_per_run=number,
                    raw_times=times,
                    task_spec=self._task_spec
                ).meets_confidence(threshold=threshold)
            return False
        times = self._threaded_measurement_loop(
            number, time_hook, stop_hook, min_run_time, max_run_time, callback=callback)

        return common.Measurement(
            number_per_run=number,
            raw_times=times,
            task_spec=self._task_spec
        )
예제 #2
0
 def stop_hook(times) -> bool:
     if len(times) > 3:
         return common.Measurement(
             number_per_run=number,
             raw_times=times,
             task_spec=self._task_spec
         ).meets_confidence(threshold=threshold)
     return False
예제 #3
0
    def timeit(self, number=1000000):
        with common.set_torch_threads(self._task_spec.num_threads):
            # Warmup
            self._timer.timeit(number=max(int(number // 100), 1))

            return common.Measurement(
                number_per_run=number,
                raw_times=[self._timer.timeit(number=number)],
                task_spec=self._task_spec
            )
예제 #4
0
 def _construct_measurement(self, number_per_run: int, times: List[float]):
     return common.Measurement(
         number_per_run=number_per_run,
         times=times,
         num_threads=self._num_threads,
         label=self._label,
         sub_label=self._sub_label,
         description=self._description,
         env=self._env,
         stmt=self._stmt,
     )
예제 #5
0
    def blocked_autorange(self, callback=None, min_run_time=0.2):
        number = self._estimate_block_size(min_run_time)

        def time_hook() -> float:
            return self._timer.timeit(number)

        def stop_hook(times) -> bool:
            return True

        times = self._threaded_measurement_loop(
            number, time_hook, stop_hook,
            min_run_time=min_run_time,
            callback=callback)

        return common.Measurement(
            number_per_run=number,
            raw_times=times,
            task_spec=self._task_spec
        )