kopia lustrzana https://github.com/OpenDroneMap/ODM
commit
922d5fa355
|
@ -1,6 +1,7 @@
|
|||
import os
|
||||
import sys
|
||||
import shutil
|
||||
import ctypes
|
||||
from opendm import log
|
||||
from repoze.lru import lru_cache
|
||||
|
||||
|
@ -9,9 +10,21 @@ def gpu_disabled_by_user():
|
|||
|
||||
@lru_cache(maxsize=None)
|
||||
def has_popsift_and_can_handle_texsize(width, height):
|
||||
# We first check that we have the required compute capabilities
|
||||
# As we do not support compute capabilities less than 3.5
|
||||
try:
|
||||
compute_major, compute_minor = get_cuda_compute_version(0)
|
||||
if compute_major < 3 or (compute_major == 3 and compute_minor < 5):
|
||||
# Not supported
|
||||
log.ODM_WARNING("CUDA compute platform is not supported (detected: %s.%s but we need at least 3.5)" % (compute_major, compute_minor))
|
||||
return False
|
||||
except Exception as e:
|
||||
log.ODM_WARNING("Cannot use GPU for feature extraction: %s" % str(e))
|
||||
return False
|
||||
|
||||
try:
|
||||
from opensfm import pypopsift
|
||||
fits = pypopsift.fits_texture(int(width * 1.025), int(height * 1.025))
|
||||
fits = pypopsift.fits_texture(int(width * 1.02), int(height * 1.02))
|
||||
if not fits:
|
||||
log.ODM_WARNING("Image size (%sx%spx) would not fit in GPU memory, falling back to CPU" % (width, height))
|
||||
return fits
|
||||
|
@ -21,6 +34,40 @@ def has_popsift_and_can_handle_texsize(width, height):
|
|||
log.ODM_WARNING(str(e))
|
||||
return False
|
||||
|
||||
@lru_cache(maxsize=None)
|
||||
def get_cuda_compute_version(device_id = 0):
|
||||
cuda_lib = "libcuda.so"
|
||||
if sys.platform == 'win32':
|
||||
cuda_lib = "nvcuda.dll"
|
||||
|
||||
nvcuda = ctypes.cdll.LoadLibrary(cuda_lib)
|
||||
|
||||
nvcuda.cuInit.argtypes = (ctypes.c_uint32, )
|
||||
nvcuda.cuInit.restypes = (ctypes.c_int32)
|
||||
|
||||
if nvcuda.cuInit(0) != 0:
|
||||
raise Exception("Cannot initialize CUDA")
|
||||
|
||||
nvcuda.cuDeviceGetCount.argtypes = (ctypes.POINTER(ctypes.c_int32), )
|
||||
nvcuda.cuDeviceGetCount.restypes = (ctypes.c_int32)
|
||||
|
||||
device_count = ctypes.c_int32()
|
||||
if nvcuda.cuDeviceGetCount(ctypes.byref(device_count)) != 0:
|
||||
raise Exception("Cannot get device count")
|
||||
|
||||
if device_count.value == 0:
|
||||
raise Exception("No devices")
|
||||
|
||||
nvcuda.cuDeviceComputeCapability.argtypes = (ctypes.POINTER(ctypes.c_int32), ctypes.POINTER(ctypes.c_int32), ctypes.c_int32)
|
||||
nvcuda.cuDeviceComputeCapability.restypes = (ctypes.c_int32)
|
||||
compute_major = ctypes.c_int32()
|
||||
compute_minor = ctypes.c_int32()
|
||||
|
||||
if nvcuda.cuDeviceComputeCapability(ctypes.byref(compute_major), ctypes.byref(compute_minor), device_id) != 0:
|
||||
raise Exception("Cannot get CUDA compute version")
|
||||
|
||||
return (compute_major.value, compute_minor.value)
|
||||
|
||||
@lru_cache(maxsize=None)
|
||||
def has_gpu():
|
||||
if gpu_disabled_by_user():
|
||||
|
|
|
@ -257,6 +257,7 @@ class OSFMContext:
|
|||
if has_popsift_and_can_handle_texsize(w, h) and feature_type == "SIFT":
|
||||
log.ODM_INFO("Using GPU for extracting SIFT features")
|
||||
feature_type = "SIFT_GPU"
|
||||
self.gpu_sift_feature_extraction = True
|
||||
|
||||
config.append("feature_type: %s" % feature_type)
|
||||
|
||||
|
@ -361,7 +362,18 @@ class OSFMContext:
|
|||
matches_dir = self.path("matches")
|
||||
|
||||
if not io.dir_exists(features_dir) or rerun:
|
||||
self.run('detect_features')
|
||||
try:
|
||||
self.run('detect_features')
|
||||
except system.SubprocessException as e:
|
||||
# Sometimes feature extraction by GPU can fail
|
||||
# for various reasons, so before giving up
|
||||
# we try to fallback to CPU
|
||||
if hasattr(self, 'gpu_sift_feature_extraction'):
|
||||
log.ODM_WARNING("GPU SIFT extraction failed, maybe the graphics card is not supported? Attempting fallback to CPU")
|
||||
self.update_config({'feature_type': "SIFT"})
|
||||
self.run('detect_features')
|
||||
else:
|
||||
raise e
|
||||
else:
|
||||
log.ODM_WARNING('Detect features already done: %s exists' % features_dir)
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue