From 52c89f40440ef5bcb318b3945bdc1463ce703b8b Mon Sep 17 00:00:00 2001 From: Eric Kunze Date: Wed, 10 May 2023 16:41:13 -0700 Subject: Add ERF activation function Defined for floating-point types only. For integer versions, a TABLE should be used. Change-Id: Ieaec6e6eb3227c5dcd9741cddd57426002a8db4d Signed-off-by: Eric Kunze --- chapters/activation_funcs.adoc | 26 ++++++++ chapters/introduction.adoc | 2 +- figures/erf.svg | 145 +++++++++++++++++++++++++++++++++++++++++ tools/dictionary.dic | 2 + tosa.xml | 27 ++++++++ 5 files changed, 201 insertions(+), 1 deletion(-) create mode 100644 figures/erf.svg diff --git a/chapters/activation_funcs.adoc b/chapters/activation_funcs.adoc index 46fa19d..1acaf56 100644 --- a/chapters/activation_funcs.adoc +++ b/chapters/activation_funcs.adoc @@ -28,6 +28,32 @@ for_each(index in shape) { } ---- +==== ERF + +// erf(z) = \frac{2}{\sqrt{\pi}} \int_{0}^{z} e^{-t^2} dt +Error function: + +.Calculation for the error function +image::erf.svg["Error function", align="center"] + +For quantized integer data types, the TABLE operator should be used instead with +the following definition. + +The ERF table has 513 entries each of 16-bit precision and covering the input range -4.0 to +4.0 in steps of 1/64. + +[source,c++] +---- +int16_t erf_reference(int16_t x) { // input x range is -256 to + 256 inclusive + F64 v = (double)x / (double)64; + v = erf(v); + return round_to_nearest_int(32768.0 * v); +} + +generate_lookup_table(&erf_table, &erf_reference); +---- + +include::{generated}/operators/ERF.adoc[] + ==== SIGMOID Applies the sigmoid logistic function to each element of the input tensor. diff --git a/chapters/introduction.adoc b/chapters/introduction.adoc index b369070..955f310 100644 --- a/chapters/introduction.adoc +++ b/chapters/introduction.adoc @@ -260,7 +260,7 @@ Otherwise:the result must be within 1 ulp of the mathematical result. Otherwise if the input is a zero the output must be an infinity of the same sign. + Otherwise the result must be within 1 ulp of the mathematical result. -| <>, <>, <>, <>, <> +| <>, <>, <>, <>, <>, <> | If the input to LOG is less than zero then the result must be a NaN. + If the inputs to POW are both zero then the result must be a NaN. + If the first input to POW is less than zero and the second input is not an integer then the result must be a NaN. + diff --git a/figures/erf.svg b/figures/erf.svg new file mode 100644 index 0000000..bb63a46 --- /dev/null +++ b/figures/erf.svg @@ -0,0 +1,145 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tools/dictionary.dic b/tools/dictionary.dic index da2e28c..70e556a 100644 --- a/tools/dictionary.dic +++ b/tools/dictionary.dic @@ -22,6 +22,8 @@ CPUs denormalizing DEPTHWISE Elementwise +ERF +erf FFT fft fp diff --git a/tosa.xml b/tosa.xml index f4186e3..8de564e 100644 --- a/tosa.xml +++ b/tosa.xml @@ -663,6 +663,33 @@ + + ERF + + + Input tensor + + + + Output tensor of same type and shape as input + + + + + + + + + + + + + + + + + + SIGMOID -- cgit v1.2.1