Path: blob/main_old/src/gpu_info_util/SystemInfo_linux.cpp
1693 views
//1// Copyright 2013 The ANGLE Project Authors. All rights reserved.2// Use of this source code is governed by a BSD-style license that can be3// found in the LICENSE file.4//56// SystemInfo_linux.cpp: implementation of the Linux-specific parts of SystemInfo.h78#include "gpu_info_util/SystemInfo_internal.h"910#include <cstring>11#include <fstream>1213#include "common/angleutils.h"14#include "common/debug.h"1516namespace angle17{1819namespace20{2122bool ReadWholeFile(const char *filename, std::string *content)23{24std::ifstream file(filename);2526if (!file)27{28return false;29}3031*content = std::string(std::istreambuf_iterator<char>(file), std::istreambuf_iterator<char>());32return true;33}3435// Scan /sys/module/amdgpu/version.36bool GetAMDBrahmaDriverVersion(std::string *version)37{38*version = "";39std::string content;4041return ReadWholeFile("/sys/module/amdgpu/version", &content) &&42ParseAMDBrahmaDriverVersion(content, version);43}4445// Scan /etc/ati/amdpcsdb.default for "ReleaseVersion".46bool GetAMDCatalystDriverVersion(std::string *version)47{48*version = "";49std::string content;5051return ReadWholeFile("/etc/ati/amdpcsdb.default", &content) &&52ParseAMDCatalystDriverVersion(content, version);53}5455} // anonymous namespace5657#if !defined(GPU_INFO_USE_X11)58bool GetNvidiaDriverVersionWithXNVCtrl(std::string *version)59{60return false;61}62#endif6364#if !defined(GPU_INFO_USE_LIBPCI)65bool GetPCIDevicesWithLibPCI(std::vector<GPUDeviceInfo> *devices)66{67return false;68}69#endif7071bool GetSystemInfo(SystemInfo *info)72{73if (!GetPCIDevicesWithLibPCI(&(info->gpus)))74{75#if defined(ANGLE_HAS_VULKAN_SYSTEM_INFO)76// Try vulkan backend to get GPU info77return GetSystemInfoVulkan(info);78#else79return false;80#endif // defined(ANGLE_HAS_VULKAN_SYSTEM_INFO)81}8283if (info->gpus.size() == 0)84{85return false;86}8788GetDualGPUInfo(info);8990for (size_t i = 0; i < info->gpus.size(); ++i)91{92GPUDeviceInfo *gpu = &info->gpus[i];9394// New GPUs might be added inside this loop, don't query for their driver version again95if (!gpu->driverVendor.empty())96{97continue;98}99100if (IsAMD(gpu->vendorId))101{102std::string version;103if (GetAMDBrahmaDriverVersion(&version))104{105gpu->driverVendor = "AMD (Brahma)";106gpu->driverVersion = std::move(version);107}108else if (GetAMDCatalystDriverVersion(&version))109{110gpu->driverVendor = "AMD (Catalyst)";111gpu->driverVersion = std::move(version);112}113}114115if (IsNVIDIA(gpu->vendorId))116{117std::string version;118if (GetNvidiaDriverVersionWithXNVCtrl(&version))119{120gpu->driverVendor = "Nvidia";121gpu->driverVersion = std::move(version);122}123}124125// In dual-GPU cases the PCI scan sometimes only gives us the Intel GPU. If we are able to126// query for the Nvidia driver version, it means there was hidden Nvidia GPU, so we add it127// to the list.128if (IsIntel(gpu->vendorId) && info->gpus.size() == 1)129{130std::string version;131if (GetNvidiaDriverVersionWithXNVCtrl(&version))132{133GPUDeviceInfo nvidiaInfo;134nvidiaInfo.vendorId = kVendorID_NVIDIA;135nvidiaInfo.deviceId = 0;136gpu->driverVendor = "Nvidia";137gpu->driverVersion = std::move(version);138139info->gpus.emplace_back(std::move(nvidiaInfo));140info->isOptimus = true;141}142}143}144145return true;146}147148} // namespace angle149150151