swiftcoreml

Check if device has Neural Engine


Is there an API that allows to know if the current device has a Neural Engine, other than inferring at the device model and version? (Apple platforms).

The purpose is to disable by default some non-critical features that rely on CoreML models if the device doesn't have such hardware acceleration.


Solution

  • There's not an explicit API that I can find, but using Instruments you can see whether or not a model is run on the ANE or Metal (i.e. on the GPU). I suppose at runtime you could use Objective C and some method swizzling to see if those ANE classes (use symbolic breakpoints, they're all prefixed with ANE) are called, but you'd need to put something through it first to find out.

    MLModelConfiguration has a computeUnits property which allows you to tell a model specifically NOT to run on the ANE, but not the other way around, the system makes the call on whether to use the ANE or not.

    There is some additional information here that may be helpful: https://github.com/hollance/neural-engine