Update selectable device Profile (#12353)

* Update selectable device Profile

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
Yakuhoandpre-commit-ci[bot] authored and GitHub committed 2024-01-03 08:09:23 +01:00
1 parent bd1a8295fb
commit 69b0faf2f7
7 files changed
+10 -9

No files matched your search

+4 -3
View File
@@ -182,9 +182,10 @@ CONFIG_DIR = user_config_dir() # Ultralytics settings dir
class Profile(contextlib.ContextDecorator):
# YOLOv5 Profile class. Usage: @Profile() decorator or 'with Profile():' context manager
def __init__(self, t=0.0):
def __init__(self, t=0.0, device: torch.device = None):
self.t = t
self.cuda = torch.cuda.is_available()
self.device = device
self.cuda = True if (device and str(device)[:4] == 'cuda') else False
def __enter__(self):
self.start = self.time()
@@ -196,7 +197,7 @@ class Profile(contextlib.ContextDecorator):
def time(self):
if self.cuda:
torch.cuda.synchronize()
torch.cuda.synchronize(self.device)
return time.time()