It takes a large time to encode a MPSCNNConvolution kernel when first time install the App

I use MPSCNNConvolution in my App. The first time I install the App and the first time i encode the kernel, it will take a lot time(about 300 ms).

How to solve this problem? Thx a lot.

Replies

When you create any render pipeline or compute kernel, Metal GPU drivers must compile the bytecode to the GPU specific machine code (even if you've built your shaders offline when you built your app). The MPSCNNConvolution kernel is pretty complex so it probably takes longer than most pipelines and kernel.


However, there is a shader cache on disk so that this compliation only need occur if Metal has never seen the kernel/shader before. This is why you see this when your app runs for the first time. The compliation occurs then, but in subsquent runs, the fully compiled kernel code is pulled from the shader cache.


Bad news is, there isn't really anything you can do about the 300ms because it's just the normal compilation operation. Good news is, that 300ms isn't done everytime your app launches since it's in the cache.

Thanks a lot. So I have to replace all the mps apis by my own shaders, ''T_T''