From fb08e621ab5aa891c770ac0716747faaa239a638 Mon Sep 17 00:00:00 2001 From: Serhiy Mytrovtsiy Date: Thu, 31 Dec 2020 11:57:25 +0100 Subject: [PATCH] feat: added Apple Graphics to the GPU module (#260) --- Modules/GPU/main.swift | 2 +- Modules/GPU/reader.swift | 39 +++++++++++++++++++++------------------ 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/Modules/GPU/main.swift b/Modules/GPU/main.swift index 33d3372e..c1379b11 100644 --- a/Modules/GPU/main.swift +++ b/Modules/GPU/main.swift @@ -26,7 +26,7 @@ public struct GPU_Info { public let model: String public let IOClass: String public let type: GPU_type - public var state: Bool = false + public var state: Bool = true public var utilization: Double = 0 public var temperature: Int = 0 diff --git a/Modules/GPU/reader.swift b/Modules/GPU/reader.swift index 18f4d3ef..3fd2834e 100644 --- a/Modules/GPU/reader.swift +++ b/Modules/GPU/reader.swift @@ -81,15 +81,33 @@ internal class InfoReader: Reader { var predictModel = "" var type: GPU_types = .unknown - if ioClass == "nvAccelerator" || ioClass.contains("nvidia") { + let utilization = stats["Device Utilization %"] as? Int ?? stats["GPU Activity(%)"] as? Int ?? 0 + var temperature = stats["Temperature(C)"] as? Int ?? 0 + + if ioClass == "nvAccelerator" || ioClass.contains("nvidia") { // nvidia predictModel = "Nvidia Graphics" type = .discrete - } else if ioClass.contains("amd") { + } else if ioClass.contains("amd") { // amd predictModel = "AMD Graphics" type = .discrete - } else if ioClass.contains("intel") { + + if temperature == 0 { + if let tmp = self.smc?.pointee.getValue("TGDD") { + temperature = Int(tmp) + } + } + } else if ioClass.contains("intel") { // intel predictModel = "Intel Graphics" type = .integrated + + if temperature == 0 { + if let tmp = self.smc?.pointee.getValue("TCGC") { + temperature = Int(tmp) + } + } + } else if ioClass.contains("AGX") { // apple + predictModel = stats["model"] as? String ?? "Apple Graphics" + type = .integrated } else { predictModel = "Unknown" type = .unknown @@ -106,21 +124,6 @@ internal class InfoReader: Reader { return } - let utilization = stats["Device Utilization %"] as? Int ?? stats["GPU Activity(%)"] as? Int ?? 0 - var temperature = stats["Temperature(C)"] as? Int ?? 0 - - if temperature == 0 { - if IOClass == "IntelAccelerator" { - if let tmp = self.smc?.pointee.getValue("TCGC") { - temperature = Int(tmp) - } - } else if IOClass.starts(with: "AMDRadeon") { - if let tmp = self.smc?.pointee.getValue("TGDD") { - temperature = Int(tmp) - } - } - } - if let agcInfo = accelerator["AGCInfo"] as? [String:Int] { self.gpus.list[idx].state = agcInfo["poweredOffByAGC"] == 0 }