mirror of
https://github.com/wassname/ray.git
synced 2026-07-15 11:25:40 +08:00
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:
committed by
Robert Nishihara
parent
6aae9a12fb
commit
7009538321
@@ -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(
|
||||
|
||||
@@ -1224,7 +1224,9 @@ def _init(address_info=None,
|
||||
num_cpus (int): Number of cpus the user wishes all local schedulers to
|
||||
be configured with.
|
||||
num_gpus (int): Number of gpus the user wishes all local schedulers to
|
||||
be configured with.
|
||||
be configured with. If unspecified, Ray will attempt to autodetect
|
||||
the number of GPUs available on the node (note that autodetection
|
||||
currently only works for Nvidia GPUs).
|
||||
resources: A dictionary mapping resource names to the quantity of that
|
||||
resource available.
|
||||
num_redis_shards: The number of Redis shards to start in addition to
|
||||
|
||||
Reference in New Issue
Block a user