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

Commit 17fbe15

Browse files
authored
Fixed cuda sync (#183)
* fixed cuda * upd
1 parent a924abd commit 17fbe15

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

benchmarks/segmentation_layers.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ def run(self):
311311

312312
benchmarks = [(layer, self.get_benchmark(c, layer, cuda)) for layer in self.args.layers]
313313
for layer, benchmark in benchmarks:
314-
result = utils.benchmark_fn(benchmark, run_time=self.args.run_time, warmup=self.args.warmup)
314+
result = utils.benchmark_fn(benchmark, run_time=self.args.run_time, warmup=self.args.warmup, cuda=cuda)
315315
result["#"] = str(i) + "/" + str(len(benchmarks) * len(params))
316316
result["N"] = n
317317
result["C"] = c
@@ -336,6 +336,9 @@ def run(self):
336336
def get_input(self, cuda, n, c, h, w, h_var, w_var, seed):
337337
inputs = []
338338
targets = []
339+
device = 'cpu'
340+
if cuda:
341+
device = 'cuda'
339342

340343
torch.manual_seed(seed)
341344
random.seed(seed)
@@ -344,10 +347,10 @@ def get_input(self, cuda, n, c, h, w, h_var, w_var, seed):
344347
for i in range(n):
345348
h_res = max(1, int(random.gauss(h, h_var)))
346349
w_res = max(1, int(random.gauss(w, w_var)))
347-
input_i = torch.randn(c, h_res, w_res)
348-
target_i = torch.randint(1, (h_res, w_res), dtype=torch.int64)
349-
inputs.append(input_i.cuda() if cuda else input_i)
350-
targets.append(target_i.cuda() if cuda else target_i)
350+
input_i = torch.randn(c, h_res, w_res, device=device)
351+
target_i = torch.randint(1, (h_res, w_res), dtype=torch.int64, device=device)
352+
inputs.append(input_i)
353+
targets.append(target_i)
351354
if cuda:
352355
# Synchronize copy operations so they don't influence the benchmark
353356
torch.cuda.synchronize()

0 commit comments

Comments
 (0)