From 48ed6cf8eb0d6beab4cb97f08fc41e037bfd182e Mon Sep 17 00:00:00 2001 From: Eric Kunze Date: Wed, 10 Jan 2024 00:58:11 +0000 Subject: CLAMP limits should be expressed in in_out_t int8/int16 should be used for the clamping, not int32_t Signed-off-by: Eric Kunze Change-Id: I18209ca76cc83d95dc61f20f88344aafdbd72033 --- reference_model/src/ops/activation_funcs.cc | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/reference_model/src/ops/activation_funcs.cc b/reference_model/src/ops/activation_funcs.cc index c8fdc74..1f4c3b3 100644 --- a/reference_model/src/ops/activation_funcs.cc +++ b/reference_model/src/ops/activation_funcs.cc @@ -52,12 +52,19 @@ int OpClamp::register_fcn() this->fcn = [min, max](InEigenType a) -> OutEigenType { return (a <= min ? min : a >= max ? max : a); }; } break; - case TOSA_REF_TYPE_INT8: + case TOSA_REF_TYPE_INT8: { + int8_t min = (int8_t)attribute->min_int(); + int8_t max = (int8_t)attribute->max_int(); + + ERROR_IF(max < min, "OpClamp: max smaller than min"); + this->fcn = [min, max](int8_t a) -> int8_t { return a <= min ? min : a >= max ? max : a; }; + } case TOSA_REF_TYPE_INT16: { - InEigenType min = (InEigenType)attribute->min_int(); - InEigenType max = (InEigenType)attribute->max_int(); + int16_t min = (int16_t)attribute->min_int(); + int16_t max = (int16_t)attribute->max_int(); + ERROR_IF(max < min, "OpClamp: max smaller than min"); - this->fcn = [min, max](InEigenType a) -> OutEigenType { return a <= min ? min : a >= max ? max : a; }; + this->fcn = [min, max](int16_t a) -> int16_t { return a <= min ? min : a >= max ? max : a; }; } break; default: -- cgit v1.2.1