def get_gpu(): """Returns video device as listed by WMI.""" wbem = _get_wmi_wbem() if not wbem: return None, None dimensions = set() state = set() # https://msdn.microsoft.com/library/aa394512.aspx for device in wbem.ExecQuery('SELECT * FROM Win32_VideoController'): # The string looks like: # PCI\VEN_15AD&DEV_0405&SUBSYS_040515AD&REV_00\3&2B8E0B4B&0&78 pnp_string = device.PNPDeviceID ven_id = u'UNKNOWN' dev_id = u'UNKNOWN' match = re.search(r'VEN_([0-9A-F]{4})', pnp_string) if match: ven_id = match.group(1).lower() match = re.search(r'DEV_([0-9A-F]{4})', pnp_string) if match: dev_id = match.group(1).lower() dev_name = device.VideoProcessor or u'' version = device.DriverVersion or u'' ven_name, dev_name = gpu.ids_to_names(ven_id, u'', dev_id, dev_name) dimensions.add(unicode(ven_id)) dimensions.add(u'%s:%s' % (ven_id, dev_id)) if version: state.add(u'%s %s %s' % (ven_name, dev_name, version)) else: state.add(u'%s %s' % (ven_name, dev_name)) return sorted(dimensions), sorted(state)
def get_gpu(): """Returns video device as listed by 'system_profiler'. Not cached as the GPU driver may change underneat. """ dimensions = set() state = set() for card in _get_system_profiler('SPDisplaysDataType'): # Warning: the value provided depends on the driver manufacturer. # Other interesting values: spdisplays_vram, spdisplays_revision-id ven_id = None if 'spdisplays_vendor-id' in card: # NVidia ven_id = card['spdisplays_vendor-id'][2:] elif 'spdisplays_vendor' in card: # Intel and ATI match = re.search(r'\(0x([0-9a-f]{4})\)', card['spdisplays_vendor']) if match: ven_id = match.group(1) dev_id = card['spdisplays_device-id'][2:] # Looks like: u'4.0.20 [3.2.8]' version = unicode(card.get('spdisplays_gmux-version', u'')) # VMWare doesn't set it. dev_name = unicode(card.get('sppci_model', u'')) ven_name = '' if dev_name: # The first word is pretty much always the company name on OSX. split_name = dev_name.split(' ', 1) ven_name = split_name[0] dev_name = split_name[1] # macOS 10.13 stopped including the vendor ID in the spdisplays_vendor # string. Infer it from the vendor name instead. if not ven_id: ven_id = gpu.vendor_name_to_id(ven_name) if not ven_id: ven_id = u'UNKNOWN' ven_name, dev_name = gpu.ids_to_names(ven_id, ven_name, dev_id, dev_name) dimensions.add(unicode(ven_id)) dimensions.add(u'%s:%s' % (ven_id, dev_id)) if version: match = re.search(r'([0-9.]+) \[([0-9.]+)\]', version) if match: dimensions.add( u'%s:%s-%s-%s' % (ven_id, dev_id, match.group(1), match.group(2))) state.add(u'%s %s %s' % (ven_name, dev_name, version)) else: state.add(u'%s %s' % (ven_name, dev_name)) return sorted(dimensions), sorted(state)
def get_gpu(): """Returns video device as listed by 'lspci'. See get_gpu(). Not cached as the GPU driver may change underneat. """ pci_devices = _lspci() if not pci_devices: # It normally happens on Google Compute Engine as lspci is not installed by # default and on ARM since they do not have a PCI bus. In either case, we # don't care about the GPU. return None, None dimensions = set() state = set() re_id = re.compile(r'^(.+?) \[([0-9a-f]{4})\]$') for line in pci_devices: # Look for display class as noted at http://wiki.osdev.org/PCI dev_type = re_id.match(line[1]).group(2) if not dev_type or not dev_type.startswith('03'): continue vendor = re_id.match(line[2]) device = re_id.match(line[3]) if not vendor or not device: continue ven_name = vendor.group(1) ven_id = vendor.group(2) dev_name = device.group(1) dev_id = device.group(2) # TODO(maruel): Implement for AMD once needed. version = u'' if ven_id == gpu.NVIDIA: version = _get_nvidia_version() elif ven_id == gpu.INTEL: version = _get_intel_version() ven_name, dev_name = gpu.ids_to_names(ven_id, ven_name, dev_id, dev_name) dimensions.add(unicode(ven_id)) dimensions.add(u'%s:%s' % (ven_id, dev_id)) if version: dimensions.add(u'%s:%s-%s' % (ven_id, dev_id, version)) state.add(u'%s %s %s' % (ven_name, dev_name, version)) else: state.add(u'%s %s' % (ven_name, dev_name)) return sorted(dimensions), sorted(state)
def get_gpu(): """Returns video device as listed by WMI. Not cached as the GPU driver may change underneat. """ wbem = _get_wmi_wbem() if not wbem: return None, None client = _get_win32com() dimensions = set() state = set() # https://msdn.microsoft.com/library/aa394512.aspx try: for device in wbem.ExecQuery('SELECT * FROM Win32_VideoController'): # The string looks like: # PCI\VEN_15AD&DEV_0405&SUBSYS_040515AD&REV_00\3&2B8E0B4B&0&78 pnp_string = device.PNPDeviceID ven_id = u'UNKNOWN' dev_id = u'UNKNOWN' match = re.search(r'VEN_([0-9A-F]{4})', pnp_string) if match: ven_id = match.group(1).lower() match = re.search(r'DEV_([0-9A-F]{4})', pnp_string) if match: dev_id = match.group(1).lower() dev_name = device.VideoProcessor or u'' version = device.DriverVersion or u'' ven_name, dev_name = gpu.ids_to_names(ven_id, u'', dev_id, dev_name) dimensions.add(unicode(ven_id)) dimensions.add(u'%s:%s' % (ven_id, dev_id)) if version: dimensions.add(u'%s:%s-%s' % (ven_id, dev_id, version)) state.add(u'%s %s %s' % (ven_name, dev_name, version)) else: state.add(u'%s %s' % (ven_name, dev_name)) except client.com_error as e: # This generally happens when this is called as the host is shutting down. logging.error('get_gpu(): %s', e) return sorted(dimensions), sorted(state)
def get_gpu(): """Returns video device as listed by 'system_profiler'. See get_gpu().""" dimensions = set() state = set() for card in _get_system_profiler('SPDisplaysDataType'): # Warning: the value provided depends on the driver manufacturer. # Other interesting values: spdisplays_vram, spdisplays_revision-id ven_id = u'UNKNOWN' if 'spdisplays_vendor-id' in card: # NVidia ven_id = card['spdisplays_vendor-id'][2:] elif 'spdisplays_vendor' in card: # Intel and ATI match = re.search(r'\(0x([0-9a-f]{4})\)', card['spdisplays_vendor']) if match: ven_id = match.group(1) dev_id = card['spdisplays_device-id'][2:] # Looks like: u'4.0.20 [3.2.8]' version = unicode(card.get('spdisplays_gmux-version', u'')) # VMWare doesn't set it. dev_name = unicode(card.get('sppci_model', u'')) if dev_name: # The first word is pretty much always the company name on OSX so strip # it. dev_name = dev_name.split(' ', 1)[-1] ven_name, dev_name = gpu.ids_to_names(ven_id, u'', dev_id, dev_name) dimensions.add(unicode(ven_id)) dimensions.add(u'%s:%s' % (ven_id, dev_id)) if version: state.add(u'%s %s %s' % (ven_name, dev_name, version)) else: state.add(u'%s %s' % (ven_name, dev_name)) return sorted(dimensions), sorted(state)