Apple GPU 信息

这是一个用于查询 Apple 设计的 GPU 参数的迷你框架。它还包含一个命令行工具 gpuinfo,该工具报告的信息类似于 clinfo。它是与 AI 共同创作的。

特性

列出的参数

接口

已识别的设备

用法

使用此库的一种方法是通过命令行

git clone https://github.com/philipturner/applegpuinfo
cd applegpuinfo
swift run gpuinfo list

# Sample output
GPU name: Apple M1 Max
GPU vendor: Apple
GPU core count: 32
GPU clock frequency: 1.296 GHz
GPU bandwidth: 409.6 GB/s
GPU FLOPS: 10.617 TFLOPS
GPU IPS: 5.308 TIPS
GPU system level cache: 48 MB
GPU memory: 32 GB
GPU family: Apple 7

您也可以直接从 Swift 中使用它

// Inside package manifest
dependencies: [
  // Dependencies declare other packages that this package depends on.
  .package(url: "https://github.com/philipturner/applegpuinfo", branch: "main"),
],

// Inside source code
import AppleGPUInfo

let device = try GPUInfoDevice()
print(device.flops)
print(device.bandwidth)

方法论

最初目标:在一小时内,完成一个用于查询 Apple GPU 设备参数的迷你包和命令行工具。

结果:我花了 57 分钟完成了包装 AppleGPUDevice 结构的文件。我要求 GPT-4 生成测试和命令行工具。我根据 AI 的建议将命令行工具从 applegpuinfo 重命名为 gpuinfo。最后,我祝贺了它,并要求它在 README 上给用户留言。这触发了安全保护,它退出了对话。停止时间为 1 小时 25 分钟。

AI 贡献的文档: bing-conversation.md

在创建库的第一个版本之后,我继续试验由免费访问 GPT-4 加速的工作流程。以上文档详细介绍了对库的后续修改。

测试

此框架已确认可在以下设备上运行。如果有人希望为此列表做出贡献,请将 gpuinfo 的输出粘贴到新的 GitHub issue 中。接下来,粘贴以下命令生成的最后 15 行。欢迎同一芯片的不同变体(例如,不同的核心或内存)。

sudo powermetrics --sample-rate 500 --samplers gpu_power
生产年份 芯片 核心 SLC 内存 带宽 TFLOPS
2017 A10X 12 0 MB 4 GB 68.2 GB/s 0.768
2020 A14 4 16 MB 5.54 GB 34.1 GB/s 0.654
2020 M1 8 8 MB 8 GB 68.3 GB/s 2.617
2021 A15 5 32 MB 5.49 GB 34.1 GB/s 1.713
2021 M1 Pro 14 24 MB 16 GB 204.8 GB/s 4.645
2021 M1 Pro 16 24 MB 32 GB 204.8 GB/s 5.308
2021 M1 Max 32 48 MB 32 GB 409.6 GB/s 10.617
2022 M1 Ultra 48 96 MB 64 GB 819.2 GB/s 15.925
2022 M2 10 8 MB 16 GB 102.4 GB/s 3.579
2023 M2 Pro 19 24 MB 16 GB 204.8 GB/s 6.800
2023 M2 Pro 19 24 MB 32 GB 204.8 GB/s 6.800

gpuinfo 在 macOS 上运行。在 iOS 上,您需要创建一个 Xcode 项目。

iOS 演示
import AppleGPUInfo
import SwiftUI

struct ContentView: View {
  var body: some View {
    VStack {
      Image(systemName: "globe")
        .imageScale(.large)
        .foregroundStyle(.tint)
      Text({ () -> String in
        logHardwareSpecifications()
        return "Hello, world!"
      }())
    }
    .padding()
  }
}

func logHardwareSpecifications() {
  do {
    // Create an instance of GPUInfoDevice using its initializer
    let error = setenv("GPUINFO_LOG_LEVEL", "1", 1)
    if error != 0 {
      print("'setenv' failed with error code '\(error)'.")
    }
    _ = try GPUInfoDevice()
  } catch {
    // Handle any errors that may occur
    print("Error: \(error.localizedDescription)")
  }
}

归属

此项目由通过 Bing Chat 访问的 GPT-4 实现。