Hello,
I have a problem that Metal doesn’t have built-in function such as erf. And we have a crash in runtime if the model contains the error function. I checked, and it should be possible to use fast_erf implementation without problems with accuracy. But I have a problem: I don’t know the right variant how can I replace erf on fast_erf in the generated code. I see the following options:
- Implement specific relay codegen for Metal and use it for replacing
erfonfast_erfin relay. I don’t like this option, at least because it will be necessary to register a newpattern_tablefor Metal and call it from python code. I would prefer that replacingerfonfast_erfdoesn’t request any additional actions from user. - Add check somewhere in
relay.buildthat if we are building model for Metal then pass which will replaceerfonfast_erfshould be applied. I don’t like this approach because it looks like a workaround for this problem and not the right solution. - I can write a
fast_erfimplementation on Metal language and add this function in Metal codegen to each kernel witherffunction. But I don’t like this option because we can get the same code from TIR and I don’t want to implementfast_erffunction one more time for Metal codegen. - Call
topi::fast_erffrom Metal codegen. For exampe, here, I tried to do it fromintrin_rule_metal.cc. I like this option more than others, but I didn’t find how can I create a validPrimExprfrom TIR op.
Could you please help me? What is the better way to solve this problem? Maybe there is another option which will be better in this case?