onnx-mlir
onnx-mlir copied to clipboard
Support onnx.Softplus op on NNPA.
Support onnx.Softplus (=ln(exp(X) + 1) on NNPA.
This PR enables to run onnx.Softplus on NNPA only when the inputs and outputs are in stickfied format to order to avoid extra unstick and stick overheads.
This PR uses a converted formula softplus(X) = relu(X) + log(exp(-|X|) + 1.0)
instead of the original formula softplus(X) =ln(exp(X) + 1.0)
to avoid overflows come from the intermediate results by exp(X). (c.f. The new formula does not use exp(X)
but uses exp(-|X|)
.)
We confirmed that it optimizes execution time of each onnx.Softplus op by about 5 times from the main branch by using -mcpu=z16 --mtriple=s390x-ibm-loz --parallel --O3 --maccel=NNPA
option. (c.f. We used the same compile option for this PR and main branch.)
Lit tests and numerical tests to confirm the generated code and its calculation results are included in this PR.
// The pattern
// zhigh.Stick (onnx.Softplus (zhigh.Unstick (%X)))
// can be replaced by
// %minusOne = zhigh.Stick(GetConstantOfType<"-1.0">, %X)
// %minusX = zhigh.Mul(%X, %minusOne)
// zhigh.Add (
// zhigh.Relu(%X),
// zhigh.log(zhigh.Sub(zhigh.Exp(zhigh.Min(%X,%minusX)), %minusOne)))
@jenkins-droid test this please
Jenkins Linux ppc64le Build #13898 [push] Support onnx.Softplus op... started at 22:45
Jenkins Linux s390x Build #14873 [push] Support onnx.Softplus op... started at 22:35
Jenkins Linux amd64 Build #14868 [push] Support onnx.Softplus op... started at 21:35
Jenkins Linux amd64 Build #14868 [push] Support onnx.Softplus op... passed after 1 hr 6 min
Jenkins Linux s390x Build #14873 [push] Support onnx.Softplus op... passed after 1 hr 24 min
Jenkins Linux ppc64le Build #13898 [push] Support onnx.Softplus op... passed after 1 hr 55 min