-
Notifications
You must be signed in to change notification settings - Fork 7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* make C extension lazy-import * add lazy loading to roi_pool
- Loading branch information
Showing
5 changed files
with
39 additions
and
31 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
_C = None | ||
|
||
|
||
def _lazy_import(): | ||
""" | ||
Make sure that CUDA versions match between the pytorch install and torchvision install | ||
""" | ||
global _C | ||
if _C is not None: | ||
return _C | ||
import torch | ||
from torchvision import _C as C | ||
_C = C | ||
if hasattr(_C, "CUDA_VERSION") and torch.version.cuda is not None: | ||
tv_version = str(_C.CUDA_VERSION) | ||
if int(tv_version) < 10000: | ||
tv_major = int(tv_version[0]) | ||
tv_minor = int(tv_version[2]) | ||
else: | ||
tv_major = int(tv_version[0:2]) | ||
tv_minor = int(tv_version[3]) | ||
t_version = torch.version.cuda | ||
t_version = t_version.split('.') | ||
t_major = int(t_version[0]) | ||
t_minor = int(t_version[1]) | ||
if t_major != tv_major or t_minor != tv_minor: | ||
raise RuntimeError("Detected that PyTorch and torchvision were compiled with different CUDA versions. " | ||
"PyTorch has CUDA Version={}.{} and torchvision has CUDA Version={}.{}. " | ||
"Please reinstall the torchvision that matches your PyTorch install." | ||
.format(t_major, t_minor, tv_major, tv_minor)) | ||
return _C |
This file contains 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
This file contains 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
This file contains 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