Skip to content

Commit 42cf30e

Browse files
committed
pass along verbosity to get_gpu_info related functions
1 parent 70bc46e commit 42cf30e

File tree

2 files changed

+22
-16
lines changed

2 files changed

+22
-16
lines changed

src/interface_py/h2o4gpu/libs/lib_utils.py

+15-13
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def __init__(self):
1111
pass
1212

1313
@staticmethod
14-
def get():
14+
def get(verbose=1):
1515
"""Get the CPU module object"""
1616
# SWIG generated files contain some deprecated calls to imp
1717
with warnings.catch_warnings():
@@ -20,10 +20,11 @@ def get():
2020
import h2o4gpu.libs.ch2o4gpu_cpu as ch2o4gpu_cpu
2121
return ch2o4gpu_cpu
2222
except ImportError as e:
23-
print("Exception:")
24-
print(e)
25-
print('\nWarning: h2o4gpu shared object (dynamic library)'
26-
' for CPU failed to load.')
23+
if verbose > 0:
24+
print("Exception:")
25+
print(e)
26+
print('\nWarning: h2o4gpu shared object (dynamic library)'
27+
' for CPU failed to load.')
2728
return None
2829

2930

@@ -35,7 +36,7 @@ def __init__(self):
3536
pass
3637

3738
@staticmethod
38-
def get():
39+
def get(verbose=1):
3940
"""Get the GPU module object"""
4041
# SWIG generated files contain some deprecated calls to imp
4142
with warnings.catch_warnings():
@@ -44,17 +45,18 @@ def get():
4445
import h2o4gpu.libs.ch2o4gpu_gpu as ch2o4gpu_gpu
4546
return ch2o4gpu_gpu
4647
except ImportError as e:
47-
print("Exception:")
48-
print(e)
49-
print('\nWarning: h2o4gpu shared object (dynamic library)'
50-
' for GPU failed to load.')
48+
if verbose > 0:
49+
print("Exception:")
50+
print(e)
51+
print('\nWarning: h2o4gpu shared object (dynamic library)'
52+
' for GPU failed to load.')
5153
return None
5254

5355

54-
def get_lib(n_gpus, devices, verbose=0):
56+
def get_lib(n_gpus, devices, verbose=1):
5557
"""Load either CPU or GPU H2O4GPU library."""
56-
cpu_lib = CPUlib().get()
57-
gpu_lib = GPUlib().get()
58+
cpu_lib = CPUlib().get(verbose=verbose)
59+
gpu_lib = GPUlib().get(verbose=verbose)
5860
if (n_gpus == 0) or \
5961
(gpu_lib is None and cpu_lib is not None) or \
6062
(devices == 0):

src/interface_py/h2o4gpu/util/gpu.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ def get_gpu_info_c(return_usage=False,
178178

179179
try:
180180
from ..libs.lib_utils import GPUlib
181-
lib = GPUlib().get()
181+
lib = GPUlib().get(verbose=0 if not verbose else 1)
182182

183183
total_gpus_actual = \
184184
lib.get_gpu_info_c(usages_tmp, total_mems_tmp, free_mems_tmp,
@@ -290,8 +290,12 @@ def get_compute_capability(gpu_id):
290290
"""
291291
Get compute capability for all gpus
292292
"""
293-
total_gpus, _, _, majors, minors =\
294-
get_gpu_info_c(return_capability=True)
293+
try:
294+
total_gpus, _, _, majors, minors =\
295+
get_gpu_info_c(return_capability=True)
296+
# pylint: disable=bare-except
297+
except:
298+
total_gpus = 0
295299
if total_gpus > 0:
296300
gpu_id = gpu_id % total_gpus
297301
device_major = majors.tolist()[gpu_id]

0 commit comments

Comments
 (0)