如何在 iphone 或 mac 中识别可用的金属计算设备

How to identify the available computational devices with metal in iphone or mac

谁能举个例子来说明如何用金属识别可用的计算设备,例如cpu和gpu?非常感谢

Metal 仅适用于 GPU。也就是说,有一个名为 MTLCopyAllDevices() 的函数 returns 您系统的所有 GPU。这是一个快速示例,说明我如何 运行 在 OS X playground 中查看我的系统有哪些兼容设备。

编辑:

Objective-C 中,这看起来很相似。只需先导入 <Metal/Metal.h>

@implementation AppDelegate

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {

    NSArray *devices = MTLCopyAllDevices();
    for (id device in devices) {
        NSLog(@"%@", [device name]);
    }
}

@end