onnx-mlir icon indicating copy to clipboard operation
onnx-mlir copied to clipboard

Support onnx.Softplus op on NNPA.

Open negiyas opened this issue 10 months ago • 1 comments

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)))

negiyas avatar Apr 08 '24 20:04 negiyas

@jenkins-droid test this please

negiyas avatar May 07 '24 01:05 negiyas

Jenkins Linux ppc64le Build #13898 [push] Support onnx.Softplus op... started at 22:45

jenkins-droid avatar May 23 '24 02:05 jenkins-droid

Jenkins Linux s390x Build #14873 [push] Support onnx.Softplus op... started at 22:35

jenkins-droid avatar May 23 '24 02:05 jenkins-droid

Jenkins Linux amd64 Build #14868 [push] Support onnx.Softplus op... started at 21:35

jenkins-droid avatar May 23 '24 02:05 jenkins-droid

Jenkins Linux amd64 Build #14868 [push] Support onnx.Softplus op... passed after 1 hr 6 min

jenkins-droid avatar May 23 '24 03:05 jenkins-droid

Jenkins Linux s390x Build #14873 [push] Support onnx.Softplus op... passed after 1 hr 24 min

jenkins-droid avatar May 23 '24 03:05 jenkins-droid

Jenkins Linux ppc64le Build #13898 [push] Support onnx.Softplus op... passed after 1 hr 55 min

jenkins-droid avatar May 23 '24 04:05 jenkins-droid