def get_workers_devices(devices): """ This static method is used by a :class:`Controller` instance to determine which devices should it use in its :class:`Worker`s, in case it is not explicitly given in its arguments. :param devices: list of Theano device ids specified in arguments .. note:: Devices fall to defaults, if they cannot be found with any available Platoon configuration method. Default devices are all CUDA devices in host. .. warning:: If any devices cannot be inferred at all, process exits. .. versionadded:: 0.6.0 """ # Get :class:`Controller`'s devices import socket hostname = socket.gethostname() if devices: # 1. Use device names from arguments if they are specified devices_found = devices else: # 2. Try device names from configuration from platoon import configparser try: devices_found = configparser.fetch_devices_for_host(hostname) except KeyError: # 3. Else try to use all compatible GPUs in host try: print("WARNING! Using all compatible GPUs in " + hostname + ".", file=sys.stderr) from pygpu import gpuarray as ga devcount = ga.count_devices("cuda", 0) print("WARNING! Found {} GPUs!".format(devcount), file=sys.stderr) devices_found = ["cuda" + str(i) for i in range(devcount)] except ImportError: print("ERROR! Could not fetch devices for Controller.", file=sys.stderr) sys.exit(2) except Exception as exc: print("ERROR! pygpu: {}".format(exc), file=sys.stderr) print("ERROR! Could not fetch devices for Controller.", file=sys.stderr) sys.exit(2) if not devices_found: print("ERROR! Cound not find any compatible GPUs in " + hostname + ".", file=sys.stderr) sys.exit(4) print("## On " + hostname + " using: " + " ".join(devices_found)) return devices_found
def n_gpu_getter(mp_n_gpu): """ Call in a subprocess because it prevents future subprocesses from using GPU. """ try: from pygpu import gpuarray except ImportError as exc: raise exc("Must have pygpu installed to use GPUs.") mp_n_gpu.value = gpuarray.count_devices("cuda", 0)
def n_gpu_subprocess(mp_n_gpu): """ Call in a subprocess because it prevents future subprocesses from using GPU. """ try: from pygpu import gpuarray mp_n_gpu.value = gpuarray.count_devices("cuda", 0) except ImportError: mp_n_gpu.value = -1