aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Johnson <jeremy.johnson@arm.com>2023-12-04 11:11:06 +0000
committerJeremy Johnson <jeremy.johnson@arm.com>2023-12-04 11:11:06 +0000
commit534923df858de76c6e0b0a2689cc23917e873548 (patch)
tree86df0f484ceb58a7b210c9603d8e3188253f7ce8
parent718f347a2d886381de19420b5b5b99db8f2b7338 (diff)
downloadreference_model-534923df858de76c6e0b0a2689cc23917e873548.tar.gz
Change TANH, SIGMOID to ABS_ERROR compliance
Signed-off-by: Jeremy Johnson <jeremy.johnson@arm.com> Change-Id: Icf04afc7fdae8f506ba4710aaa085d6ea53bb5bf
-rw-r--r--reference_model/src/ops/activation_funcs.cc20
-rw-r--r--verif/generator/tosa_test_gen.py4
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<Rank, Dtype>::register_fcn()
this->fcn = [](InEigenType a) -> OutEigenType { return fpTrunc<Dtype>(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<Rank, Dtype>::register_fcn()
this->fcn = [](InEigenType a) -> OutEigenType { return fpTrunc<Dtype>(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,