This is a mini-framework for querying parameters of an Apple-designed GPU. It also contains a command-line tool, gpuinfo
, which reports information similarly to clinfo. It was co-authored with an AI.
Listed parameters:
Interfaces:
Recognized devices:
One way to use this library is from the command-line:
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
You can also use it directly from 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)
Original Goal: In one hour, finish a mini-package and command-line tool for querying Apple GPU device parameters.
Results: I spent 57 minutes finishing the file that wraps the AppleGPUDevice
structure. I asked GPT-4 to generate the tests and command-line tool. I renamed the command-line tool from applegpuinfo
to gpuinfo
according to the AI's suggestion. Finally, I congratulated it and asked for it to leave a comment to users on the README. That triggered a safeguard and it quit the conversation. The stop time was 1 hour, 25 minutes.
Documentation of AI contributions: bing-conversation.md
After creating the first release of the library, I have continued experimenting with workflows accelerated by free access to GPT-4. The above document details these subsequent modifications to the library.
This framework is confirmed to work on the following devices. If anyone wishes to contribute to this list, please paste the output of gpuinfo
into a new GitHub issue. Next, paste the last 15 lines generated by the following command. Different variations of the same chip (e.g. different cores or memory) are welcome.
sudo powermetrics --sample-rate 500 --samplers gpu_power
Production Year | Chip | Cores | SLC | Memory | Bandwidth | TFLOPS |
---|---|---|---|---|---|---|
2017 | A10X | 12 | 0 MB | 4 GB | 68.2 GB/s | 0.768 |
2021 | A15 | 5 | 32 MB | 5.49 GB | 34.1 GB/s | 1.713 |
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
runs on macOS. On iOS, you need to create an Xcode project.
ContentView.swift
with the demonstration below.Cmd + R
and look for text in the Xcode console.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)")
}
}
This project was made possible by GPT-4, accessed through Bing Chat.
link |
Stars: 44 |
Last commit: 6 days ago |
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics