2021-03-23 19:15:47 +00:00
|
|
|
import os
|
2021-11-24 16:26:03 +00:00
|
|
|
import sys
|
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_gpus():
|
2021-11-12 15:41:41 +00:00
|
|
|
if gpu_disabled_by_user():
|
2021-03-23 19:15:47 +00:00
|
|
|
log.ODM_INFO("Disabling GPU features (ODM_NO_GPU is set)")
|
|
|
|
return False
|
|
|
|
|
2021-03-05 15:44:08 +00:00
|
|
|
try:
|
|
|
|
import pyopencl
|
|
|
|
except:
|
|
|
|
return False
|
2021-02-09 17:14:05 +00:00
|
|
|
|
|
|
|
try:
|
|
|
|
platforms = pyopencl.get_platforms()
|
2021-02-10 19:00:43 +00:00
|
|
|
for p in platforms:
|
|
|
|
log.ODM_INFO("Found GPU device: %s" % p.name)
|
|
|
|
|
|
|
|
return len(platforms) > 0
|
2021-02-09 17:14:05 +00:00
|
|
|
except Exception as e:
|
|
|
|
return False
|
2021-11-24 16:02:36 +00:00
|
|
|
|
|
|
|
@lru_cache(maxsize=None)
|
|
|
|
def windows_no_cuda():
|
|
|
|
"""
|
|
|
|
Check if CUDA lib is available on Windows
|
|
|
|
Returns true if OS is windows and CUDA is not found.
|
|
|
|
"""
|
|
|
|
if sys.platform == 'win32':
|
|
|
|
nvcuda_path = os.path.join(os.environ.get('SYSTEMROOT'), 'system32', 'nvcuda.dll')
|
|
|
|
if os.path.isfile(nvcuda_path):
|
|
|
|
return False
|
|
|
|
else:
|
|
|
|
log.ODM_INFO("No CUDA drivers detected, using CPU")
|
|
|
|
return True
|
|
|
|
else:
|
|
|
|
return False
|
|
|
|
|