Skip to content

Commit

Permalink
Guard CUDA calls with an explicit check (#516)
Browse files Browse the repository at this point in the history
  • Loading branch information
st235 committed Jul 12, 2023
1 parent d3fb34f commit 3c9607c
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions nanodet/model/arch/one_stage_detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,23 @@ def forward(self, x):

def inference(self, meta):
with torch.no_grad():
torch.cuda.synchronize()
is_cuda_available = torch.cuda.is_available()
if is_cuda_available:
torch.cuda.synchronize()

time1 = time.time()
preds = self(meta["img"])
torch.cuda.synchronize()

if is_cuda_available:
torch.cuda.synchronize()

time2 = time.time()
print("forward time: {:.3f}s".format((time2 - time1)), end=" | ")
results = self.head.post_process(preds, meta)
torch.cuda.synchronize()

if is_cuda_available:
torch.cuda.synchronize()

print("decode time: {:.3f}s".format((time.time() - time2)), end=" | ")
return results

Expand Down

0 comments on commit 3c9607c

Please sign in to comment.