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
erf
onfast_erf
in relay. I don’t like this option, at least because it will be necessary to register a newpattern_table
for Metal and call it from python code. I would prefer that replacingerf
onfast_erf
doesn’t request any additional actions from user. - Add check somewhere in
relay.build
that if we are building model for Metal then pass which will replaceerf
onfast_erf
should 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_erf
implementation on Metal language and add this function in Metal codegen to each kernel witherf
function. But I don’t like this option because we can get the same code from TIR and I don’t want to implementfast_erf
function one more time for Metal codegen. - Call
topi::fast_erf
from 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 validPrimExpr
from 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?