diff options
author | Tai Ly <tai.ly@arm.com> | 2023-05-12 21:42:19 +0000 |
---|---|---|
committer | Eric Kunze <eric.kunze@arm.com> | 2023-05-18 01:18:18 +0000 |
commit | 307392a4962cc659f7104867a56816a011694a44 (patch) | |
tree | 9957c65666b4be69e9920a4ae7e1925ad0f254d7 /reference_model/src/ops/reduction.cc | |
parent | 264f7faa59709ffa8117541f5d55c99c5dba967d (diff) | |
download | reference_model-307392a4962cc659f7104867a56816a011694a44.tar.gz |
Add abs calculations under precise_mode
This adds a second run of reference model under precise_mode
when test_desc.json contains a "compliance" dictionary which
contains a "mode" entry with value "dot product".
In this second run, abs_mode will be set to true, which causes:
1. evaluation will take absolute values of inputs for these operators:
conv2d, conv3d, depthwise_conv2d, fully_connected,
matmul, transpose_conv2d, fft2d, rfft2d
reduce_sum, avg_pool2d
2. output files will have prefix "bounds_" prepended to them
Signed-off-by: Tai Ly <tai.ly@arm.com>
Change-Id: I7070ecc7ead2d2ea3375c44663d653c6772b88e0
Diffstat (limited to 'reference_model/src/ops/reduction.cc')
-rw-r--r-- | reference_model/src/ops/reduction.cc | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/reference_model/src/ops/reduction.cc b/reference_model/src/ops/reduction.cc index fd48472..f07ffd7 100644 --- a/reference_model/src/ops/reduction.cc +++ b/reference_model/src/ops/reduction.cc @@ -192,7 +192,10 @@ int OpReduceSum<Rank, Dtype>::eval() { case TOSA_REF_TYPE_FP16: case TOSA_REF_TYPE_BF16: - this->out->getTensor() = this->in->getTensor().sum(this->dims).reshape(this->out->getTensor().dimensions()).unaryExpr([](float f){return fpTrunc<Dtype>(f);}); + this->out->getTensor() = this->in->getTensor() + .sum(this->dims) + .reshape(this->out->getTensor().dimensions()) + .unaryExpr([](float f) { return fpTrunc<Dtype>(f); }); break; case TOSA_REF_TYPE_FP32: case TOSA_REF_TYPE_INT32: @@ -225,7 +228,9 @@ struct SumRequiresReducer { template <int Rank, TOSA_REF_TYPE Dtype> int OpReduceSumInt<Rank, Dtype>::eval() { - this->out->getTensor() = this->in->getTensor().reduce(this->dims, SumRequiresReducer(this->parent_sgt)).reshape(this->out->getTensor().dimensions()); + this->out->getTensor() = this->in->getTensor() + .reduce(this->dims, SumRequiresReducer(this->parent_sgt)) + .reshape(this->out->getTensor().dimensions()); return GraphNode::eval(); } @@ -250,12 +255,17 @@ struct SumDoubleReducer template <int Rank, TOSA_REF_TYPE Dtype> int OpReduceSumDouble<Rank, Dtype>::eval() { + typename ReduceNode<Rank, Dtype>::TIn in_val = this->in->getTensor(); + if (g_func_config.abs_mode) + { + // in abs_mode: take abs values of in value + in_val = in_val.abs(); + } switch (Dtype) { case TOSA_REF_TYPE_FP64: - this->out->getTensor() = this->in->getTensor() - .reduce(this->dims, SumDoubleReducer()) - .reshape(this->out->getTensor().dimensions()); + this->out->getTensor() = + in_val.reduce(this->dims, SumDoubleReducer()).reshape(this->out->getTensor().dimensions()); break; default: ERROR_IF(true, "unsupported TOSA_REF_TYPE %s", EnumNameTOSAREFTYPE(Dtype)); |