Autodetect the number of GPUs when starting Ray. (#1293)

* autodetect

* Wed Dec  6 12:46:52 PST 2017

* Wed Dec  6 12:47:54 PST 2017

* Move GPU autodetection into services.py.

* Fix capitalization of Nvidia.

* Update documentation.
This commit is contained in:
Eric Liang
2017-12-09 15:30:16 -08:00
committed by Robert Nishihara
parent 6aae9a12fb
commit 7009538321
4 changed files with 23 additions and 4 deletions
+17
View File
@@ -279,6 +279,20 @@ def wait_for_redis_to_start(redis_ip_address, redis_port, num_retries=5):
"configured properly.")
def _autodetect_num_gpus():
"""Attempt to detect the number of GPUs on this machine.
TODO(rkn): This currently assumes Nvidia GPUs and Linux.
Returns:
The number of GPUs if any were detected, otherwise 0.
"""
proc_gpus_path = "/proc/driver/nvidia/gpus"
if os.path.isdir(proc_gpus_path):
return len(os.listdir(proc_gpus_path))
return 0
def _compute_version_info():
"""Compute the versions of Python, cloudpickle, pyarrow, and Ray.
@@ -679,6 +693,9 @@ def start_local_scheduler(redis_address,
# By default, use the number of hardware execution threads for the
# number of cores.
resources["CPU"] = psutil.cpu_count()
if "GPU" not in resources:
# Try to automatically detect the number of GPUs.
resources["GPU"] = _autodetect_num_gpus()
print("Starting local scheduler with the following resources: {}."
.format(resources))
local_scheduler_name, p = ray.local_scheduler.start_local_scheduler(