fortran66のブログ

fortran について書きます。

【メモ帳】mac GPU お触り

m1 macGPU を Metal 経由で Swift でさわる 

「基礎から学ぶ Metal 」をながめて、コマンドラインツールで行けるところだけを swift でいじってみるつもりです。Swift 文法は1ミリも知りませんので、ほぼ一言も何を言っているのか分かりません。

基礎から学ぶ Metal〜MetalによるGPUプログラミング入門

基礎から学ぶ Metal〜MetalによるGPUプログラミング入門

  • 作者:林 晃
  • 発売日: 2021/01/20
  • メディア: 単行本(ソフトカバー)

プログラム

GPU の情報を表示。

import Metal

print("Metal: GPU information")
print("\(MTLCreateSystemDefaultDevice()!.currentAllocatedSize)")


let devices = MTLCopyAllDevices()

for device in devices {
    let recommendSize = Double(device.recommendedMaxWorkingSetSize) / pow(2, 30)
    let maxBuffSize   = Double(device.maxBufferLength) / pow(2, 30)
    
    print("\(device.name):" +
          "RecommendedMaxSize=\(recommendSize)GB, " +
          "MaxBufferSize=\(maxBuffSize)GB, " +
          "HasUnifiedMemory=\(device.hasUnifiedMemory)")
    print()
    
    print("apple1:", device.supportsFamily(.apple1))
    print("apple2:", device.supportsFamily(.apple2))
    print("apple3:", device.supportsFamily(.apple3))
    print("apple4:", device.supportsFamily(.apple4))
    print("apple5:", device.supportsFamily(.apple5))
    print("apple6:", device.supportsFamily(.apple6))
    print("apple7:", device.supportsFamily(.apple7))
    print("common1:", device.supportsFamily(.common1))
    print("common2:", device.supportsFamily(.common2))
    print("common3:", device.supportsFamily(.common3))
    print("mac1:", device.supportsFamily(.mac1))
    print("mac2:", device.supportsFamily(.mac2))
    print("macCatalyst1:", device.supportsFamily(.macCatalyst1))
    print("macCatalyst1:", device.supportsFamily(.macCatalyst2))
    print()
    
    print("macOS_GPUFamily1_v1", device.supportsFeatureSet(.macOS_GPUFamily1_v1))
    print("macOS_GPUFamily1_v2", device.supportsFeatureSet(.macOS_GPUFamily1_v2))
    print("macOS_GPUFamily1_v3", device.supportsFeatureSet(.macOS_GPUFamily1_v3))
    print("macOS_GPUFamily1_v4", device.supportsFeatureSet(.macOS_GPUFamily1_v4))
    print("macOS_GPUFamily2_v1", device.supportsFeatureSet(.macOS_GPUFamily2_v1))
    print("macOS_ReadWriteTextureTier2", device.supportsFeatureSet(.macOS_ReadWriteTextureTier2))
    print("osx_GPUFamily1_v1", device.supportsFeatureSet(.osx_GPUFamily1_v1))
    print("osx_GPUFamily1_v2", device.supportsFeatureSet(.osx_GPUFamily1_v2))
    print("osx_ReadWriteTextureTier2", device.supportsFeatureSet(.osx_ReadWriteTextureTier2))

}

実行結果

Metal: GPU information
2021-04-19 20:45:18.553826+0900 test[23354:919025] Metal GPU Frame Capture Enabled
2021-04-19 20:45:18.554106+0900 test[23354:919025] Metal API Validation Enabled
1163264
Apple M1:RecommendedMaxSize=5.333343505859375GB, MaxBufferSize=4.0GB, HasUnifiedMemory=true

apple1: true
apple2: true
apple3: true
apple4: true
apple5: true
apple6: true
apple7: true
common1: true
common2: true
common3: true
mac1: true
mac2: true
macCatalyst1: false
macCatalyst1: false

macOS_GPUFamily1_v1 true
macOS_GPUFamily1_v2 true
macOS_GPUFamily1_v3 true
macOS_GPUFamily1_v4 true
macOS_GPUFamily2_v1 true
macOS_ReadWriteTextureTier2 false
osx_GPUFamily1_v1 true
osx_GPUFamily1_v2 true
osx_ReadWriteTextureTier2 false
Program ended with exit code: 0