MCPcopy Create free account
hub / github.com/PythonOT/POT / _bench

Method _bench

ot/backend.py:2357–2383  ·  view source on GitHub ↗
(self, callable, *args, n_runs=1, warmup_runs=1)

Source from the content-addressed store, hash-verified

2355 return type_as.device.type.replace("cuda", "gpu").upper()
2356
2357 def _bench(self, callable, *args, n_runs=1, warmup_runs=1):
2358 results = dict()
2359 for type_as in self.__type_list__:
2360 inputs = [self.from_numpy(arg, type_as=type_as) for arg in args]
2361 for _ in range(warmup_runs):
2362 callable(*inputs)
2363 if self.device_type(type_as) == "GPU": # pragma: no cover
2364 torch.cuda.synchronize()
2365 start = torch.cuda.Event(enable_timing=True)
2366 end = torch.cuda.Event(enable_timing=True)
2367 start.record()
2368 else:
2369 start = time.perf_counter()
2370 for _ in range(n_runs):
2371 callable(*inputs)
2372 if self.device_type(type_as) == "GPU": # pragma: no cover
2373 end.record()
2374 torch.cuda.synchronize()
2375 duration = start.elapsed_time(end) / 1000.0
2376 else:
2377 end = time.perf_counter()
2378 duration = end - start
2379 key = ("Pytorch", self.device_type(type_as), self.bitsize(type_as))
2380 results[key] = duration / n_runs
2381 if torch.cuda.is_available():
2382 torch.cuda.empty_cache()
2383 return results
2384
2385 def solve(self, a, b):
2386 return torch.linalg.solve(a, b)

Callers

nothing calls this directly

Calls 3

device_typeMethod · 0.95
bitsizeMethod · 0.95
from_numpyMethod · 0.80

Tested by

no test coverage detected