From ed425d2465fbcdcd77673b34243cb99a19d22527 Mon Sep 17 00:00:00 2001 From: Piero Toffanin Date: Mon, 30 May 2022 15:52:13 -0400 Subject: [PATCH] Add --no-gpu flag --- opendm/config.py | 8 +++++++- opendm/gpu.py | 10 ++++++---- opendm/osfm.py | 2 +- stages/openmvs.py | 2 +- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/opendm/config.py b/opendm/config.py index 30ad5e79..7c21f2c0 100755 --- a/opendm/config.py +++ b/opendm/config.py @@ -269,7 +269,13 @@ def config(argv=None, parser=None): 'caps the maximum resolution of image outputs and ' 'resizes images when necessary, resulting in faster processing and ' 'lower memory usage. Since GSD is an estimate, sometimes ignoring it can result in slightly better image output quality. Default: %(default)s') - + + parser.add_argument('--no-gpu', + action=StoreTrue, + nargs=0, + default=False, + help='Do not use GPU acceleration, even if it\'s available. Default: %(default)s') + parser.add_argument('--mesh-size', metavar='', action=StoreValue, diff --git a/opendm/gpu.py b/opendm/gpu.py index 97b2e02d..f3b9e1b8 100644 --- a/opendm/gpu.py +++ b/opendm/gpu.py @@ -5,7 +5,7 @@ import ctypes from opendm import log from repoze.lru import lru_cache -def gpu_disabled_by_user(): +def gpu_disabled_by_user_env(): return bool(os.environ.get('ODM_NO_GPU')) @lru_cache(maxsize=None) @@ -68,11 +68,13 @@ def get_cuda_compute_version(device_id = 0): return (compute_major.value, compute_minor.value) -@lru_cache(maxsize=None) -def has_gpu(): - if gpu_disabled_by_user(): +def has_gpu(args): + if gpu_disabled_by_user_env(): log.ODM_INFO("Disabling GPU features (ODM_NO_GPU is set)") return False + if args.no_gpu: + log.ODM_INFO("Disabling GPU features (--no-gpu is set)") + return False if sys.platform == 'win32': nvcuda_path = os.path.join(os.environ.get('SYSTEMROOT'), 'system32', 'nvcuda.dll') diff --git a/opendm/osfm.py b/opendm/osfm.py index 7a74295d..7623b90a 100644 --- a/opendm/osfm.py +++ b/opendm/osfm.py @@ -251,7 +251,7 @@ class OSFMContext: config.append("matcher_type: %s" % osfm_matchers[matcher_type]) # GPU acceleration? - if has_gpu(): + if has_gpu(args): max_photo = find_largest_photo(photos) w, h = max_photo.width, max_photo.height if w > h: diff --git a/stages/openmvs.py b/stages/openmvs.py index 9ea5b49c..02c4ec5e 100644 --- a/stages/openmvs.py +++ b/stages/openmvs.py @@ -76,7 +76,7 @@ class ODMOpenMVSStage(types.ODM_Stage): gpu_config = [] - if not has_gpu(): + if not has_gpu(args): gpu_config.append("--cuda-device -2") if args.pc_tile: