Exemplo n.º 1
0
 def objective(trial):
     args = suggest_func(trial)
     max_total_time = optimize_config.max_total_time_per_trial
     try:
         perf = profiler.benchmark(target_func,
                                   args,
                                   max_duration=max_total_time)
         return perf.gpu_times.mean()
     except Exception as e:
         if isinstance(e, ignore_error):
             return math.inf
         else:
             raise e
Exemplo n.º 2
0
    def test_multigpu_routine(self):
        with mock.patch('time.perf_counter',
                        mock.Mock(side_effect=[2.4, 3.8, 3.8] * 10)):
            with mock.patch('cupy.cuda.get_elapsed_time',
                            mock.Mock(return_value=2500)):
                mock_func = mock.Mock()
                mock_func.__name__ = 'test_name_xxx'
                x = cupy.testing.shaped_random((2, 3), cupy, 'int32')
                y = cupy.testing.shaped_random((2, 3), cupy, 'int32')
                assert mock_func.call_count == 0

                perf = profiler.benchmark(
                    mock_func, (x, y), n_repeat=10, n_warmup=3, devices=(0, 1))

                assert perf.name == 'test_name_xxx'
                assert mock_func.call_count == 13
                assert perf.cpu_times.shape == (10,)
                assert perf.gpu_times.shape == (2, 10,)
                assert (perf.cpu_times == 1.4).all()
                assert (perf.gpu_times == 2.5).all()
Exemplo n.º 3
0
    def test_benchmark_max_duration(self):
        with mock.patch('time.perf_counter',
                        mock.Mock(side_effect=[1., 2., 2.] * 6)):
            with mock.patch('cupy.cuda.get_elapsed_time',
                            mock.Mock(return_value=2500)):
                mock_func = mock.Mock()
                mock_func.__name__ = 'test_name_xxx'
                x = cupy.testing.shaped_random((2, 3), cupy, 'int32')
                y = cupy.testing.shaped_random((2, 3), cupy, 'int32')
                assert mock_func.call_count == 0

                perf = profiler.benchmark(
                    mock_func, (x, y), n_warmup=3, max_duration=2.5)

                assert perf.name == 'test_name_xxx'
                assert mock_func.call_count == 6
                assert perf.cpu_times.shape == (3,)
                assert perf.gpu_times.shape == (1, 3)
                assert (perf.cpu_times == 1.).all()
                assert (perf.gpu_times == 2.5).all()
Exemplo n.º 4
0
 def test_benchmark_kwargs(self):
     x = cupy.random.rand(5)
     profiler.benchmark(
         cupy.nonzero, kwargs={'a': x}, n_repeat=1, n_warmup=1)
Exemplo n.º 5
0
def launch_test(n, ts):
    flow = CavityFlow(n, ts)
    print(benchmark(flow.compute, n_repeat=5, n_warmup=2))