From 534923df858de76c6e0b0a2689cc23917e873548 Mon Sep 17 00:00:00 2001 From: Jeremy Johnson Date: Mon, 4 Dec 2023 11:11:06 +0000 Subject: Change TANH, SIGMOID to ABS_ERROR compliance Signed-off-by: Jeremy Johnson Change-Id: Icf04afc7fdae8f506ba4710aaa085d6ea53bb5bf --- reference_model/src/ops/activation_funcs.cc | 20 ++++++++++++++++++-- verif/generator/tosa_test_gen.py | 4 +--- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/reference_model/src/ops/activation_funcs.cc b/reference_model/src/ops/activation_funcs.cc index 8ca77f7..ce58d77 100644 --- a/reference_model/src/ops/activation_funcs.cc +++ b/reference_model/src/ops/activation_funcs.cc @@ -89,7 +89,15 @@ int OpSigmoid::register_fcn() this->fcn = [](InEigenType a) -> OutEigenType { return fpTrunc(1.f / (1.f + (expf(-1.f * a)))); }; break; case TOSA_REF_TYPE_FP64: - this->fcn = [](InEigenType a) -> OutEigenType { return (1.L / (1.L + (exp(-1.L * a)))); }; + if (g_func_config.abs_mode) + { + // ABS_ERROR bounds return 2*(1+abs(a)) + this->fcn = [](InEigenType a) -> OutEigenType { return 2.0 * (1.0 + (a > (InEigenType)0 ? a : (-a))); }; + } + else + { + this->fcn = [](InEigenType a) -> OutEigenType { return (1.L / (1.L + (exp(-1.L * a)))); }; + } break; default: ERROR_IF(true, "unsupported TOSA_REF_TYPE %s", EnumNameTOSAREFTYPE(Dtype)); @@ -113,7 +121,15 @@ int OpTanh::register_fcn() this->fcn = [](InEigenType a) -> OutEigenType { return fpTrunc(tanhf(a)); }; break; case TOSA_REF_TYPE_FP64: - this->fcn = [](InEigenType a) -> OutEigenType { return tanh(a); }; + if (g_func_config.abs_mode) + { + // ABS_ERROR bounds return 2*(1+abs(a)) + this->fcn = [](InEigenType a) -> OutEigenType { return 2.0 * (1.0 + (a > (InEigenType)0 ? a : (-a))); }; + } + else + { + this->fcn = [](InEigenType a) -> OutEigenType { return tanh(a); }; + } break; default: ERROR_IF(true, "unsupported TOSA_REF_TYPE %s", EnumNameTOSAREFTYPE(Dtype)); diff --git a/verif/generator/tosa_test_gen.py b/verif/generator/tosa_test_gen.py index 0a8d035..ba10dcf 100644 --- a/verif/generator/tosa_test_gen.py +++ b/verif/generator/tosa_test_gen.py @@ -341,7 +341,7 @@ class TosaTestGen: compliance_tens["ulp_info"] = {"ulp": op["compliance"]["ulp"]} elif op["op"] == Op.REDUCE_PRODUCT: mode = gtu.ComplianceMode.REDUCE_PRODUCT - elif op["op"] in (Op.EXP, Op.POW): + elif op["op"] in (Op.EXP, Op.POW, Op.TANH, Op.SIGMOID): mode = gtu.ComplianceMode.ABS_ERROR else: mode = gtu.ComplianceMode.EXACT @@ -3243,7 +3243,6 @@ class TosaTestGen: "data_gen": { "fp": (gtu.DataGenType.PSEUDO_RANDOM,), }, - "compliance": {"ulp": 5}, }, "tanh": { "op": Op.TANH, @@ -3264,7 +3263,6 @@ class TosaTestGen: "data_gen": { "fp": (gtu.DataGenType.PSEUDO_RANDOM,), }, - "compliance": {"ulp": 5}, }, "erf": { "op": Op.ERF, -- cgit v1.2.1