请问有没有人能提供一个示例来说明如何使用Metal识别可用的计算设备,例如CPU和GPU?非常感谢。
Metal
仅适用于GPU。不过,有一个名为MTLCopyAllDevices()
的函数,它返回系统上所有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
MTLCopyAllDevices
。此函数仅适用于OS X。在iOS上,只有一个设备,您可以通过调用MTLCreateSystemDefaultDevice
来获取它。 - warrenm