I have a metal compute kernel that crashes MTLCompiler when I try to load the .metallib on an iPhone SE running iOS 14.4. I get the following error:
MTLCompiler: Compilation failed with XPC_ERROR_CONNECTION_INTERRUPTED on 3 try
Unable to init metal: Compiler encountered an internal error
By selectively commenting out code I narrowed it down to the use of SIMD permute functions. These functions are supported by the iOS/Metal version running on the device, but not by the actual hardware (according to the metal features set table). I have 2 variants of this code, one that uses the SIMD permute functions and one that doesn't.
My thought was to check the GPU family in Swift, then set a function constant supportsSIMDPermute
and use this to ensure the correct variation runs on the device, like this:
constant bool supportsSIMDPermute [[ function_constant(1) ]];
// kernel code
if(supportsSIMDPermute) {
// variant of code that uses SIMD permute
} else {
// Variant that uses slightly slower code that does not use SIMD permute
}
The library compiles without complaints in Xcode, but then crashes the on-device compiler when loading the library. Is this expected behaviour?