Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions benchmarks/operator_benchmark/benchmark_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,17 +249,18 @@ def _iteration_result_is_significant(self, iters, run_time_sec, curr_test_total_
def _launch_forward(self, test_case, iters, print_per_iter):
""" Use Python's timeit module to measure execution time (unit: second).
"""
cuda_sync = True if 'cuda' in test_case.test_config.test_name else False
func = test_case.run_forward
if self.use_jit:
func = test_case.run_jit_forward
forward_time = timeit.timeit(functools.partial(func, iters, print_per_iter), number=1)
forward_time = timeit.timeit(functools.partial(func, iters, print_per_iter, cuda_sync), number=1)
return forward_time

def _launch_backward(self, test_case, iters, print_per_iter=False):
""" This function runs forward path of an op to get an output. Then the backward path is executed
and the execution time is reported
"""
test_case.run_forward(num_runs=1, print_per_iter=False)
test_case.run_forward(num_runs=1, print_per_iter=False, cuda_sync=False)
if test_case.framework == "PyTorch":
test_case._output_mean()
backward_time = timeit.timeit(functools.partial(test_case.run_backward, iters,
Expand Down
8 changes: 6 additions & 2 deletions benchmarks/operator_benchmark/benchmark_pytorch.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def __init__(self, op_bench, test_config):
self.framework = "PyTorch"
self.time_series = []

def run_jit_forward(self, num_runs, print_per_iter=False):
def run_jit_forward(self, num_runs, print_per_iter=False, cuda_sync=False):
""" Run the forward path of an op with JIT mode
"""
if self.op_bench._jit_forward is None:
Expand All @@ -147,18 +147,22 @@ def _print_per_iter(self):
}
))

def run_forward(self, num_runs, print_per_iter):
def run_forward(self, num_runs, print_per_iter, cuda_sync):
""" Run the forward path of an op with eager mode
"""
if print_per_iter:
for _ in range(num_runs):
start_time = time.time()
self.output = self.op_bench.forward()
if cuda_sync:
torch.cuda.synchronize(torch.cuda.current_device())
end_time = time.time()
self.time_series.append((end_time - start_time) * 1e3)
else:
for _ in range(num_runs):
self.output = self.op_bench.forward()
if cuda_sync:
torch.cuda.synchronize(torch.cuda.current_device())

def _output_mean(self):
""" TODO (mingzhe): it is not necessary to sum up everything by myself,
Expand Down