OpenDroneMap-ODM/opendm/gpu.py

45 wiersze
1.4 KiB
Python
Czysty Zwykły widok Historia

2021-03-23 19:15:47 +00:00
import os
2021-11-24 16:26:03 +00:00
import sys
2021-12-16 19:36:17 +00:00
import shutil
2021-02-09 17:14:05 +00:00
from opendm import log
from repoze.lru import lru_cache
2021-11-12 15:41:41 +00:00
def gpu_disabled_by_user():
return bool(os.environ.get('ODM_NO_GPU'))
2021-02-09 17:14:05 +00:00
@lru_cache(maxsize=None)
def has_popsift_and_can_handle_texsize(width, height):
try:
2021-12-16 19:36:17 +00:00
from opensfm import pypopsift
fits = pypopsift.fits_texture(int(width * 1.025), int(height * 1.025))
if not fits:
log.ODM_WARNING("Image size (%sx%spx) would not fit in GPU memory, falling back to CPU" % (width, height))
return fits
2021-12-17 17:12:41 +00:00
except (ModuleNotFoundError, ImportError):
return False
except Exception as e:
log.ODM_WARNING(str(e))
return False
2021-02-09 17:14:05 +00:00
2021-12-16 19:36:17 +00:00
@lru_cache(maxsize=None)
def has_gpu():
if gpu_disabled_by_user():
log.ODM_INFO("Disabling GPU features (ODM_NO_GPU is set)")
2021-02-09 17:14:05 +00:00
return False
if sys.platform == 'win32':
nvcuda_path = os.path.join(os.environ.get('SYSTEMROOT'), 'system32', 'nvcuda.dll')
if os.path.isfile(nvcuda_path):
2022-02-03 14:13:25 +00:00
log.ODM_INFO("CUDA drivers detected")
2021-12-16 19:36:17 +00:00
return True
else:
log.ODM_INFO("No CUDA drivers detected, using CPU")
2021-12-16 19:36:17 +00:00
return False
else:
2021-12-16 19:36:17 +00:00
if shutil.which('nvidia-smi') is not None:
2022-02-03 14:13:25 +00:00
log.ODM_INFO("nvidia-smi detected")
2021-12-16 19:36:17 +00:00
return True
else:
log.ODM_INFO("nvidia-smi not found in PATH, using CPU")
return False