Skip to content
This repository was archived by the owner on Nov 15, 2022. It is now read-only.

Fixed cuda sync #183

Merged
merged 3 commits into from
Jun 18, 2020
Merged
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
13 changes: 8 additions & 5 deletions benchmarks/segmentation_layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ def run(self):

benchmarks = [(layer, self.get_benchmark(c, layer, cuda)) for layer in self.args.layers]
for layer, benchmark in benchmarks:
result = utils.benchmark_fn(benchmark, run_time=self.args.run_time, warmup=self.args.warmup)
result = utils.benchmark_fn(benchmark, run_time=self.args.run_time, warmup=self.args.warmup, cuda=cuda)
result["#"] = str(i) + "/" + str(len(benchmarks) * len(params))
result["N"] = n
result["C"] = c
Expand All @@ -336,6 +336,9 @@ def run(self):
def get_input(self, cuda, n, c, h, w, h_var, w_var, seed):
inputs = []
targets = []
device = 'cpu'
if cuda:
device = 'cuda'

torch.manual_seed(seed)
random.seed(seed)
Expand All @@ -344,10 +347,10 @@ def get_input(self, cuda, n, c, h, w, h_var, w_var, seed):
for i in range(n):
h_res = max(1, int(random.gauss(h, h_var)))
w_res = max(1, int(random.gauss(w, w_var)))
input_i = torch.randn(c, h_res, w_res)
target_i = torch.randint(1, (h_res, w_res), dtype=torch.int64)
inputs.append(input_i.cuda() if cuda else input_i)
targets.append(target_i.cuda() if cuda else target_i)
input_i = torch.randn(c, h_res, w_res, device=device)
target_i = torch.randint(1, (h_res, w_res), dtype=torch.int64, device=device)
inputs.append(input_i)
targets.append(target_i)
if cuda:
# Synchronize copy operations so they don't influence the benchmark
torch.cuda.synchronize()
Expand Down