figure out what GPU devices are available and choose the supported ones.
165655
def dev_setup():
    ''''''

    # check first if NiftyPET was already installed and use the choice of GPU
    path_resources = path_niftypet_local()
    # if so, import the resources and get the constants
    if os.path.isfile(os.path.join(path_resources,'resources.py')):
        sys.path.append(path_resources)
        try:
            import resources
        except ImportError as ie:
            print '----------------------------'
            print 'e> Import Error: NiftyPET''s resources file <resources.py> could not be imported.  It should be in ''~/.niftypet/resources.py'' but likely it does not exists.'
            print '----------------------------'
    else:
        print 'e> resources file not found/installed.'
        return None

    # get all constants and check if device is already chosen
    Cnt = resources.get_setup()
    if 'CCARCH' in Cnt and 'DEVID' in Cnt:
        print 'i> using this CUDA architecture(s):', Cnt['CCARCH']
        return Cnt['CCARCH']

    # get the current locations
    path_current = os.path.dirname( os.path.realpath(__file__) )
    path_resins = os.path.join(path_current, 'resources')
    path_dinf = os.path.join(path_current, 'niftypet')
    path_dinf = os.path.join(path_dinf, 'nimpa')
    path_dinf = os.path.join(path_dinf, 'dinf')
    # temporary installation location for identifying the CUDA devices
    path_tmp_dinf = os.path.join(path_resins,'dinf')
    # if the folder 'path_tmp_dinf' exists, delete it
    if os.path.isdir(path_tmp_dinf):
        shutil.rmtree(path_tmp_dinf)
    # copy the device_info module to the resources folder within the installation package
    shutil.copytree( path_dinf, path_tmp_dinf)
    # create a build using cmake
    if platform.system()=='Windows':
        path_tmp_build = os.path.join(path_tmp_dinf, 'build')
    elif platform.system() in ['Linux', 'Darwin']:
        path_tmp_build = os.path.join(path_tmp_dinf, 'build')
    else:
        print 'w> the operating system {} is not supported for GPU'.format(platform.system())
        return ''
        
    os.makedirs(path_tmp_build)
    os.chdir(path_tmp_build)
    if platform.system()=='Windows':
        subprocess.call(
            ['cmake', '../', '-DPYTHON_INCLUDE_DIRS='+pyhdr,
             '-DPYTHON_PREFIX_PATH='+prefix, '-G', Cnt['MSVC_VRSN']]
        )
        subprocess.call(['cmake', '--build', './', '--config', 'Release'])
        path_tmp_build = os.path.join(path_tmp_build, 'Release')

    elif platform.system() in ['Linux', 'Darwin']:
        subprocess.call(
            ['cmake', '../', '-DPYTHON_INCLUDE_DIRS='+pyhdr,
             '-DPYTHON_PREFIX_PATH='+prefix]
        )
        subprocess.call(['cmake', '--build', './'])
    else:
        print 'e> This operating systems {} is not supported!'.format(platform.system())
        return ''
    
    # imoprt the new module for device properties
    sys.path.insert(0, path_tmp_build)
    try:
        import dinf
    except ImportError:
        print 'e> could not compile a CUDA C file--assuming no CUDA installation.'
        return ''
    
    # get the list of installed CUDA devices
    Ldev = dinf.dev_info(0)
    # extract the compute capability as a single number 
    cclist = [int(str(e[2])+str(e[3])) for e in Ldev]
    # get the list of supported CUDA devices (with minimum compute capability)
    spprtd = [str(cc) for cc in cclist if cc>=mincc]
    ccstr = ''
    if spprtd:
        # best for the default CUDA device
        i = [int(s) for s in spprtd]
        devid = i.index(max(i))
        #-----------------------------------------------------------------------------------
        # form return list of compute capability numbers for which the software will be compiled
        
        for cc in spprtd:
            ccstr += '-gencode=arch=compute_'+cc+',code=compute_'+cc+';'
        #-----------------------------------------------------------------------------------
    else:
        devid = None

    # remove the temporary path
    sys.path.remove(path_tmp_build)
    # delete the build once the info about the GPUs has been obtained
    os.chdir(path_current)
    shutil.rmtree(path_tmp_dinf, ignore_errors=True)

    # passing this setting to resources.py
    fpth = os.path.join(path_resources,'resources.py') #resource_filename(__name__, 'resources/resources.py')
    f = open(fpth, 'r')
    rsrc = f.read()
    f.close()
    # get the region of keeping in synch with Python
    i0 = rsrc.find('### start GPU properties ###')
    i1 = rsrc.find('### end GPU properties ###')
    # list of constants which will be kept in sych from Python
    cnt_list = ['DEV_ID', 'CC_ARCH']
    val_list = [str(devid), '\''+ccstr+'\'']
    # update the resource.py file
    strNew = '### start GPU properties ###\n'
    for i in range(len(cnt_list)):
        strNew += cnt_list[i]+' = '+val_list[i] + '\n'
    rsrcNew = rsrc[:i0] + strNew + rsrc[i1:] 
    f = open(fpth, 'w')
    f.write(rsrcNew)
    f.close()

    return ccstr
143724
private function _buildHardware()
    {
        $hardware = $this->_xml->addChild('Hardware');
        if ($this->_sys->getMachine() != "") {
            $hardware->addAttribute('Name', $this->_sys->getMachine());
        }
        $pci = null;
        foreach (System::removeDupsAndCount($this->_sys->getPciDevices()) as $dev) {
            if ($pci === null) $pci = $hardware->addChild('PCI');
            $tmp = $pci->addChild('Device');
            $tmp->addAttribute('Name', $dev->getName());
            if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
                if ($dev->getManufacturer() !== null) {
                    $tmp->addAttribute('Manufacturer', $dev->getManufacturer());
                }
                if ($dev->getProduct() !== null) {
                    $tmp->addAttribute('Product', $dev->getProduct());
                }
            }
            if ($dev->getCount() > 1) {
                $tmp->addAttribute('Count', $dev->getCount());
            }
        }
        $usb = null;
        foreach (System::removeDupsAndCount($this->_sys->getUsbDevices()) as $dev) {
            if ($usb === null) $usb = $hardware->addChild('USB');
            $tmp = $usb->addChild('Device');
            $tmp->addAttribute('Name', $dev->getName());
            if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
                if ($dev->getManufacturer() !== null) {
                    $tmp->addAttribute('Manufacturer', $dev->getManufacturer());
                }
                if ($dev->getProduct() !== null) {
                    $tmp->addAttribute('Product', $dev->getProduct());
                }
                if (defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL && ($dev->getSerial() !== null)) {
                    $tmp->addAttribute('Serial', $dev->getSerial());
                }
            }
            if ($dev->getCount() > 1) {
                $tmp->addAttribute('Count', $dev->getCount());
            }
        }
        $ide = null;
        foreach (System::removeDupsAndCount($this->_sys->getIdeDevices()) as $dev) {
            if ($ide === null) $ide = $hardware->addChild('IDE');
            $tmp = $ide->addChild('Device');
            $tmp->addAttribute('Name', $dev->getName());
            if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
                if ($dev->getCapacity() !== null) {
                    $tmp->addAttribute('Capacity', $dev->getCapacity());
                }
                if (defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL && ($dev->getSerial() !== null)) {
                    $tmp->addAttribute('Serial', $dev->getSerial());
                }
            }
            if ($dev->getCount() > 1) {
                $tmp->addAttribute('Count', $dev->getCount());
            }
        }
        $scsi = null;
        foreach (System::removeDupsAndCount($this->_sys->getScsiDevices()) as $dev) {
            if ($scsi === null) $scsi = $hardware->addChild('SCSI');
            $tmp = $scsi->addChild('Device');
            $tmp->addAttribute('Name', $dev->getName());
            if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
                if ($dev->getCapacity() !== null) {
                    $tmp->addAttribute('Capacity', $dev->getCapacity());
                }
                if (defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL && ($dev->getSerial() !== null)) {
                    $tmp->addAttribute('Serial', $dev->getSerial());
                }
            }
            if ($dev->getCount() > 1) {
                $tmp->addAttribute('Count', $dev->getCount());
            }
        }
        $nvme = null;
        foreach (System::removeDupsAndCount($this->_sys->getNvmeDevices()) as $dev) {
            if ($nvme === null) $nvme = $hardware->addChild('NVMe');
            $tmp = $nvme->addChild('Device');
            $tmp->addAttribute('Name', $dev->getName());
            if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
                if ($dev->getCapacity() !== null) {
                    $tmp->addAttribute('Capacity', $dev->getCapacity());
                }
                if (defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL && ($dev->getSerial() !== null)) {
                    $tmp->addAttribute('Serial', $dev->getSerial());
                }
            }
            if ($dev->getCount() > 1) {
                $tmp->addAttribute('Count', $dev->getCount());
            }
        }
        $tb = null;
        foreach (System::removeDupsAndCount($this->_sys->getTbDevices()) as $dev) {
            if ($tb === null) $tb = $hardware->addChild('TB');
            $tmp = $tb->addChild('Device');
            $tmp->addAttribute('Name', $dev->getName());
            if ($dev->getCount() > 1) {
                $tmp->addAttribute('Count', $dev->getCount());
            }
        }
        $i2c = null;
        foreach (System::removeDupsAndCount($this->_sys->getI2cDevices()) as $dev) {
            if ($i2c === null) $i2c = $hardware->addChild('I2C');
            $tmp = $i2c->addChild('Device');
            $tmp->addAttribute('Name', $dev->getName());
            if ($dev->getCount() > 1) {
                $tmp->addAttribute('Count', $dev->getCount());
            }
        }

        $cpu = null;
        foreach ($this->_sys->getCpus() as $oneCpu) {
            if ($cpu === null) $cpu = $hardware->addChild('CPU');
            $tmp = $cpu->addChild('CpuCore');
            $tmp->addAttribute('Model', $oneCpu->getModel());
            if ($oneCpu->getCpuSpeed() !== 0) {
                $tmp->addAttribute('CpuSpeed', max($oneCpu->getCpuSpeed(), 0));
            }
            if ($oneCpu->getCpuSpeedMax() !== 0) {
                $tmp->addAttribute('CpuSpeedMax', $oneCpu->getCpuSpeedMax());
            }
            if ($oneCpu->getCpuSpeedMin() !== 0) {
                $tmp->addAttribute('CpuSpeedMin', $oneCpu->getCpuSpeedMin());
            }
/*
            if ($oneCpu->getTemp() !== null) {
                $tmp->addAttribute('CpuTemp', $oneCpu->getTemp());
            }
*/
            if ($oneCpu->getBusSpeed() !== null) {
                $tmp->addAttribute('BusSpeed', $oneCpu->getBusSpeed());
            }
            if ($oneCpu->getCache() !== null) {
                $tmp->addAttribute('Cache', $oneCpu->getCache());
            }
            if ($oneCpu->getVirt() !== null) {
                $tmp->addAttribute('Virt', $oneCpu->getVirt());
            }
            if ($oneCpu->getBogomips() !== null) {
                $tmp->addAttribute('Bogomips', $oneCpu->getBogomips());
            }
            if ($oneCpu->getLoad() !== null) {
                $tmp->addAttribute('Load', $oneCpu->getLoad());
            }
        }
    }
1138649
def add_on_gpu(self, transforms):
        """"""
        if not isinstance(transforms, list):
            transforms = [transforms]
        self.gpu_transforms.extend(transforms or [])
        return self
828654
def get_driver_platform(self):
        
        platform = ''
        if 'platform' in self.driver.desired_capabilities:
            platform = self.driver.desired_capabilities['platform']
        elif 'platformName' in self.driver.desired_capabilities:
            platform = self.driver.desired_capabilities['platformName']
        return platform
47368
def postActivate_(self):
        
        if (self.requiredGPU_MB(self.required_mb)):
            self.analyzer = YoloV3Analyzer(verbose = self.verbose)
        else:
            self.warning_message = "WARNING: not enough GPU memory!"
            self.analyzer = None
424920
def main( gpu:Param("GPU to run on", str)=None ):
    """"""
    gpu = setup_distrib(gpu)
    n_gpus = num_distrib()
    path = url2path(URLs.CIFAR)
    ds_tfms = ([*rand_pad(4, 32), flip_lr(p=0.5)], [])
    workers = min(16, num_cpus()//n_gpus)
    data = ImageDataBunch.from_folder(path, valid='test', ds_tfms=ds_tfms, bs=512//n_gpus,
                                      num_workers=workers).normalize(cifar_stats)
    learn = Learner(data, wrn_22(), metrics=accuracy)
    if gpu is None: learn.model = nn.DataParallel(learn.model)
    else: learn.to_distributed(gpu)
    learn.to_fp16()
    learn.fit_one_cycle(35, 3e-3, wd=0.4)
1245814
def _check_type(self):
        '''
        '''

        if self.type not in self.available_types:
            msg = 'Unsupported cluster type was given: %s' % self.type
            raise DeviceGroupNotSupported(msg)
        elif self.type == 'sync-only' and self.name != 'device_trust_group':
            msg = "Management of sync-only device groups only supported for " \
                "built-in device group named 'device_trust_group'"
            raise DeviceGroupNotSupported(msg)
540600
def gpu_info():
    

    GPUInfo = namedtuple('GPUInfo', ['name', 'driver', 'totalmem', 'freemem'])
    gpus = GPUtil.getGPUs()
    info = []
    for g in gpus:
        info.append(GPUInfo(g.name, g.driver, g.memoryTotal, g.memoryFree))
    return info
734484
def device_info(self):
        """"""
        return {
            'family': self.family,
            'platform': self.platform,
            'os_type': self.os_type,
            'os_version': self.os_version,
            'udi': self.udi,
            # TODO(klstanie): add property to make driver automatically
            'driver_name': self.driver.platform,
            'mode': self.mode,
            'is_console': self.is_console,
            'is_target': self.is_target,
            # 'prompt': self.driver.base_prompt(self.prompt),
            'hostname': self.hostname,
        }
440112
def is_gpu(self):
        
        return self._device.get_info(cl.device_info.TYPE) == cl.device_type.GPU
657420
private function _hardware()
    {
        foreach ($this->_devicelist('PCI') as $pciDev) {
            $dev = new HWDevice();
            $dev->setName($pciDev['Name']);
            if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
                $dev->setManufacturer($pciDev['Manufacturer']);
                $dev->setProduct($pciDev['Product']);
            }
            $this->sys->setPciDevices($dev);
        }

        foreach ($this->_devicelist('IDE') as $ideDev) {
            $dev = new HWDevice();
            $dev->setName($ideDev['Name']);
            if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
                $dev->setCapacity($ideDev['Capacity']);
                if (defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL) {
                    $dev->setSerial($ideDev['Serial']);
                }
            }
            $this->sys->setIdeDevices($dev);
        }

        foreach ($this->_devicelist('SCSI') as $scsiDev) {
            $dev = new HWDevice();
            $dev->setName($scsiDev['Name']);
            if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
                $dev->setCapacity($scsiDev['Capacity']);
                if (defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL) {
                    $dev->setSerial($scsiDev['Serial']);
                }
            }
            $this->sys->setScsiDevices($dev);
        }

        foreach ($this->_devicelist('USB') as $usbDev) {
            $dev = new HWDevice();
            $dev->setName($usbDev['Name']);
            if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
                $dev->setManufacturer($usbDev['Manufacturer']);
                $dev->setProduct($usbDev['Product']);
                if (defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL) {
                    $dev->setSerial($usbDev['Serial']);
                }
            }
            $this->sys->setUsbDevices($dev);
        }
    }
912045
def get_available_devices(self):
        
        connected_devices = self.mbeds.list_mbeds() if self.mbeds else []
        # Check non mbedOS supported devices.
        # Just for backward compatible reason - is obsolete..
        edbg_ports = self.available_edbg_ports()
        for port in edbg_ports:
            connected_devices.append({
                "platform_name": "SAM4E",
                "serial_port": port,
                "mount_point": None,
                "target_id": None,
                "baud_rate": 460800
            })
        for dev in connected_devices:
            dev['state'] = "unknown"

        return connected_devices
967924
def select_device_by_load(wproc=0.5, wmem=0.5):
    

    ids = device_by_load(wproc=wproc, wmem=wmem)
    cp.cuda.Device(ids[0]).use()
    return ids[0]
221371
def get_ordered_devices():
    

    libcudart = get_libcudart()

    devices = {}
    for i in range(0, get_installed_devices()):
        gpu = get_device_properties(i)

        pciBusId = ctypes.create_string_buffer(64)
        libcudart.cudaDeviceGetPCIBusId(ctypes.byref(pciBusId), 64, i)
        full_id = pciBusId.value.decode('utf-8')
        gpu['fullId'] = full_id
        devices[full_id] = gpu

    ordered = []

    i = 0
    for key in sorted(devices):
        devices[key]['id'] = i
        ordered.append(devices[key])
        i += 1

    del libcudart

    return ordered
1112307
def cudaGetDevice():
    

    dev = ctypes.c_int()
    status = _libcudart.cudaGetDevice(ctypes.byref(dev))
    cudaCheckStatus(status)
    return dev.value
976884
def _check_for_supported_vendor(self, profile):
        
        vendor_info = profile.get('pci_vendor_info')
        if not vendor_info:
            return False
        if vendor_info not in self.supported_pci_devs:
            return False
        return True
272675
def _find_devices_win(self):
        """"""
        self._find_xinput()
        self._detect_gamepads()
        self._count_devices()
        if self._raw_device_counts['keyboards'] > 0:
            self.keyboards.append(Keyboard(
                self,
                "/dev/input/by-id/usb-A_Nice_Keyboard-event-kbd"))

        if self._raw_device_counts['mice'] > 0:
            self.mice.append(Mouse(
                self,
                "/dev/input/by-id/usb-A_Nice_Mouse_called_Arthur-event-mouse"))