fix: store cuda_available variable and extend perf_counter fix to all get_computational_cost functions#467
Closed
vinitjain2005 wants to merge 3 commits into
Conversation
… get_computational_cost functions
dpascualhe
reviewed
Mar 25, 2026
Collaborator
dpascualhe
left a comment
There was a problem hiding this comment.
Good! Upon fixing these small issues, we can merge.
Reset random sampling for Open3D-ML models during warm-up runs.
Contributor
Author
|
@dpascualhe I have updated the changes |
Collaborator
|
Thanks for addressing the previous concerns! Upon closer inspection, there is a last change that would improve your PR. Could you use the |
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR extends the timing fix originally proposed in the closed PR to all
get_computational_cost()functions across the library, and also addresses the review comment to storetorch.cuda.is_available()in a variable instead of calling it on every loop iteration.Closes #453
Problem
The
get_computational_cost()functions across multiple files had two issues:torch.cuda.synchronize()was called unconditionally on every iteration — it is a no-op on CPU and was designed only for CUDA devicestime.time()was used for timing — it has low resolution on Windows (15ms granularity) causing timing to show 0ms or jump in 15ms chunkstorch.cuda.is_available()was being called on every loop iteration instead of being stored once as a variableFix
Files Changed
perceptionmetrics/models/torch_detection.pyget_computational_cost()functionperceptionmetrics/models/torch_segmentation.pyTorchImageSegmentationModel.get_computational_cost()TorchLiDARSegmentationModel.get_computational_cost()perceptionmetrics/models/tf_segmentation.pyTensorflowImageSegmentationModel.get_computational_cost()has_gpuvariable (already stored before loop)and replaces
time.time()withtime.perf_counter()Impact
Every user running computational cost estimation on CPU gets accurate timing results. This is especially relevant since CUDA is optional and most contributors and new users run on CPU-only machines.
References
torch.cuda.synchronize()only synchronizes CUDA device operationstime.perf_counter()is the recommended high-resolution timer for benchmarkingGithub: @vinitjain2005