mirror of
https://github.com/zebrajr/pytorch.git
synced 2025-12-07 12:21:27 +01:00
32 lines
1.1 KiB
Python
32 lines
1.1 KiB
Python
import atexit
|
|
import logging
|
|
import sys
|
|
from caffe2.python import extension_loader
|
|
|
|
# We will first try to load the gpu-enabled caffe2. If it fails, we will then
|
|
# attempt to load the cpu version. The cpu backend is the minimum required, so
|
|
# if that still fails, we will exit loud.
|
|
with extension_loader.DlopenGuard():
|
|
try:
|
|
from .libcaffe2_python_gpu import * # noqa
|
|
if NumCudaDevices():
|
|
has_gpu_support = True
|
|
else:
|
|
has_gpu_support = False
|
|
except ImportError as e:
|
|
logging.warning(
|
|
'This caffe2 python run does not have GPU support. '
|
|
'Will run in CPU only mode.')
|
|
logging.warning('Debug message: {0}'.format(str(e)))
|
|
has_gpu_support = False
|
|
try:
|
|
from .libcaffe2_python_cpu import * # noqa
|
|
except ImportError as e:
|
|
logging.critical(
|
|
'Cannot load caffe2.python. Error: {0}'.format(str(e)))
|
|
sys.exit(1)
|
|
|
|
# libcaffe2_python contains a global Workspace that we need to properly delete
|
|
# when exiting. Otherwise, cudart will cause segfaults sometimes.
|
|
atexit.register(OnModuleExit) # noqa
|