aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJerry Ge <jerry.ge@arm.com>2023-07-19 23:08:16 +0000
committerJerry Ge <jerry.ge@arm.com>2023-07-25 22:49:17 +0000
commit9c9c8dafe8f9a32bd70aee268cd537b93865a3ba (patch)
treee94fc471261b9f72bef86033fbc76022f55d5de8
parentc1e13432b4a218781afd6b0171d4afff11730433 (diff)
downloadreference_model-9c9c8dafe8f9a32bd70aee268cd537b93865a3ba.tar.gz
Run clang-format and update copyright
- Also added run clang-format to pre-commit runs Signed-off-by: Jerry Ge <jerry.ge@arm.com> Change-Id: I4e59ac0afbaa30dce0773aa63d92a1a3b119e2f3
-rw-r--r--.pre-commit-config.yaml12
-rw-r--r--reference_model/include/debug_types.h2
-rw-r--r--reference_model/include/dtype.h2
-rw-r--r--reference_model/include/func_config.h34
-rw-r--r--reference_model/include/func_debug.h28
-rw-r--r--reference_model/include/graph_status.h4
-rw-r--r--reference_model/include/model_runner.h4
-rw-r--r--reference_model/include/verify.h79
-rw-r--r--reference_model/include/version.h4
-rw-r--r--reference_model/samples/model_runner_simple_sample.cpp22
-rw-r--r--reference_model/src/arith_util.h3
-rw-r--r--reference_model/src/command_line_utils.h22
-rw-r--r--reference_model/src/func_debug.cc11
-rw-r--r--reference_model/src/graph_node.h4
-rw-r--r--reference_model/src/main.cpp20
-rw-r--r--reference_model/src/model_runner.cc8
-rw-r--r--reference_model/src/model_runner_impl.cc11
-rw-r--r--reference_model/src/model_runner_impl.h4
-rw-r--r--reference_model/src/operators.cc2
-rw-r--r--reference_model/src/ops/activation_funcs.cc22
-rw-r--r--reference_model/src/ops/activation_funcs.h4
-rw-r--r--reference_model/src/ops/control_flow.cc12
-rw-r--r--reference_model/src/ops/data_layout.cc67
-rw-r--r--reference_model/src/ops/data_nodes.cc4
-rw-r--r--reference_model/src/ops/ewise_binary.cc50
-rw-r--r--reference_model/src/ops/ewise_binary.h4
-rw-r--r--reference_model/src/ops/ewise_ternary.cc30
-rw-r--r--reference_model/src/ops/ewise_unary.cc20
-rw-r--r--reference_model/src/ops/image.cc22
-rw-r--r--reference_model/src/ops/op_factory.h23
-rw-r--r--reference_model/src/ops/reduction.cc72
-rw-r--r--reference_model/src/ops/scatter_gather.cc8
-rw-r--r--reference_model/src/ops/tensor_ops.cc307
-rw-r--r--reference_model/src/ops/tensor_ops.h55
-rw-r--r--reference_model/src/ops/type_conversion.cc40
-rw-r--r--reference_model/src/subgraph_traverser.cc71
-rw-r--r--reference_model/src/subgraph_traverser.h2
-rw-r--r--reference_model/src/tensor.cc63
-rw-r--r--reference_model/src/tensor.h3
-rw-r--r--reference_model/src/tosa_model_types.h4
-rw-r--r--reference_model/src/verify.cc41
41 files changed, 612 insertions, 588 deletions
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index b253ddd..4a6c9c7 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -1,4 +1,4 @@
-# Copyright (c) 2021-2022 Arm Limited.
+# Copyright (c) 2021-2023 Arm Limited.
# SPDX-License-Identifier: Apache-2.0
# See https://pre-commit.com for more information
@@ -28,3 +28,13 @@ repos:
entry: pytest -m "not postcommit"
types: [python]
pass_filenames: false
+
+- repo: local
+ hooks:
+ - id: clang-format
+ name: clang-format
+ exclude: build|third_party
+ language: system
+ entry: clang-format
+ types: ["c++"]
+ args: ["-i"] \ No newline at end of file
diff --git a/reference_model/include/debug_types.h b/reference_model/include/debug_types.h
index 9ff0098..4b97710 100644
--- a/reference_model/include/debug_types.h
+++ b/reference_model/include/debug_types.h
@@ -19,7 +19,7 @@
* Defines fundamental debugger datatypes for the functional model
*/
-#include<stdint.h>
+#include <stdint.h>
#ifndef DEBUG_TYPES_H_
#define DEBUG_TYPES_H_
diff --git a/reference_model/include/dtype.h b/reference_model/include/dtype.h
index 59b7fcd..bde678a 100644
--- a/reference_model/include/dtype.h
+++ b/reference_model/include/dtype.h
@@ -82,7 +82,7 @@ inline const char* EnumNameTOSAREFTYPE(TOSA_REF_TYPE e)
// return corresponding TOSA_REF_TYPE for DType
inline TOSA_REF_TYPE ConvertDType(const DType dtype)
{
- assert(DType_MAX == DType_BF16); // must update whenever DType_MAX changes
+ assert(DType_MAX == DType_BF16); // must update whenever DType_MAX changes
if (g_func_config.precise_mode)
{
diff --git a/reference_model/include/func_config.h b/reference_model/include/func_config.h
index 900ebab..1e93b89 100644
--- a/reference_model/include/func_config.h
+++ b/reference_model/include/func_config.h
@@ -19,29 +19,31 @@
#include <iostream>
#include <stdio.h>
-struct tosa_level_t {
+struct tosa_level_t
+{
int32_t MAX_RANK = 0;
int32_t MAX_KERNEL = 0;
int32_t MAX_STRIDE = 0;
int32_t MAX_SCALE = 0;
- bool operator!=(const tosa_level_t &rhs) {
- return !(MAX_RANK == rhs.MAX_RANK && MAX_KERNEL == rhs.MAX_KERNEL &&
- MAX_STRIDE == rhs.MAX_STRIDE && MAX_SCALE == rhs.MAX_SCALE);
+ bool operator!=(const tosa_level_t& rhs)
+ {
+ return !(MAX_RANK == rhs.MAX_RANK && MAX_KERNEL == rhs.MAX_KERNEL && MAX_STRIDE == rhs.MAX_STRIDE &&
+ MAX_SCALE == rhs.MAX_SCALE);
}
};
struct func_config_t
{
- std::string operator_fbs = "tosa.fbs";
- std::string test_desc = "desc.json";
- std::string flatbuffer_dir = "";
- std::string output_dir = "";
- std::string tosa_file = "";
- std::string ifm_name = "";
- std::string ifm_file = "";
- std::string ofm_name = "";
- std::string ofm_file = "";
+ std::string operator_fbs = "tosa.fbs";
+ std::string test_desc = "desc.json";
+ std::string flatbuffer_dir = "";
+ std::string output_dir = "";
+ std::string tosa_file = "";
+ std::string ifm_name = "";
+ std::string ifm_file = "";
+ std::string ofm_name = "";
+ std::string ofm_file = "";
uint32_t eval = 1;
uint32_t validate_only = 0;
uint32_t output_tensors = 1;
@@ -49,12 +51,12 @@ struct func_config_t
uint32_t dump_intermediates = 0;
std::string fp_format = "0.5";
uint32_t precise_mode = 0;
- bool abs_mode = 0; // set in main as second run of precise_mode
- bool float_is_big_endian = false; // Set in arith_util.h by float_is_big_endian()
+ bool abs_mode = 0; // set in main as second run of precise_mode
+ bool float_is_big_endian = false; // Set in arith_util.h by float_is_big_endian()
tosa_level_t tosa_level;
static constexpr tosa_level_t EIGHTK = { 6, 8192, 8192, 64 };
- static constexpr tosa_level_t NONE = { 0, 0, 0, 0 };
+ static constexpr tosa_level_t NONE = { 0, 0, 0, 0 };
};
#endif
diff --git a/reference_model/include/func_debug.h b/reference_model/include/func_debug.h
index 3794a35..556faf2 100644
--- a/reference_model/include/func_debug.h
+++ b/reference_model/include/func_debug.h
@@ -60,12 +60,12 @@ void func_enable_signal_handlers();
struct func_debug_t
{
- uint32_t func_debug_verbosity = 0; // What verbosity level is set? (bitmask)
- uint64_t func_debug_mask = 0; // Which units have debugging enabled? (bitmask)
- uint64_t func_debug_inst_mask = 0; // Which instances have debugging enabled (bitmask)
- uint64_t inst_id = 0; // The instance id for multiple model instances
- FILE* func_debug_file = stderr; // Output file
- bool is_output_unbuffered = false; // should log files be opened with unbuffered I/O.
+ uint32_t func_debug_verbosity = 0; // What verbosity level is set? (bitmask)
+ uint64_t func_debug_mask = 0; // Which units have debugging enabled? (bitmask)
+ uint64_t func_debug_inst_mask = 0; // Which instances have debugging enabled (bitmask)
+ uint64_t inst_id = 0; // The instance id for multiple model instances
+ FILE* func_debug_file = stderr; // Output file
+ bool is_output_unbuffered = false; // should log files be opened with unbuffered I/O.
int init_debug(uint64_t inst_id);
int fini_debug();
@@ -115,13 +115,13 @@ struct func_debug_t
#endif
#ifndef LEVEL_CHECK
-#define LEVEL_CHECK(COND, fmt, ...) \
- if (g_func_config.tosa_level != func_config_t::NONE && (!(COND))) \
- { \
- fprintf(g_func_debug.func_debug_file, COL_FATAL("LEVEL_CHECK() fails AT %s:%d %s(): (%s)\n"), __FILE__, __LINE__, \
- __func__, #COND); \
- fprintf(g_func_debug.func_debug_file, COL_FATAL(fmt) "\n", ##__VA_ARGS__); \
- this->parent_sgt->setGraphStatus(GraphStatus::TOSA_UNPREDICTABLE); \
+#define LEVEL_CHECK(COND, fmt, ...) \
+ if (g_func_config.tosa_level != func_config_t::NONE && (!(COND))) \
+ { \
+ fprintf(g_func_debug.func_debug_file, COL_FATAL("LEVEL_CHECK() fails AT %s:%d %s(): (%s)\n"), __FILE__, \
+ __LINE__, __func__, #COND); \
+ fprintf(g_func_debug.func_debug_file, COL_FATAL(fmt) "\n", ##__VA_ARGS__); \
+ this->parent_sgt->setGraphStatus(GraphStatus::TOSA_UNPREDICTABLE); \
}
#endif
@@ -174,8 +174,6 @@ void func_debug_warning(
fprintf(stderr, COL_WARN(fmt) "\n", ##__VA_ARGS__);
#endif
-
-
// Is this debug verbosity and unit level enabled?
// Provide compiler hints that this is unlikely
// Two versions, depending on whether DEBUG_INSTANCE_EXPR is defined in a file or not
diff --git a/reference_model/include/graph_status.h b/reference_model/include/graph_status.h
index f3be004..91330df 100644
--- a/reference_model/include/graph_status.h
+++ b/reference_model/include/graph_status.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2022, ARM Limited.
+// Copyright (c) 2022-2023, ARM Limited.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -22,4 +22,4 @@ enum class GraphStatus : int
TOSA_ERROR = 2,
};
-#endif // GRAPH_STATUS_H
+#endif // GRAPH_STATUS_H
diff --git a/reference_model/include/model_runner.h b/reference_model/include/model_runner.h
index 86d0056..2c610b8 100644
--- a/reference_model/include/model_runner.h
+++ b/reference_model/include/model_runner.h
@@ -1,5 +1,5 @@
-// Copyright (c) 2022, ARM Limited.
+// Copyright (c) 2022-2023, ARM Limited.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -16,8 +16,8 @@
#ifndef MODEL_RUNNER_H_
#define MODEL_RUNNER_H_
-#include "model_common.h"
#include "graph_status.h"
+#include "model_common.h"
#include "tosa_serialization_handler.h"
diff --git a/reference_model/include/verify.h b/reference_model/include/verify.h
index 0ac35fe..d294388 100644
--- a/reference_model/include/verify.h
+++ b/reference_model/include/verify.h
@@ -21,50 +21,51 @@
#include <cstddef>
#ifdef __cplusplus
-extern "C" {
+extern "C"
+{
#endif /* __cplusplus */
-// Check result
-//
-// Error is valid only and only if is_valid is true
-struct CheckResult
-{
- bool is_valid;
- double error;
-};
+ // Check result
+ //
+ // Error is valid only and only if is_valid is true
+ struct CheckResult
+ {
+ bool is_valid;
+ double error;
+ };
-/// Validate and calculate tensor element error when using an fp32 accumulator
-///
-/// \param ref Tensor element calculated using fp64
-/// \param bnd Tensor element calculated using fp64 on abs(input, weights)
-/// \param imp Tensor element calculated through the implementation
-/// \param KS The kernel size
-///
-/// \return Output error
-CheckResult tosa_validate_element_accfp32(double ref, double bnd, float imp, size_t KS);
+ /// Validate and calculate tensor element error when using an fp32 accumulator
+ ///
+ /// \param ref Tensor element calculated using fp64
+ /// \param bnd Tensor element calculated using fp64 on abs(input, weights)
+ /// \param imp Tensor element calculated through the implementation
+ /// \param KS The kernel size
+ ///
+ /// \return Output error
+ CheckResult tosa_validate_element_accfp32(double ref, double bnd, float imp, size_t KS);
-/// Validate the accumulated output error
-///
-/// \param err_sum Sum of error of all the tensor elements within a tensor
-/// \param err_sum_sq Sum of error squares of all the tensor elements within a tensor
-/// \param T Number of output (dot-product) elements
-/// \param KS The kernel size
-/// \param S Test set used as a input/weight generator
-///
-/// \return True if the error is within margin else false
-bool tosa_validate_output_error(double err_sum, double err_sum_sq, size_t T, size_t KS, int S);
+ /// Validate the accumulated output error
+ ///
+ /// \param err_sum Sum of error of all the tensor elements within a tensor
+ /// \param err_sum_sq Sum of error squares of all the tensor elements within a tensor
+ /// \param T Number of output (dot-product) elements
+ /// \param KS The kernel size
+ /// \param S Test set used as a input/weight generator
+ ///
+ /// \return True if the error is within margin else false
+ bool tosa_validate_output_error(double err_sum, double err_sum_sq, size_t T, size_t KS, int S);
-/// Validate error of whole vector of output data
-///
-/// \param ref Output elements calculated using fp64
-/// \param bnd Output elements calculated using fp64 on abs(input, weights)
-/// \param imp Output elements calculated using the implementation
-/// \param T Number of elements in outputs (need to match)
-/// \param KS The kernel size
-/// \param S Test set used as a input/weight generator
-///
-/// \return True if the error is within margin else false
-bool tosa_validate_data_fp32(const double* ref, const double* bnd, const float* imp, size_t T, size_t KS, int S);
+ /// Validate error of whole vector of output data
+ ///
+ /// \param ref Output elements calculated using fp64
+ /// \param bnd Output elements calculated using fp64 on abs(input, weights)
+ /// \param imp Output elements calculated using the implementation
+ /// \param T Number of elements in outputs (need to match)
+ /// \param KS The kernel size
+ /// \param S Test set used as a input/weight generator
+ ///
+ /// \return True if the error is within margin else false
+ bool tosa_validate_data_fp32(const double* ref, const double* bnd, const float* imp, size_t T, size_t KS, int S);
#ifdef __cplusplus
}
diff --git a/reference_model/include/version.h b/reference_model/include/version.h
index c81eedd..481a934 100644
--- a/reference_model/include/version.h
+++ b/reference_model/include/version.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2022, ARM Limited.
+// Copyright (c) 2022-2023, ARM Limited.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -20,4 +20,4 @@
#define TOSA_REFERENCE_MODEL_VERSION_PATCH 0
#define TOSA_REFERENCE_MODEL_VERSION_DRAFT true
-#endif //VERSION_H
+#endif //VERSION_H
diff --git a/reference_model/samples/model_runner_simple_sample.cpp b/reference_model/samples/model_runner_simple_sample.cpp
index 2eebca6..f1c9e96 100644
--- a/reference_model/samples/model_runner_simple_sample.cpp
+++ b/reference_model/samples/model_runner_simple_sample.cpp
@@ -1,5 +1,5 @@
-// Copyright (c) 2022, ARM Limited.
+// Copyright (c) 2022-2023, ARM Limited.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -27,24 +27,24 @@ int main()
std::string expected_output_file(test_root + "tflite_result.npy");
std::vector<std::string> input_names = { "TosaInput_0", "TosaInput_1" };
- std::string output_name = "TosaOutput_0";
+ std::string output_name = "TosaOutput_0";
std::vector<int32_t> input0_shape = { 1, 4, 4, 1 };
std::vector<int32_t> input1_shape = { 1, 4, 4, 4 };
std::vector<int32_t> output_shape = { 1, 4, 4, 4 };
std::vector<std::vector<float>> inputs(input_names.size());
- std::vector<float> expected_outputs = { };
- std::vector<float> actual_outputs = { };
+ std::vector<float> expected_outputs = {};
+ std::vector<float> actual_outputs = {};
// Read in inputs and expected outputs for sample purposes.
- inputs[0] = readFromNpyFile<float>(input0_file.c_str(), input0_shape);
- inputs[1] = readFromNpyFile<float>(input1_file.c_str(), input1_shape);
+ inputs[0] = readFromNpyFile<float>(input0_file.c_str(), input0_shape);
+ inputs[1] = readFromNpyFile<float>(input1_file.c_str(), input1_shape);
expected_outputs = readFromNpyFile<float>(expected_output_file.c_str(), output_shape);
tosa::TosaSerializationHandler handler;
tosa::tosa_err_t error = handler.LoadFileTosaFlatbuffer(tosa_model_file.c_str());
- if(error != tosa::TOSA_OK)
+ if (error != tosa::TOSA_OK)
{
WARNING("An error occurred while loading the model from file.");
return 1;
@@ -54,7 +54,7 @@ int main()
// Initialize the ModelRunner with configurations.
IModelRunner runner;
status = runner.initialize(handler);
- if(status != GraphStatus::TOSA_VALID)
+ if (status != GraphStatus::TOSA_VALID)
{
WARNING("An error occurred while initializing.");
return 1;
@@ -66,7 +66,7 @@ int main()
// Run the ModelRunner using test inputs.
status = runner.run();
- if(status != GraphStatus::TOSA_VALID)
+ if (status != GraphStatus::TOSA_VALID)
{
WARNING("An error occurred when running the model.");
return 1;
@@ -79,14 +79,14 @@ int main()
bool if_accurate = true;
for (size_t i = 0; i < expected_outputs.size(); ++i)
{
- if(actual_outputs[i] != expected_outputs[i])
+ if (actual_outputs[i] != expected_outputs[i])
{
WARNING("Actual output (%f) doesn't match expected output (%f).");
if_accurate = false;
}
}
- if(!if_accurate)
+ if (!if_accurate)
{
WARNING("There were mismatches in actual vs expected output, see above output for more details.");
return 1;
diff --git a/reference_model/src/arith_util.h b/reference_model/src/arith_util.h
index 76f3bb8..cab43ba 100644
--- a/reference_model/src/arith_util.h
+++ b/reference_model/src/arith_util.h
@@ -218,7 +218,8 @@ inline void float_trunc_bytes(float* src)
memcpy(src, &src_as_bytes, sizeof(float));
}
-inline void truncateFloatToBFloat(float* src, int64_t size) {
+inline void truncateFloatToBFloat(float* src, int64_t size)
+{
/* Set the least significant two bytes to zero for each float
value in the input src buffer. */
ASSERT_MEM(src);
diff --git a/reference_model/src/command_line_utils.h b/reference_model/src/command_line_utils.h
index 8fdff01..dcb0564 100644
--- a/reference_model/src/command_line_utils.h
+++ b/reference_model/src/command_line_utils.h
@@ -19,8 +19,8 @@
#include "func_config.h"
#include "func_debug.h"
-#include <stdint.h>
#include <cxxopts.hpp>
+#include <stdint.h>
// Read the command line arguments
int func_model_parse_cmd_line(
@@ -69,30 +69,36 @@ int func_model_parse_cmd_line(
// clang-format on
auto result = options.parse(argc, argv);
- if (result.count("help")) {
+ if (result.count("help"))
+ {
std::cout << options.help() << std::endl;
return 1;
}
- if (result.count("debugmask")) {
+ if (result.count("debugmask"))
+ {
auto& v = result["debugmask"].as<std::vector<std::string>>();
for (const std::string& s : v)
func_debug.set_mask(s);
}
- if (result.count("loglevel")) {
+ if (result.count("loglevel"))
+ {
const std::string& levelstr = result["loglevel"].as<std::string>();
func_debug.set_verbosity(levelstr);
}
- if (result.count("logfile")) {
+ if (result.count("logfile"))
+ {
func_debug.set_file(result["logfile"].as<std::string>());
}
- if (result.count("input_tensor_file")) {
+ if (result.count("input_tensor_file"))
+ {
func_config.ifm_name = result["input_tensor_file"].as<std::string>();
}
- if (result.count("version")) {
+ if (result.count("version"))
+ {
std::cout << "Model version " << version << std::endl;
}
}
- catch(const std::exception& e)
+ catch (const std::exception& e)
{
std::cerr << e.what() << '\n';
return 1;
diff --git a/reference_model/src/func_debug.cc b/reference_model/src/func_debug.cc
index 745d076..7979c89 100644
--- a/reference_model/src/func_debug.cc
+++ b/reference_model/src/func_debug.cc
@@ -1,5 +1,5 @@
-// Copyright (c) 2020, ARM Limited.
+// Copyright (c) 2020-2023, ARM Limited.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -15,12 +15,12 @@
#include <ctype.h>
#include <signal.h>
+#include <sstream>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
-#include <sstream>
#ifndef _MSC_VER
#include <execinfo.h>
@@ -164,7 +164,7 @@ int func_debug_t::init_debug(uint64_t inst_id)
set_verbosity(DEBUG_VERB_NONE);
set_inst_mask(DEBUG_INST_ALL);
func_debug_file = stderr;
- this->inst_id = inst_id;
+ this->inst_id = inst_id;
return 0;
}
@@ -268,7 +268,7 @@ void func_debug_t::set_inst_mask(const uint64_t mask)
}
std::vector<std::pair<std::string, int>> debug_str_table = {
-#define DEBUG_MODE(NAME, BIT) {#NAME, DEBUG_##NAME},
+#define DEBUG_MODE(NAME, BIT) { #NAME, DEBUG_##NAME },
#include "debug_modes.def"
#undef DEBUG_MODE
};
@@ -327,7 +327,8 @@ void func_debug_warning(
std::string func_debug_t::get_debug_mask_help_string()
{
std::string rval = "Set debug mask. Valid values are: ";
- for (auto& mask : debug_str_table) {
+ for (auto& mask : debug_str_table)
+ {
rval += mask.first + " ";
}
rval += "ALL";
diff --git a/reference_model/src/graph_node.h b/reference_model/src/graph_node.h
index aafc07f..900f4b8 100644
--- a/reference_model/src/graph_node.h
+++ b/reference_model/src/graph_node.h
@@ -276,8 +276,8 @@ protected:
if (requiredRankMin >= 0 && requiredRankMax >= 0)
{
ASSERT_MSG(requiredRankMin <= requiredRankMax,
- "GraphNode::setRequiredRank: requiredRankMin %d must be <= requiredRankMax %d", requiredRankMin,
- requiredRankMax);
+ "GraphNode::setRequiredRank: requiredRankMin %d must be <= requiredRankMax %d", requiredRankMin,
+ requiredRankMax);
}
return 0;
diff --git a/reference_model/src/main.cpp b/reference_model/src/main.cpp
index 55e6d67..0c86cbd 100644
--- a/reference_model/src/main.cpp
+++ b/reference_model/src/main.cpp
@@ -16,17 +16,17 @@
#include "model_runner.h"
#include "version.h"
+#include "arith_util.h"
#include "command_line_utils.h"
#include "ops/op_factory.h"
#include "subgraph_traverser.h"
#include "tosa_serialization_handler.h"
-#include "arith_util.h"
+#include <Eigen/CXX11/Tensor>
#include <fstream>
#include <iostream>
-#include <stdio.h>
-#include <Eigen/CXX11/Tensor>
#include <nlohmann/json.hpp>
+#include <stdio.h>
using namespace TosaReference;
using namespace tosa;
@@ -42,10 +42,8 @@ bool isComplianceModeDotProduct(json& test_desc);
int main(int argc, char** argv)
{
- TosaVersion model_version(TOSA_REFERENCE_MODEL_VERSION_MAJOR,
- TOSA_REFERENCE_MODEL_VERSION_MINOR,
- TOSA_REFERENCE_MODEL_VERSION_PATCH,
- TOSA_REFERENCE_MODEL_VERSION_DRAFT);
+ TosaVersion model_version(TOSA_REFERENCE_MODEL_VERSION_MAJOR, TOSA_REFERENCE_MODEL_VERSION_MINOR,
+ TOSA_REFERENCE_MODEL_VERSION_PATCH, TOSA_REFERENCE_MODEL_VERSION_DRAFT);
// Initialize configuration and debug subsystems
g_func_debug.init_debug(0);
@@ -245,7 +243,8 @@ int loadGraph(TosaSerializationHandler& tsh, json& test_desc)
{
if (tsh.LoadFileSchema(g_func_config.operator_fbs.c_str()))
{
- FATAL_ERROR("\nJSON file detected. Unable to load TOSA flatbuffer schema from: %s\nCheck --operator_fbs is set correctly",
+ FATAL_ERROR("\nJSON file detected. Unable to load TOSA flatbuffer schema from: %s\nCheck --operator_fbs "
+ "is set correctly",
g_func_config.operator_fbs.c_str());
}
@@ -259,9 +258,8 @@ int loadGraph(TosaSerializationHandler& tsh, json& test_desc)
{
if (tsh.LoadFileTosaFlatbuffer(graph_fullname))
{
- FATAL_ERROR(
- "\nError loading TOSA flatbuffer file: %s\n%s%s",
- graph_fullname, error_msg1.c_str(), error_msg2.c_str());
+ FATAL_ERROR("\nError loading TOSA flatbuffer file: %s\n%s%s", graph_fullname, error_msg1.c_str(),
+ error_msg2.c_str());
}
}
diff --git a/reference_model/src/model_runner.cc b/reference_model/src/model_runner.cc
index 62d6ce6..0ef44f9 100644
--- a/reference_model/src/model_runner.cc
+++ b/reference_model/src/model_runner.cc
@@ -1,5 +1,5 @@
-// Copyright (c) 2022, ARM Limited.
+// Copyright (c) 2022-2023, ARM Limited.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -21,11 +21,11 @@ using namespace TosaReference;
func_config_t g_func_config;
func_debug_t g_func_debug;
-IModelRunner::IModelRunner() : model_runner_impl(new ModelRunnerImpl())
+IModelRunner::IModelRunner()
+ : model_runner_impl(new ModelRunnerImpl())
{}
-IModelRunner::IModelRunner(const func_config_t& func_config,
- const func_debug_t& func_debug)
+IModelRunner::IModelRunner(const func_config_t& func_config, const func_debug_t& func_debug)
: model_runner_impl(new ModelRunnerImpl(func_config, func_debug))
{}
diff --git a/reference_model/src/model_runner_impl.cc b/reference_model/src/model_runner_impl.cc
index f1b70e7..ce548e9 100644
--- a/reference_model/src/model_runner_impl.cc
+++ b/reference_model/src/model_runner_impl.cc
@@ -20,11 +20,10 @@ using namespace TosaReference;
ModelRunnerImpl::ModelRunnerImpl()
{}
-ModelRunnerImpl::ModelRunnerImpl(const func_config_t& func_config,
- const func_debug_t& func_debug)
+ModelRunnerImpl::ModelRunnerImpl(const func_config_t& func_config, const func_debug_t& func_debug)
{
g_func_config = func_config;
- g_func_debug = func_debug;
+ g_func_debug = func_debug;
}
ModelRunnerImpl::~ModelRunnerImpl()
@@ -339,10 +338,8 @@ GraphStatus ModelRunnerImpl::initialize(TosaSerializationBasicBlock* bb,
void ModelRunnerImpl::validateTosaVersion(TosaSerializationHandler& serialization_handler)
{
- TosaVersion model_version(TOSA_REFERENCE_MODEL_VERSION_MAJOR,
- TOSA_REFERENCE_MODEL_VERSION_MINOR,
- TOSA_REFERENCE_MODEL_VERSION_PATCH,
- TOSA_REFERENCE_MODEL_VERSION_DRAFT);
+ TosaVersion model_version(TOSA_REFERENCE_MODEL_VERSION_MAJOR, TOSA_REFERENCE_MODEL_VERSION_MINOR,
+ TOSA_REFERENCE_MODEL_VERSION_PATCH, TOSA_REFERENCE_MODEL_VERSION_DRAFT);
TosaVersion::compat_t is_compat = model_version.is_compatible(serialization_handler.GetVersion());
switch (is_compat)
diff --git a/reference_model/src/model_runner_impl.h b/reference_model/src/model_runner_impl.h
index b43370c..aed8a1e 100644
--- a/reference_model/src/model_runner_impl.h
+++ b/reference_model/src/model_runner_impl.h
@@ -1,5 +1,5 @@
-// Copyright (c) 2022, ARM Limited.
+// Copyright (c) 2022-2023, ARM Limited.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -16,8 +16,8 @@
#ifndef MODEL_RUNNER_IMPL_H_
#define MODEL_RUNNER_IMPL_H_
-#include "model_runner.h"
#include "graph_status.h"
+#include "model_runner.h"
#include "version.h"
#include "array_proxy.h"
diff --git a/reference_model/src/operators.cc b/reference_model/src/operators.cc
index b6625d0..f3023dd 100644
--- a/reference_model/src/operators.cc
+++ b/reference_model/src/operators.cc
@@ -602,7 +602,7 @@ extern "C"
TosaNoneAttribute attr;
// Create tensors
- tosa::TosaSerializationTensor* input = translate_client_tensor(client_input, "input");
+ tosa::TosaSerializationTensor* input = translate_client_tensor(client_input, "input");
tosa::TosaSerializationTensor* output = translate_client_tensor(client_output, "output");
// Create operator
diff --git a/reference_model/src/ops/activation_funcs.cc b/reference_model/src/ops/activation_funcs.cc
index 12d0697..8ca77f7 100644
--- a/reference_model/src/ops/activation_funcs.cc
+++ b/reference_model/src/ops/activation_funcs.cc
@@ -14,9 +14,9 @@
// limitations under the License.
#include "activation_funcs.h"
+#include "arith_util.h"
#include "quant_util.h"
#include "template_types.h"
-#include "arith_util.h"
#include <cmath>
using namespace TosaReference;
@@ -34,17 +34,17 @@ int OpClamp<Rank, Dtype>::register_fcn()
{
case TOSA_REF_TYPE_FP16:
case TOSA_REF_TYPE_BF16:
- case TOSA_REF_TYPE_FP32:
- {
+ case TOSA_REF_TYPE_FP32: {
InEigenType min = (InEigenType)attribute->min_fp();
InEigenType max = (InEigenType)attribute->max_fp();
ERROR_IF(max < min, "OpClamp: max smaller than min");
- this->fcn = [min, max](InEigenType a) -> OutEigenType { return fpTrunc<Dtype>(a <= min ? min : a >= max ? max : a); };
+ this->fcn = [min, max](InEigenType a) -> OutEigenType {
+ return fpTrunc<Dtype>(a <= min ? min : a >= max ? max : a);
+ };
}
break;
- case TOSA_REF_TYPE_FP64:
- {
+ case TOSA_REF_TYPE_FP64: {
InEigenType min = (InEigenType)attribute->min_fp();
InEigenType max = (InEigenType)attribute->max_fp();
ERROR_IF(max < min, "OpClamp: max smaller than min");
@@ -53,8 +53,7 @@ int OpClamp<Rank, Dtype>::register_fcn()
}
break;
case TOSA_REF_TYPE_INT8:
- case TOSA_REF_TYPE_INT16:
- {
+ case TOSA_REF_TYPE_INT16: {
InEigenType min = (InEigenType)attribute->min_int();
InEigenType max = (InEigenType)attribute->max_int();
ERROR_IF(max < min, "OpClamp: max smaller than min");
@@ -71,7 +70,8 @@ int OpClamp<Rank, Dtype>::register_fcn()
template <int Rank, TOSA_REF_TYPE Dtype>
OpClamp<Rank, Dtype>::~OpClamp()
{
- if (attribute) delete attribute;
+ if (attribute)
+ delete attribute;
}
template <int Rank, TOSA_REF_TYPE Dtype>
@@ -86,9 +86,7 @@ int OpSigmoid<Rank, Dtype>::register_fcn()
case TOSA_REF_TYPE_FP16:
case TOSA_REF_TYPE_BF16:
case TOSA_REF_TYPE_FP32:
- this->fcn = [](InEigenType a) -> OutEigenType {
- return fpTrunc<Dtype>(1.f / (1.f + (expf(-1.f * a))));
- };
+ 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)))); };
diff --git a/reference_model/src/ops/activation_funcs.h b/reference_model/src/ops/activation_funcs.h
index a7e1275..1696668 100644
--- a/reference_model/src/ops/activation_funcs.h
+++ b/reference_model/src/ops/activation_funcs.h
@@ -86,8 +86,8 @@ public:
{
register_fcn();
}
- using InEigenType = typename GetEigenType<Dtype>::type;
- using OutEigenType = typename GetEigenType<Dtype>::type;
+ using InEigenType = typename GetEigenType<Dtype>::type;
+ using OutEigenType = typename GetEigenType<Dtype>::type;
virtual int register_fcn();
};
diff --git a/reference_model/src/ops/control_flow.cc b/reference_model/src/ops/control_flow.cc
index a0e1fc2..0afb7e2 100644
--- a/reference_model/src/ops/control_flow.cc
+++ b/reference_model/src/ops/control_flow.cc
@@ -95,20 +95,17 @@ int OpControlFlow::evalBlock(TosaSerializationBasicBlock* block,
// pass block status back
switch (block_sgt.getGraphStatus())
{
- case GraphStatus::TOSA_VALID:
- {
+ case GraphStatus::TOSA_VALID: {
DEBUG_MED(OP, "Successfully evaluating block %s", block_name.c_str());
break;
}
- case GraphStatus::TOSA_UNPREDICTABLE:
- {
+ case GraphStatus::TOSA_UNPREDICTABLE: {
DEBUG_MED(OP, "Finish evaluating block %s but result is UNPREDICTABLE", block_name.c_str());
DEBUG_MED(OP, "Setting parent graph status to UNPREDICTABLE");
parent_sgt->setGraphStatus(GraphStatus::TOSA_UNPREDICTABLE);
break;
}
- case GraphStatus::TOSA_ERROR:
- {
+ case GraphStatus::TOSA_ERROR: {
DEBUG_MED(OP, "Fail evaluating block %s. Result is ERROR", block_name.c_str());
if (parent_sgt->getGraphStatus() != GraphStatus::TOSA_UNPREDICTABLE)
{
@@ -311,7 +308,8 @@ OpWhileLoop::~OpWhileLoop()
int OpWhileLoop::checkTensorAttributes()
{
- if (!tsh) {
+ if (!tsh)
+ {
WARNING("OpWhileLoop: tosa serialization handler must not be null");
return 1;
}
diff --git a/reference_model/src/ops/data_layout.cc b/reference_model/src/ops/data_layout.cc
index 86cd752..bc97c89 100644
--- a/reference_model/src/ops/data_layout.cc
+++ b/reference_model/src/ops/data_layout.cc
@@ -21,9 +21,7 @@ using namespace Eigen;
using namespace tosa;
template <int Rank, TOSA_REF_TYPE Dtype>
-OpConcat<Rank, Dtype>::OpConcat(SubgraphTraverser* sgt_,
- TosaAttributeBase* attribute_,
- uint64_t id_)
+OpConcat<Rank, Dtype>::OpConcat(SubgraphTraverser* sgt_, TosaAttributeBase* attribute_, uint64_t id_)
: GraphNode(sgt_, Op_CONCAT, id_)
{
setRequiredOperands(-1, 1);
@@ -125,9 +123,7 @@ int OpConcat<Rank, Dtype>::eval()
}
template <int Rank, TOSA_REF_TYPE Dtype>
-OpPad<Rank, Dtype>::OpPad(SubgraphTraverser* sgt_,
- TosaAttributeBase* attribute_,
- uint64_t id_)
+OpPad<Rank, Dtype>::OpPad(SubgraphTraverser* sgt_, TosaAttributeBase* attribute_, uint64_t id_)
: GraphNode(sgt_, Op_PAD, id_)
{
setRequiredOperands(1, 1);
@@ -138,8 +134,7 @@ OpPad<Rank, Dtype>::OpPad(SubgraphTraverser* sgt_,
template <int Rank, TOSA_REF_TYPE Dtype>
OpPad<Rank, Dtype>::~OpPad()
-{
-}
+{}
template <int Rank, TOSA_REF_TYPE Dtype>
int OpPad<Rank, Dtype>::checkTensorAttributes()
@@ -215,9 +210,7 @@ int OpPad<Rank, Dtype>::eval()
}
template <int InRank, int OutRank, TOSA_REF_TYPE Dtype>
-OpReshape<InRank, OutRank, Dtype>::OpReshape(SubgraphTraverser* sgt_,
- TosaAttributeBase* attribute_,
- uint64_t id_)
+OpReshape<InRank, OutRank, Dtype>::OpReshape(SubgraphTraverser* sgt_, TosaAttributeBase* attribute_, uint64_t id_)
: GraphNode(sgt_, Op_RESHAPE, id_)
{
setRequiredOperands(1, 1);
@@ -251,40 +244,47 @@ int OpReshape<InRank, OutRank, Dtype>::checkTensorAttributes()
}
// -1 shape inferencing
- auto inferred_size = -1;
- auto inferred_dim = -1;
- auto total_size = getInputs()[0]->getElementCount();
+ auto inferred_size = -1;
+ auto inferred_dim = -1;
+ auto total_size = getInputs()[0]->getElementCount();
uint32_t accum_size = 1;
for (int32_t d = 0; d < OutRank; d++)
{
auto curr_new_shape = attribute->new_shape()[d];
- if (curr_new_shape != -1) {
+ if (curr_new_shape != -1)
+ {
accum_size *= curr_new_shape;
- } else {
+ }
+ else
+ {
ERROR_IF(inferred_dim != -1, "OpReshape: only 1 inferred dimension in output shape is supported");
inferred_dim = d;
}
}
- ERROR_IF((total_size % accum_size) != 0, "OpReshape: shape inference failed, missing dimension would be non-integer");
+ ERROR_IF((total_size % accum_size) != 0,
+ "OpReshape: shape inference failed, missing dimension would be non-integer");
inferred_size = total_size / accum_size;
- if (inferred_dim != -1) {
+ if (inferred_dim != -1)
+ {
getOutputs()[0]->setDimSize(inferred_dim, inferred_size);
// Need to also edit the serializedTensor's shape at inferred_dim
TosaSerializationTensor* serializedTensor;
- for (auto region : parent_sgt->getTsh()->GetRegions()) {
- for (auto block : region->GetBlocks()) {
- if (block->GetTensorByName(getOutputs()[0]->getName())) {
+ for (auto region : parent_sgt->getTsh()->GetRegions())
+ {
+ for (auto block : region->GetBlocks())
+ {
+ if (block->GetTensorByName(getOutputs()[0]->getName()))
+ {
serializedTensor = block->GetTensorByName(getOutputs()[0]->getName());
serializedTensor->SetDimSize(inferred_dim, inferred_size);
break;
}
}
}
-
}
ERROR_IF(inputs[0]->getElementCount() != outputs[0]->getElementCount(),
@@ -294,7 +294,7 @@ int OpReshape<InRank, OutRank, Dtype>::checkTensorAttributes()
{
auto curr_new_shape = attribute->new_shape()[d];
ERROR_IF(curr_new_shape != -1 && curr_new_shape != outputs[0]->getShape()[d],
- "OpReshape: new_shape doesn't match output shape");
+ "OpReshape: new_shape doesn't match output shape");
}
in = dynamic_cast<TosaReference::TensorTemplate<TIn>*>(inputs[0]);
@@ -308,7 +308,7 @@ int OpReshape<InRank, OutRank, Dtype>::eval()
{
for (int32_t d = 0; d < OutRank; d++)
{
- array_shape[d] = getOutputs()[0]->getShape()[OutRank - 1 - d];
+ array_shape[d] = getOutputs()[0]->getShape()[OutRank - 1 - d];
out_reverser[d] = OutRank - 1 - d;
}
@@ -347,9 +347,7 @@ int OpReshape<InRank, OutRank, Dtype>::eval()
}
template <int Rank, TOSA_REF_TYPE Dtype>
-OpReverse<Rank, Dtype>::OpReverse(SubgraphTraverser* sgt_,
- TosaAttributeBase* attribute_,
- uint64_t id_)
+OpReverse<Rank, Dtype>::OpReverse(SubgraphTraverser* sgt_, TosaAttributeBase* attribute_, uint64_t id_)
: GraphNode(sgt_, Op_REVERSE, id_)
{
setRequiredOperands(1, 1);
@@ -418,9 +416,7 @@ int OpReverse<Rank, Dtype>::eval()
}
template <int Rank, TOSA_REF_TYPE Dtype>
-OpSlice<Rank, Dtype>::OpSlice(SubgraphTraverser* sgt_,
- TosaAttributeBase* attribute_,
- uint64_t id_)
+OpSlice<Rank, Dtype>::OpSlice(SubgraphTraverser* sgt_, TosaAttributeBase* attribute_, uint64_t id_)
: GraphNode(sgt_, Op_SLICE, id_)
{
setRequiredOperands(1, 1);
@@ -491,9 +487,7 @@ int OpSlice<Rank, Dtype>::eval()
}
template <int Rank, TOSA_REF_TYPE Dtype>
-OpTileBase<Rank, Dtype>::OpTileBase(SubgraphTraverser* sgt_,
- TosaAttributeBase* attribute_,
- uint64_t id_)
+OpTileBase<Rank, Dtype>::OpTileBase(SubgraphTraverser* sgt_, TosaAttributeBase* attribute_, uint64_t id_)
: GraphNode(sgt_, Op_TILE, id_)
{
setRequiredOperands(1, 1);
@@ -693,9 +687,7 @@ int OpTile<6, Dtype>::eval()
}
template <int Rank, TOSA_REF_TYPE Dtype>
-OpTranspose<Rank, Dtype>::OpTranspose(SubgraphTraverser* sgt_,
- TosaAttributeBase* attribute_,
- uint64_t id_)
+OpTranspose<Rank, Dtype>::OpTranspose(SubgraphTraverser* sgt_, TosaAttributeBase* attribute_, uint64_t id_)
: GraphNode(sgt_, Op_TRANSPOSE, id_)
{
setRequiredOperands(1, 1);
@@ -707,7 +699,8 @@ OpTranspose<Rank, Dtype>::OpTranspose(SubgraphTraverser* sgt_,
template <int Rank, TOSA_REF_TYPE Dtype>
OpTranspose<Rank, Dtype>::~OpTranspose()
{
- if (attribute) delete attribute;
+ if (attribute)
+ delete attribute;
}
template <int Rank, TOSA_REF_TYPE Dtype>
diff --git a/reference_model/src/ops/data_nodes.cc b/reference_model/src/ops/data_nodes.cc
index b7f987a..07e7e97 100644
--- a/reference_model/src/ops/data_nodes.cc
+++ b/reference_model/src/ops/data_nodes.cc
@@ -43,9 +43,7 @@ int OpConst::eval()
}
template <int Rank, TOSA_REF_TYPE Dtype>
-OpIdentity<Rank, Dtype>::OpIdentity(SubgraphTraverser* sgt_,
- TosaAttributeBase* attribute_,
- uint64_t id_)
+OpIdentity<Rank, Dtype>::OpIdentity(SubgraphTraverser* sgt_, TosaAttributeBase* attribute_, uint64_t id_)
: GraphNode(sgt_, Op_IDENTITY, id_)
{
setRequiredOperands(1, 1);
diff --git a/reference_model/src/ops/ewise_binary.cc b/reference_model/src/ops/ewise_binary.cc
index 8578527..3fa4194 100644
--- a/reference_model/src/ops/ewise_binary.cc
+++ b/reference_model/src/ops/ewise_binary.cc
@@ -23,9 +23,7 @@ using namespace Eigen;
using namespace tosa;
template <int Rank, TOSA_REF_TYPE InDtype, TOSA_REF_TYPE OutDtype>
-BinaryNodeBase<Rank, InDtype, OutDtype>::BinaryNodeBase(SubgraphTraverser* sgt_,
- const Op& op_,
- uint64_t id_)
+BinaryNodeBase<Rank, InDtype, OutDtype>::BinaryNodeBase(SubgraphTraverser* sgt_, const Op& op_, uint64_t id_)
: GraphNode(sgt_, op_, id_)
{
setRequiredOperands(2, 1);
@@ -100,11 +98,16 @@ int BinaryNodeBase<Rank, InDtype, OutDtype>::broadcast(std::vector<int>& calcula
// calculates the broadcasted output shape
calculated_shape = a_shape;
- for (size_t i = 0; i < calculated_shape.size(); i++) {
- if (calculated_shape[i] == 1) {
+ for (size_t i = 0; i < calculated_shape.size(); i++)
+ {
+ if (calculated_shape[i] == 1)
+ {
calculated_shape[i] = b_shape[i];
- } else {
- ERROR_IF(b_shape[i] != 1 && b_shape[i] != calculated_shape[i], "Broadcast_shape failure, input shapes are not compatible");
+ }
+ else
+ {
+ ERROR_IF(b_shape[i] != 1 && b_shape[i] != calculated_shape[i],
+ "Broadcast_shape failure, input shapes are not compatible");
}
}
@@ -118,7 +121,8 @@ int BinaryNode<Rank, InDtype, OutDtype>::eval()
this->broadcast(calculated_shape);
auto result_shape = this->result->getShape();
- ERROR_IF(calculated_shape != result_shape, "Broadcast_shape failure, calculated_shape and result_shape don't match");
+ ERROR_IF(calculated_shape != result_shape,
+ "Broadcast_shape failure, calculated_shape and result_shape don't match");
Eigen::array<int, Rank> reshaper;
reshaper.fill(1);
@@ -210,7 +214,8 @@ int OpArithmeticRightShift<Rank, Dtype>::register_fcn()
template <int Rank, TOSA_REF_TYPE Dtype>
OpArithmeticRightShift<Rank, Dtype>::~OpArithmeticRightShift()
{
- if (attribute) delete attribute;
+ if (attribute)
+ delete attribute;
}
template <int Rank, TOSA_REF_TYPE Dtype>
@@ -309,21 +314,21 @@ int OpLogicalLeftShift<Rank, Dtype>::register_fcn()
case TOSA_REF_TYPE_INT8:
this->fcn = [this](InEigenType a, InEigenType b) -> OutEigenType {
REQUIRE(b >= 0 && b <= 31, "OpLogicalLeftShift: shift value %d is out of valid range [0, 31]",
- (int32_t)b);
+ (int32_t)b);
return static_cast<OutEigenType>(static_cast<int8_t>(a << b));
};
break;
case TOSA_REF_TYPE_INT16:
this->fcn = [this](InEigenType a, InEigenType b) -> OutEigenType {
REQUIRE(b >= 0 && b <= 31, "OpLogicalLeftShift: shift value %d is out of valid range [0, 31]",
- (int32_t)b);
+ (int32_t)b);
return static_cast<OutEigenType>(static_cast<int16_t>(a << b));
};
break;
case TOSA_REF_TYPE_INT32:
this->fcn = [this](InEigenType a, InEigenType b) -> OutEigenType {
REQUIRE(b >= 0 && b <= 31, "OpLogicalLeftShift: shift value %d is out of valid range [0, 31]",
- (int32_t)b);
+ (int32_t)b);
return static_cast<OutEigenType>(static_cast<int32_t>(a << b));
};
break;
@@ -342,21 +347,21 @@ int OpLogicalRightShift<Rank, Dtype>::register_fcn()
case TOSA_REF_TYPE_INT8:
this->fcn = [this](InEigenType a, InEigenType b) -> OutEigenType {
REQUIRE(b >= 0 && b <= 31, "OpLogicalRightShift: shift value %d is out of valid range [0, 31]",
- (int32_t)b);
+ (int32_t)b);
return static_cast<OutEigenType>(static_cast<int8_t>(a) >> b);
};
break;
case TOSA_REF_TYPE_INT16:
this->fcn = [this](InEigenType a, InEigenType b) -> OutEigenType {
REQUIRE(b >= 0 && b <= 31, "OpLogicalRightShift: shift value %d is out of valid range [0, 31]",
- (int32_t)b);
+ (int32_t)b);
return static_cast<OutEigenType>(static_cast<int16_t>(a) >> b);
};
break;
case TOSA_REF_TYPE_INT32:
this->fcn = [this](InEigenType a, InEigenType b) -> OutEigenType {
REQUIRE(b >= 0 && b <= 31, "OpLogicalRightShift: shift value %d is out of valid range [0, 31]",
- (int32_t)b);
+ (int32_t)b);
return static_cast<OutEigenType>(static_cast<int32_t>(a) >> b);
};
break;
@@ -494,7 +499,8 @@ int OpMul<Rank, InDtype, OutDtype>::register_fcn()
template <int Rank, TOSA_REF_TYPE InDtype, TOSA_REF_TYPE OutDtype>
OpMul<Rank, InDtype, OutDtype>::~OpMul()
{
- if (attribute) delete attribute;
+ if (attribute)
+ delete attribute;
}
template <int Rank, TOSA_REF_TYPE Dtype>
@@ -547,9 +553,7 @@ int OpSub<Rank, Dtype>::register_fcn()
}
template <int Rank, TOSA_REF_TYPE InDtype>
-OpTable<Rank, InDtype>::OpTable(SubgraphTraverser* sgt_,
- TosaAttributeBase* attribute_,
- uint64_t id_)
+OpTable<Rank, InDtype>::OpTable(SubgraphTraverser* sgt_, TosaAttributeBase* attribute_, uint64_t id_)
: GraphNode(sgt_, Op_TABLE, id_)
{
setRequiredOperands(1, 1);
@@ -561,7 +565,8 @@ OpTable<Rank, InDtype>::OpTable(SubgraphTraverser* sgt_,
template <int Rank, TOSA_REF_TYPE InDtype>
OpTable<Rank, InDtype>::~OpTable()
{
- if (attribute) delete attribute;
+ if (attribute)
+ delete attribute;
}
template <int Rank, TOSA_REF_TYPE InDtype>
@@ -624,10 +629,11 @@ int OpTable<Rank, InDtype>::eval()
int32_t base = table[index];
int32_t next = table[index + 1];
int32_t slope = next - base;
- REQUIRE(slope <= std::numeric_limits<int16_t>::max() && slope >= std::numeric_limits<int16_t>::min(), "OpTable: slope out of int16_t range");
+ REQUIRE(slope <= std::numeric_limits<int16_t>::max() && slope >= std::numeric_limits<int16_t>::min(),
+ "OpTable: slope out of int16_t range");
// 4. interpolate, generate 16.7 (23-bit) output
- int32_t value = (base << 7) + (slope) * frac;
+ int32_t value = (base << 7) + (slope)*frac;
return value;
});
diff --git a/reference_model/src/ops/ewise_binary.h b/reference_model/src/ops/ewise_binary.h
index 3a6f24c..1215c93 100644
--- a/reference_model/src/ops/ewise_binary.h
+++ b/reference_model/src/ops/ewise_binary.h
@@ -137,9 +137,7 @@ template <int Rank, TOSA_REF_TYPE Dtype>
class OpArithmeticRightShift : public BinaryNode<Rank, Dtype, Dtype>
{
public:
- OpArithmeticRightShift(SubgraphTraverser* sgt_,
- TosaAttributeBase* attribute_,
- uint64_t id_)
+ OpArithmeticRightShift(SubgraphTraverser* sgt_, TosaAttributeBase* attribute_, uint64_t id_)
: BinaryNode<Rank, Dtype, Dtype>(sgt_, Op_ARITHMETIC_RIGHT_SHIFT, id_)
{
INIT_ATTRIBUTE(ArithmeticRightShift);
diff --git a/reference_model/src/ops/ewise_ternary.cc b/reference_model/src/ops/ewise_ternary.cc
index fd2510f..5861cb2 100644
--- a/reference_model/src/ops/ewise_ternary.cc
+++ b/reference_model/src/ops/ewise_ternary.cc
@@ -20,9 +20,7 @@ using namespace Eigen;
using namespace tosa;
template <int Rank, TOSA_REF_TYPE Dtype>
-OpSelectBase<Rank, Dtype>::OpSelectBase(SubgraphTraverser* sgt_,
- TosaAttributeBase* attribute_,
- uint64_t id_)
+OpSelectBase<Rank, Dtype>::OpSelectBase(SubgraphTraverser* sgt_, TosaAttributeBase* attribute_, uint64_t id_)
: GraphNode(sgt_, Op_SELECT, id_)
{
setRequiredOperands(3, 1);
@@ -83,17 +81,26 @@ int OpSelect<Rank, Dtype>::broadcast(std::vector<int>& calculated_shape)
// calculates the broadcasted output shape
calculated_shape = cond_shape;
- for (size_t i = 0; i < calculated_shape.size(); i++) {
- if (calculated_shape[i] == 1) {
+ for (size_t i = 0; i < calculated_shape.size(); i++)
+ {
+ if (calculated_shape[i] == 1)
+ {
calculated_shape[i] = then_shape[i];
- } else {
- ERROR_IF(then_shape[i] != 1 && then_shape[i] != calculated_shape[i], "Broadcast_shape failure, input shapes are not compatible");
+ }
+ else
+ {
+ ERROR_IF(then_shape[i] != 1 && then_shape[i] != calculated_shape[i],
+ "Broadcast_shape failure, input shapes are not compatible");
}
- if (calculated_shape[i] == 1) {
+ if (calculated_shape[i] == 1)
+ {
calculated_shape[i] = else_shape[i];
- } else {
- ERROR_IF(else_shape[i] != 1 && else_shape[i] != calculated_shape[i], "Broadcast_shape failure, input shapes are not compatible");
+ }
+ else
+ {
+ ERROR_IF(else_shape[i] != 1 && else_shape[i] != calculated_shape[i],
+ "Broadcast_shape failure, input shapes are not compatible");
}
}
@@ -107,7 +114,8 @@ int OpSelect<Rank, Dtype>::eval()
this->broadcast(calculated_shape);
auto result_shape = this->out->getShape();
- ERROR_IF(calculated_shape != result_shape, "Broadcast_shape failure, calculated_shape and result_shape don't match");
+ ERROR_IF(calculated_shape != result_shape,
+ "Broadcast_shape failure, calculated_shape and result_shape don't match");
this->out->getTensor() = this->cond->getTensor()
.broadcast(this->bcast_cond)
diff --git a/reference_model/src/ops/ewise_unary.cc b/reference_model/src/ops/ewise_unary.cc
index e6e870e..05c1f4b 100644
--- a/reference_model/src/ops/ewise_unary.cc
+++ b/reference_model/src/ops/ewise_unary.cc
@@ -237,9 +237,7 @@ int OpLogicalNot<Rank, Dtype>::register_fcn()
}
template <int Rank, TOSA_REF_TYPE Dtype>
-OpNegate<Rank, Dtype>::OpNegate(SubgraphTraverser* sgt_,
- TosaAttributeBase* attribute_,
- uint64_t id_)
+OpNegate<Rank, Dtype>::OpNegate(SubgraphTraverser* sgt_, TosaAttributeBase* attribute_, uint64_t id_)
: UnaryNode<Rank, Dtype>(sgt_, Op_NEGATE, id_)
{
INIT_ATTRIBUTE(Negate);
@@ -279,10 +277,11 @@ int OpNegate<Rank, Dtype>::register_fcn()
case TOSA_REF_TYPE_INT16:
case TOSA_REF_TYPE_INT32:
this->fcn = [this](InEigenType a) -> OutEigenType {
- int64_t res_in_64 = 0L - a;
+ int64_t res_in_64 = 0L - a;
int64_t i32_max_in_64 = static_cast<int64_t>(std::numeric_limits<int32_t>::max());
int64_t i32_min_in_64 = static_cast<int64_t>(std::numeric_limits<int32_t>::min());
- REQUIRE(res_in_64 <= i32_max_in_64 && res_in_64 >= i32_min_in_64, "OpNegate: result not in acc type range (int32)");
+ REQUIRE(res_in_64 <= i32_max_in_64 && res_in_64 >= i32_min_in_64,
+ "OpNegate: result not in acc type range (int32)");
int64_t max_clip_in_64, min_clip_in_64;
if (Dtype == TOSA_REF_TYPE_INT16)
@@ -295,17 +294,20 @@ int OpNegate<Rank, Dtype>::register_fcn()
max_clip_in_64 = i32_max_in_64;
min_clip_in_64 = i32_min_in_64;
}
- return static_cast<InEigenType>(std::min<int64_t>(max_clip_in_64, std::max<int64_t>(min_clip_in_64, res_in_64)));
+ return static_cast<InEigenType>(
+ std::min<int64_t>(max_clip_in_64, std::max<int64_t>(min_clip_in_64, res_in_64)));
};
break;
case TOSA_REF_TYPE_INT8:
this->fcn = [this](InEigenType a) -> OutEigenType {
- int64_t res_in_64 = 0 - (a - attribute->input1_zp());
+ int64_t res_in_64 = 0 - (a - attribute->input1_zp());
int64_t i32_max_in_64 = static_cast<int64_t>(std::numeric_limits<int32_t>::max());
int64_t i32_min_in_64 = static_cast<int64_t>(std::numeric_limits<int32_t>::min());
- REQUIRE(res_in_64 <= i32_max_in_64 && res_in_64 >= i32_min_in_64, "OpNegate: result not in acc type range (int32)");
+ REQUIRE(res_in_64 <= i32_max_in_64 && res_in_64 >= i32_min_in_64,
+ "OpNegate: result not in acc type range (int32)");
res_in_64 += attribute->output_zp();
- InEigenType result = static_cast<InEigenType>(std::min(std::max(res_in_64, static_cast<int64_t>(QMin)), static_cast<int64_t>(QMax)));
+ InEigenType result = static_cast<InEigenType>(
+ std::min(std::max(res_in_64, static_cast<int64_t>(QMin)), static_cast<int64_t>(QMax)));
return result;
};
break;
diff --git a/reference_model/src/ops/image.cc b/reference_model/src/ops/image.cc
index 575a500..cf2b60a 100644
--- a/reference_model/src/ops/image.cc
+++ b/reference_model/src/ops/image.cc
@@ -24,9 +24,7 @@ using namespace Eigen;
using namespace tosa;
template <TOSA_REF_TYPE InDtype, TOSA_REF_TYPE OutDtype, typename resize_t>
-OpResize<InDtype, OutDtype, resize_t>::OpResize(SubgraphTraverser* sgt_,
- TosaAttributeBase* attribute_,
- uint64_t id_)
+OpResize<InDtype, OutDtype, resize_t>::OpResize(SubgraphTraverser* sgt_, TosaAttributeBase* attribute_, uint64_t id_)
: GraphNode(sgt_, Op_RESIZE, id_)
{
setRequiredOperands(1, 1);
@@ -134,17 +132,19 @@ int OpResize<InDtype, OutDtype, resize_t>::eval()
// Check Tosa Level
auto tosa_level = g_func_config.tosa_level;
- LEVEL_CHECK(scale_y_n / scale_y_d <= tosa_level.MAX_SCALE, "scale_y_n / scale_y_d should be smaller than or equal to MAX_SCALE");
- LEVEL_CHECK(scale_x_n / scale_x_d <= tosa_level.MAX_SCALE, "scale_x_n / scale_x_d should be smaller than or equal to MAX_SCALE");
+ LEVEL_CHECK(scale_y_n / scale_y_d <= tosa_level.MAX_SCALE,
+ "scale_y_n / scale_y_d should be smaller than or equal to MAX_SCALE");
+ LEVEL_CHECK(scale_x_n / scale_x_d <= tosa_level.MAX_SCALE,
+ "scale_x_n / scale_x_d should be smaller than or equal to MAX_SCALE");
int32_t res_height = 0;
- int32_t res_width = 0;
+ int32_t res_width = 0;
if (idiv_check((in_height - 1) * scale_y_n - offset_y + border_y, scale_y_d, res_height))
- return 1;
+ return 1;
if (idiv_check((in_width - 1) * scale_x_n - offset_x + border_x, scale_x_d, res_width))
- return 1;
+ return 1;
ERROR_IF(out_height != res_height + 1,
"OpResize: mismatch between output height dimension provided and expected shape");
@@ -247,8 +247,10 @@ int OpResize<InDtype, OutDtype, resize_t>::eval()
}
acc = in->getTensor()(b, iy, ix, c);
}
- if ((typeid(resize_t) == typeid(Eigen::bfloat16))) {
- ASSERT_MSG(checkValidBFloat(acc), "Resize accumulator float value is not a valid bfloat16 value.");
+ if ((typeid(resize_t) == typeid(Eigen::bfloat16)))
+ {
+ ASSERT_MSG(checkValidBFloat(acc),
+ "Resize accumulator float value is not a valid bfloat16 value.");
}
out->getTensor()(b, oy, ox, c) = acc;
}
diff --git a/reference_model/src/ops/op_factory.h b/reference_model/src/ops/op_factory.h
index f276e03..06ef36e 100644
--- a/reference_model/src/ops/op_factory.h
+++ b/reference_model/src/ops/op_factory.h
@@ -110,7 +110,7 @@
FATAL_ERROR("Can't initialize Tosa" #ATTRIBUTE_NAME "Attribute.\nPre-initialization " \
"of this attribute is required in order to determine the accumulate type."); \
} \
- ConvertDType(accumDType); \
+ ConvertDType(accumDType); \
})
#define DEF_FACTORY_TWO_TYPE_RESIZE_INT16(OP, DTYPE1, DTYPE2) \
@@ -192,8 +192,7 @@
{ \
switch (inputRank) \
{ \
- case 0: \
- { \
+ case 0: { \
switch (outputRank) \
{ \
DEF_FACTORY_TWO_RANK_ONE_TYPE(OP, 0, 0, DTYPE) \
@@ -205,8 +204,7 @@
DEF_FACTORY_TWO_RANK_ONE_TYPE(OP, 0, 6, DTYPE) \
} \
} \
- case 1: \
- { \
+ case 1: { \
switch (outputRank) \
{ \
DEF_FACTORY_TWO_RANK_ONE_TYPE(OP, 1, 0, DTYPE) \
@@ -218,8 +216,7 @@
DEF_FACTORY_TWO_RANK_ONE_TYPE(OP, 1, 6, DTYPE) \
} \
} \
- case 2: \
- { \
+ case 2: { \
switch (outputRank) \
{ \
DEF_FACTORY_TWO_RANK_ONE_TYPE(OP, 2, 0, DTYPE) \
@@ -231,8 +228,7 @@
DEF_FACTORY_TWO_RANK_ONE_TYPE(OP, 2, 6, DTYPE) \
} \
} \
- case 3: \
- { \
+ case 3: { \
switch (outputRank) \
{ \
DEF_FACTORY_TWO_RANK_ONE_TYPE(OP, 3, 0, DTYPE) \
@@ -244,8 +240,7 @@
DEF_FACTORY_TWO_RANK_ONE_TYPE(OP, 3, 6, DTYPE) \
} \
} \
- case 4: \
- { \
+ case 4: { \
switch (outputRank) \
{ \
DEF_FACTORY_TWO_RANK_ONE_TYPE(OP, 4, 0, DTYPE) \
@@ -257,8 +252,7 @@
DEF_FACTORY_TWO_RANK_ONE_TYPE(OP, 4, 6, DTYPE) \
} \
} \
- case 5: \
- { \
+ case 5: { \
switch (outputRank) \
{ \
DEF_FACTORY_TWO_RANK_ONE_TYPE(OP, 5, 0, DTYPE) \
@@ -270,8 +264,7 @@
DEF_FACTORY_TWO_RANK_ONE_TYPE(OP, 5, 6, DTYPE) \
} \
} \
- case 6: \
- { \
+ case 6: { \
switch (outputRank) \
{ \
DEF_FACTORY_TWO_RANK_ONE_TYPE(OP, 6, 0, DTYPE) \
diff --git a/reference_model/src/ops/reduction.cc b/reference_model/src/ops/reduction.cc
index 639da8d..2eb764a 100644
--- a/reference_model/src/ops/reduction.cc
+++ b/reference_model/src/ops/reduction.cc
@@ -83,27 +83,44 @@ int ReduceNode<Rank, Dtype>::checkTensorAttributes()
// These 2 reducers are to overcome a bug introduced in Eigen between 3.3.7 and 3.4.0
// The in-built .any and .all operations now fail on an assert in TensorMorphing.h:150
// which seems to be due to incorrect data being passed internally as m_impl
-struct AllReducer {
+struct AllReducer
+{
static const bool PacketAccess = false;
- void reduce(const bool val, bool* accum) {
+ void reduce(const bool val, bool* accum)
+ {
*accum = *accum && val;
}
- bool initialize() const { return true; }
- bool finalize(const bool accum) const { return accum; }
+ bool initialize() const
+ {
+ return true;
+ }
+ bool finalize(const bool accum) const
+ {
+ return accum;
+ }
};
-struct AnyReducer {
+struct AnyReducer
+{
static const bool PacketAccess = false;
- void reduce(const bool val, bool* accum) {
+ void reduce(const bool val, bool* accum)
+ {
*accum = *accum || val;
}
- bool initialize() const { return false; }
- bool finalize(const bool accum) const { return accum; }
+ bool initialize() const
+ {
+ return false;
+ }
+ bool finalize(const bool accum) const
+ {
+ return accum;
+ }
};
template <int Rank, TOSA_REF_TYPE Dtype>
int OpReduceAll<Rank, Dtype>::eval()
{
- this->out->getTensor() = this->in->getTensor().reduce(this->dims, AllReducer()).reshape(this->out->getTensor().dimensions());
+ this->out->getTensor() =
+ this->in->getTensor().reduce(this->dims, AllReducer()).reshape(this->out->getTensor().dimensions());
return GraphNode::eval();
}
@@ -111,7 +128,8 @@ int OpReduceAll<Rank, Dtype>::eval()
template <int Rank, TOSA_REF_TYPE Dtype>
int OpReduceAny<Rank, Dtype>::eval()
{
- this->out->getTensor() = this->in->getTensor().reduce(this->dims, AnyReducer()).reshape(this->out->getTensor().dimensions());
+ this->out->getTensor() =
+ this->in->getTensor().reduce(this->dims, AnyReducer()).reshape(this->out->getTensor().dimensions());
return GraphNode::eval();
}
@@ -135,14 +153,18 @@ int OpReduceMin<Rank, Dtype>::eval()
template <int Rank, TOSA_REF_TYPE Dtype>
int OpReduceProduct<Rank, Dtype>::eval()
{
- switch(Dtype)
+ switch (Dtype)
{
case TOSA_REF_TYPE_FP16:
case TOSA_REF_TYPE_BF16:
- this->out->getTensor() = this->in->getTensor().prod(this->dims).reshape(this->out->getTensor().dimensions()).unaryExpr([](float f){return fpTrunc<Dtype>(f);});
+ this->out->getTensor() = this->in->getTensor()
+ .prod(this->dims)
+ .reshape(this->out->getTensor().dimensions())
+ .unaryExpr([](float f) { return fpTrunc<Dtype>(f); });
break;
case TOSA_REF_TYPE_FP32:
- this->out->getTensor() = this->in->getTensor().prod(this->dims).reshape(this->out->getTensor().dimensions());
+ this->out->getTensor() =
+ this->in->getTensor().prod(this->dims).reshape(this->out->getTensor().dimensions());
break;
default:
ERROR_IF(true, "unsupported TOSA_REF_TYPE %s", EnumNameTOSAREFTYPE(Dtype));
@@ -188,7 +210,7 @@ int OpReduceProductDouble<Rank, Dtype>::eval()
template <int Rank, TOSA_REF_TYPE Dtype>
int OpReduceSum<Rank, Dtype>::eval()
{
- switch(Dtype)
+ switch (Dtype)
{
case TOSA_REF_TYPE_FP16:
case TOSA_REF_TYPE_BF16:
@@ -208,20 +230,30 @@ int OpReduceSum<Rank, Dtype>::eval()
return GraphNode::eval();
}
-struct SumRequiresReducer {
+struct SumRequiresReducer
+{
static const bool PacketAccess = false;
- SumRequiresReducer(SubgraphTraverser* parent_sgt) : parent_sgt(parent_sgt) {}
- void reduce(const int32_t val, int32_t* accum) {
+ SumRequiresReducer(SubgraphTraverser* parent_sgt)
+ : parent_sgt(parent_sgt)
+ {}
+ void reduce(const int32_t val, int32_t* accum)
+ {
int64_t res_in_64 = static_cast<int64_t>(*accum) + val;
int64_t i32_max_in_64 = static_cast<int64_t>(std::numeric_limits<int32_t>::max());
int64_t i32_min_in_64 = static_cast<int64_t>(std::numeric_limits<int32_t>::min());
REQUIRE(res_in_64 <= i32_max_in_64 && res_in_64 >= i32_min_in_64, "OpReduceSum: result not in i32 range");
*accum = static_cast<int32_t>(res_in_64);
}
- int32_t initialize() const { return 0; }
- int32_t finalize(const int32_t accum) const { return accum; }
+ int32_t initialize() const
+ {
+ return 0;
+ }
+ int32_t finalize(const int32_t accum) const
+ {
+ return accum;
+ }
- private:
+private:
SubgraphTraverser* parent_sgt;
};
diff --git a/reference_model/src/ops/scatter_gather.cc b/reference_model/src/ops/scatter_gather.cc
index 80b6c58..65d61b6 100644
--- a/reference_model/src/ops/scatter_gather.cc
+++ b/reference_model/src/ops/scatter_gather.cc
@@ -21,9 +21,7 @@ using namespace Eigen;
using namespace tosa;
template <TOSA_REF_TYPE Dtype>
-OpGather<Dtype>::OpGather(SubgraphTraverser* sgt_,
- TosaAttributeBase* attribute_,
- uint64_t id_)
+OpGather<Dtype>::OpGather(SubgraphTraverser* sgt_, TosaAttributeBase* attribute_, uint64_t id_)
: GraphNode(sgt_, Op_GATHER, id_)
{
setRequiredOperands(2, 1);
@@ -117,9 +115,7 @@ int OpGather<Dtype>::eval()
}
template <TOSA_REF_TYPE Dtype>
-OpScatter<Dtype>::OpScatter(SubgraphTraverser* sgt_,
- TosaAttributeBase* attribute_,
- uint64_t id_)
+OpScatter<Dtype>::OpScatter(SubgraphTraverser* sgt_, TosaAttributeBase* attribute_, uint64_t id_)
: GraphNode(sgt_, Op_SCATTER, id_)
{
setRequiredOperands(3, 1);
diff --git a/reference_model/src/ops/tensor_ops.cc b/reference_model/src/ops/tensor_ops.cc
index 5ba7a83..96fd41c 100644
--- a/reference_model/src/ops/tensor_ops.cc
+++ b/reference_model/src/ops/tensor_ops.cc
@@ -14,9 +14,9 @@
// limitations under the License.
#include "tensor_ops.h"
+#include "half.hpp"
#include "quant_util.h"
#include "template_types.h"
-#include "half.hpp"
using namespace TosaReference;
using namespace Eigen;
@@ -96,19 +96,16 @@ int check_pool2d_attribute(tosa::TosaPoolAttribute* attribute,
int32_t full_H = IH + pad_top + pad_bottom - kernel_y;
int32_t full_W = IW + pad_left + pad_right - kernel_x;
- if ((full_H % stride_y != 0) ||
- (full_W % stride_x != 0))
+ if ((full_H % stride_y != 0) || (full_W % stride_x != 0))
{
msg = "Parameters must yield exact integer output dimensions";
return 1;
}
- if ((OH != (full_H / stride_y) + 1) ||
- (OW != (full_W / stride_x) + 1))
+ if ((OH != (full_H / stride_y) + 1) || (OW != (full_W / stride_x) + 1))
{
msg = "Mismatch between output shape provided and expected output shape (" +
- std::to_string((full_H / stride_y) + 1) + "," +
- std::to_string((full_W / stride_x) + 1) + ")";
+ std::to_string((full_H / stride_y) + 1) + "," + std::to_string((full_W / stride_x) + 1) + ")";
return 1;
}
@@ -173,19 +170,19 @@ int check_conv_attribute(tosa::TosaConvAttribute* attribute,
ASSERT_MSG(conv_dimension == 2 || conv_dimension == 3, "Unsupported convolution dimension")
int32_t offset_d = conv_dimension == 3 ? 1 : 0;
- int32_t ID = conv_dimension == 3 ? input_shape[1] : 1;
- int32_t IH = input_shape[1 + offset_d];
- int32_t IW = input_shape[2 + offset_d];
- int32_t OD = conv_dimension == 3 ? output_shape[1] : 1;
- int32_t OH = output_shape[1 + offset_d];
- int32_t OW = output_shape[2 + offset_d];
-
- int32_t stride_d = conv_dimension == 3 ? attribute->stride()[0] : 1;
- int32_t stride_y = attribute->stride()[0 + offset_d];
- int32_t stride_x = attribute->stride()[1 + offset_d];
- int32_t kernel_d = conv_dimension == 3 ? weights[offset_kernel] : 1;
- int32_t kernel_h = weights[offset_kernel + offset_d];
- int32_t kernel_w = weights[offset_kernel + 1 + offset_d];
+ int32_t ID = conv_dimension == 3 ? input_shape[1] : 1;
+ int32_t IH = input_shape[1 + offset_d];
+ int32_t IW = input_shape[2 + offset_d];
+ int32_t OD = conv_dimension == 3 ? output_shape[1] : 1;
+ int32_t OH = output_shape[1 + offset_d];
+ int32_t OW = output_shape[2 + offset_d];
+
+ int32_t stride_d = conv_dimension == 3 ? attribute->stride()[0] : 1;
+ int32_t stride_y = attribute->stride()[0 + offset_d];
+ int32_t stride_x = attribute->stride()[1 + offset_d];
+ int32_t kernel_d = conv_dimension == 3 ? weights[offset_kernel] : 1;
+ int32_t kernel_h = weights[offset_kernel + offset_d];
+ int32_t kernel_w = weights[offset_kernel + 1 + offset_d];
int32_t dilation_d = conv_dimension == 3 ? attribute->dilation()[0] : 1;
int32_t dilation_y = attribute->dilation()[0 + offset_d];
int32_t dilation_x = attribute->dilation()[1 + offset_d];
@@ -202,27 +199,21 @@ int check_conv_attribute(tosa::TosaConvAttribute* attribute,
int32_t full_H = IH - 1 + pad_top + pad_bottom - (kernel_h - 1) * dilation_y;
int32_t full_W = IW - 1 + pad_left + pad_right - (kernel_w - 1) * dilation_x;
- if ((full_H % stride_y != 0) ||
- (full_W % stride_x != 0) ||
- (full_D % stride_d != 0))
+ if ((full_H % stride_y != 0) || (full_W % stride_x != 0) || (full_D % stride_d != 0))
{
msg = "Parameters must yield exact integer output dimensions";
return 1;
}
- if ((OH != (full_H / stride_y) + 1) ||
- (OW != (full_W / stride_x) + 1) ||
- (OD != (full_D / stride_d) + 1))
+ if ((OH != (full_H / stride_y) + 1) || (OW != (full_W / stride_x) + 1) || (OD != (full_D / stride_d) + 1))
{
std::string msg_d = "";
if (conv_dimension == 3)
{
msg_d += std::to_string((full_D / stride_d) + 1) + ",";
}
- msg = "Mismatch between output shape provided and expected output shape (" +
- msg_d +
- std::to_string((full_H / stride_y) + 1) + "," +
- std::to_string((full_W / stride_x) + 1) + ")";
+ msg = "Mismatch between output shape provided and expected output shape (" + msg_d +
+ std::to_string((full_H / stride_y) + 1) + "," + std::to_string((full_W / stride_x) + 1) + ")";
return 1;
}
@@ -244,12 +235,10 @@ int check_fft_shape(const std::vector<int32_t>& in_real,
const std::vector<int32_t>& in_imag,
const std::vector<int32_t>& out_real,
const std::vector<int32_t>& out_imag,
- std::string& msg) {
- const bool is_rfft = in_imag.empty();
- auto is_power_of_two = [](int32_t n) -> bool
- {
- return (n & (n-1)) == 0 && n > 0;
- };
+ std::string& msg)
+{
+ const bool is_rfft = in_imag.empty();
+ auto is_power_of_two = [](int32_t n) -> bool { return (n & (n - 1)) == 0 && n > 0; };
if (!is_power_of_two(in_real[1]) || !is_power_of_two(in_real[2]))
{
@@ -309,7 +298,9 @@ int check_fft_shape(const std::vector<int32_t>& in_real,
msg = "Output width is expected to match input width / 2 + 1";
return 1;
}
- } else {
+ }
+ else
+ {
if (in_real[2] != out_real[2])
{
msg = "Input and output width don't match";
@@ -321,9 +312,7 @@ int check_fft_shape(const std::vector<int32_t>& in_real,
}
template <int Rank, TOSA_REF_TYPE Dtype>
-OpArgMax<Rank, Dtype>::OpArgMax(SubgraphTraverser* sgt_,
- TosaAttributeBase* attribute_,
- uint64_t id_)
+OpArgMax<Rank, Dtype>::OpArgMax(SubgraphTraverser* sgt_, TosaAttributeBase* attribute_, uint64_t id_)
: GraphNode(sgt_, Op_ARGMAX, id_)
{
setRequiredOperands(1, 1);
@@ -417,9 +406,7 @@ int OpArgMax<Rank, Dtype>::eval()
}
template <TOSA_REF_TYPE Dtype, TOSA_REF_TYPE AccDtype>
-OpAvgPool2d<Dtype, AccDtype>::OpAvgPool2d(SubgraphTraverser* sgt_,
- TosaAttributeBase* attribute_,
- uint64_t id_)
+OpAvgPool2d<Dtype, AccDtype>::OpAvgPool2d(SubgraphTraverser* sgt_, TosaAttributeBase* attribute_, uint64_t id_)
: GraphNode(sgt_, Op_AVG_POOL2D, id_)
{
setRequiredOperands(1, 1);
@@ -485,7 +472,8 @@ ETensor1<int32_t> OpAvgPool2d<Dtype, AccDtype>::calculate_div_map_1d(
// adjust divisors on the left side for padding
// We start at the leftmost output element, and remove pad_left - (index * stride) elements
// until we have no more padding being used
- for(int index = 0; (index <= pad_left / stride) && (index < out_size); index++) {
+ for (int index = 0; (index <= pad_left / stride) && (index < out_size); index++)
+ {
int32_t adjust = pad_left - (index * stride);
result(index) -= adjust;
}
@@ -495,7 +483,8 @@ ETensor1<int32_t> OpAvgPool2d<Dtype, AccDtype>::calculate_div_map_1d(
// padding is defined in the initialization of index below. Then we keep moving
// to the right, increasing padding until we get to the last output element.
int index = std::max(0, ((pad_left + in_size - kernel_size) / stride) + 1);
- for (; index < out_size; index++) {
+ for (; index < out_size; index++)
+ {
int32_t adjust = ((index * stride) + kernel_size) - (pad_left + in_size);
result(index) -= adjust;
}
@@ -524,10 +513,10 @@ int OpAvgPool2d<Dtype, AccDtype>::eval()
int pad_bottom = this->attribute->pad()[1];
int pad_left = this->attribute->pad()[2];
int pad_right = this->attribute->pad()[3];
- int kernel_y = this->attribute->kernel()[0];
- int kernel_x = this->attribute->kernel()[1];
- int stride_y = this->attribute->stride()[0];
- int stride_x = this->attribute->stride()[1];
+ int kernel_y = this->attribute->kernel()[0];
+ int kernel_x = this->attribute->kernel()[1];
+ int stride_y = this->attribute->stride()[0];
+ int stride_x = this->attribute->stride()[1];
// Check Tosa Level
auto tosa_level = g_func_config.tosa_level;
@@ -613,12 +602,11 @@ int OpAvgPool2d<Dtype, AccDtype>::eval()
Eigen::array<Eigen::IndexPair<Eigen::Index>, 1> contract_dims = { Eigen::IndexPair<Eigen::Index>(1, 0) };
Eigen::array<Eigen::Index, 4> bcast{ out_batch, 1, 1, out_channels };
- ETensor2<int32_t> dm2_w = div_map_w.reshape(Eigen::array<Eigen::Index, 2>{ 1, out_width });
- ETensor2<int32_t> dm2_h = div_map_h.reshape(Eigen::array<Eigen::Index, 2>{ out_height, 1 });
- ETensor4<int32_t> div_map =
- dm2_h.contract(dm2_w, contract_dims)
- .reshape(Eigen::array<Eigen::Index, 4>{ 1, out_height, out_width, 1 })
- .broadcast(bcast);
+ ETensor2<int32_t> dm2_w = div_map_w.reshape(Eigen::array<Eigen::Index, 2>{ 1, out_width });
+ ETensor2<int32_t> dm2_h = div_map_h.reshape(Eigen::array<Eigen::Index, 2>{ out_height, 1 });
+ ETensor4<int32_t> div_map = dm2_h.contract(dm2_w, contract_dims)
+ .reshape(Eigen::array<Eigen::Index, 4>{ 1, out_height, out_width, 1 })
+ .broadcast(bcast);
if (Dtype != TOSA_REF_TYPE_FP32 && Dtype != TOSA_REF_TYPE_FP16 && Dtype != TOSA_REF_TYPE_BF16 &&
Dtype != TOSA_REF_TYPE_FP64)
{
@@ -649,9 +637,7 @@ int OpAvgPool2d<Dtype, AccDtype>::eval()
}
template <TOSA_REF_TYPE InDtype, TOSA_REF_TYPE WeightDtype, TOSA_REF_TYPE OutDtype>
-OpConv2d<InDtype, WeightDtype, OutDtype>::OpConv2d(SubgraphTraverser* sgt_,
- TosaAttributeBase* attribute_,
- uint64_t id_)
+OpConv2d<InDtype, WeightDtype, OutDtype>::OpConv2d(SubgraphTraverser* sgt_, TosaAttributeBase* attribute_, uint64_t id_)
: GraphNode(sgt_, Op_CONV2D, id_)
{
setRequiredOperands(3, 1);
@@ -685,7 +671,7 @@ int OpConv2d<InDtype, WeightDtype, OutDtype>::checkTensorAttributes()
}
ERROR_IF(outputs[0]->getDtype() != OutDtype,
- "OpConv2d: Output data type not supported for this configuration of operator");
+ "OpConv2d: Output data type not supported for this configuration of operator");
input = dynamic_cast<TosaReference::TensorTemplate<TIn>*>(inputs[0]);
weight = dynamic_cast<TosaReference::TensorTemplate<TWeight>*>(inputs[1]);
@@ -694,7 +680,7 @@ int OpConv2d<InDtype, WeightDtype, OutDtype>::checkTensorAttributes()
std::string msg;
if (check_conv_attribute(attribute, 2 /* conv_dimension */, input->getShape(), output->getShape(),
- weight->getShape(), 1 /* offset_kernel */, InDtype, WeightDtype, msg))
+ weight->getShape(), 1 /* offset_kernel */, InDtype, WeightDtype, msg))
{
msg = "OpConv2d: " + msg;
printNodeValidationError(msg.c_str());
@@ -736,15 +722,17 @@ int OpConv2d<InDtype, WeightDtype, OutDtype>::eval()
int pad_left = this->attribute->pad()[2];
int pad_right = this->attribute->pad()[3];
- int stride_y = this->attribute->stride()[0];
- int stride_x = this->attribute->stride()[1];
- int dilation_y = this->attribute->dilation()[0];
- int dilation_x = this->attribute->dilation()[1];
+ int stride_y = this->attribute->stride()[0];
+ int stride_x = this->attribute->stride()[1];
+ int dilation_y = this->attribute->dilation()[0];
+ int dilation_x = this->attribute->dilation()[1];
// Check Tosa Level
auto tosa_level = g_func_config.tosa_level;
- LEVEL_CHECK(dilation_y * f_height <= tosa_level.MAX_KERNEL, "dilation_y * KH should be smaller than or equal to MAX_KERNEL");
- LEVEL_CHECK(dilation_x * f_width <= tosa_level.MAX_KERNEL, "dilation_x * KW should be smaller than or equal to MAX_KERNEL");
+ LEVEL_CHECK(dilation_y * f_height <= tosa_level.MAX_KERNEL,
+ "dilation_y * KH should be smaller than or equal to MAX_KERNEL");
+ LEVEL_CHECK(dilation_x * f_width <= tosa_level.MAX_KERNEL,
+ "dilation_x * KW should be smaller than or equal to MAX_KERNEL");
LEVEL_CHECK(pad_top <= tosa_level.MAX_KERNEL, "pad_top should be smaller than or equal to MAX_KERNEL");
LEVEL_CHECK(pad_bottom <= tosa_level.MAX_KERNEL, "pad_bottom should be smaller than or equal to MAX_KERNEL");
LEVEL_CHECK(pad_left <= tosa_level.MAX_KERNEL, "pad_left should be smaller than or equal to MAX_KERNEL");
@@ -756,8 +744,8 @@ int OpConv2d<InDtype, WeightDtype, OutDtype>::eval()
"perform OpConv2d, input.shape=[%d,%d,%d,%d], weight.shape=[%d,%d,%d,%d], output.shape=[%d,%d,%d,%d], "
"stride=[%d,%d], dilation=[%d,%d], pad=[%d,%d,%d,%d]",
in_batch, in_height, in_width, in_channels, f_height, f_width, f_in_channels, f_out_channels, out_batch,
- out_height, out_width, out_channels, stride_y, stride_x, dilation_y, dilation_x, pad_top,
- pad_bottom, pad_left, pad_right);
+ out_height, out_width, out_channels, stride_y, stride_x, dilation_y, dilation_x, pad_top, pad_bottom,
+ pad_left, pad_right);
// GEMM-conv2d, left matrix is input, right matrix is weight
Eigen::array<Eigen::Index, 2> im2col_input_dims;
@@ -827,7 +815,7 @@ int OpConv2d<InDtype, WeightDtype, OutDtype>::eval()
// transpose and reshape weight from [OC, H, W, IC] to [H * W * IC, OC]
ETensor2<WeightEigenType> im2col_weight =
- weight_val.shuffle(Eigen::array<Eigen::Index, 4>({ 1, 2, 3, 0 })).reshape(im2col_weight_dims);
+ weight_val.shuffle(Eigen::array<Eigen::Index, 4>({ 1, 2, 3, 0 })).reshape(im2col_weight_dims);
// don't need to apply bias_multiplier ( * bias_scale and >> bias_shift) since tflite already scale it
// and reshaped from [C] to [1, C], and broadcast to [N * H * W, C]
@@ -835,8 +823,9 @@ int OpConv2d<InDtype, WeightDtype, OutDtype>::eval()
(bias_val.reshape(bias_reshaped_dims).broadcast(bias_bcast_dims)).template cast<OutEigenType>();
// output matrix is [N * H * W, C]
- ETensor2<OutEigenType> contracted_result =
- (im2col_input.template cast<AccEigenType>().contract(im2col_weight.template cast<AccEigenType>(), contract_dims)).template cast<OutEigenType>();
+ ETensor2<OutEigenType> contracted_result = (im2col_input.template cast<AccEigenType>().contract(
+ im2col_weight.template cast<AccEigenType>(), contract_dims))
+ .template cast<OutEigenType>();
// adding bias
ETensor2<OutEigenType> biased_output = contracted_result + bias_2d;
@@ -854,9 +843,7 @@ int OpConv2d<InDtype, WeightDtype, OutDtype>::eval()
}
template <TOSA_REF_TYPE InDtype, TOSA_REF_TYPE WeightDtype, TOSA_REF_TYPE OutDtype>
-OpConv3d<InDtype, WeightDtype, OutDtype>::OpConv3d(SubgraphTraverser* sgt_,
- TosaAttributeBase* attribute_,
- uint64_t id_)
+OpConv3d<InDtype, WeightDtype, OutDtype>::OpConv3d(SubgraphTraverser* sgt_, TosaAttributeBase* attribute_, uint64_t id_)
: GraphNode(sgt_, Op_CONV3D, id_)
{
setRequiredOperands(3, 1);
@@ -890,7 +877,7 @@ int OpConv3d<InDtype, WeightDtype, OutDtype>::checkTensorAttributes()
}
ERROR_IF(outputs[0]->getDtype() != OutDtype,
- "OpConv3d: Output data type not supported for this configuration of operator");
+ "OpConv3d: Output data type not supported for this configuration of operator");
input = dynamic_cast<TosaReference::TensorTemplate<TIn>*>(inputs[0]);
weight = dynamic_cast<TosaReference::TensorTemplate<TWeight>*>(inputs[1]);
@@ -899,7 +886,7 @@ int OpConv3d<InDtype, WeightDtype, OutDtype>::checkTensorAttributes()
std::string msg;
if (check_conv_attribute(attribute, 3 /* conv_dimension */, input->getShape(), output->getShape(),
- weight->getShape(), 1 /* offset_kernel */, InDtype, WeightDtype, msg))
+ weight->getShape(), 1 /* offset_kernel */, InDtype, WeightDtype, msg))
{
msg = "OpConv3d: " + msg;
printNodeValidationError(msg.c_str());
@@ -946,19 +933,22 @@ int OpConv3d<InDtype, WeightDtype, OutDtype>::eval()
int pad_left = this->attribute->pad()[4];
int pad_right = this->attribute->pad()[5];
- int stride_d = this->attribute->stride()[0];
- int stride_y = this->attribute->stride()[1];
- int stride_x = this->attribute->stride()[2];
+ int stride_d = this->attribute->stride()[0];
+ int stride_y = this->attribute->stride()[1];
+ int stride_x = this->attribute->stride()[2];
- int dilation_d = this->attribute->dilation()[0];
- int dilation_y = this->attribute->dilation()[1];
- int dilation_x = this->attribute->dilation()[2];
+ int dilation_d = this->attribute->dilation()[0];
+ int dilation_y = this->attribute->dilation()[1];
+ int dilation_x = this->attribute->dilation()[2];
// Check Tosa Level
auto tosa_level = g_func_config.tosa_level;
- LEVEL_CHECK(dilation_d * f_depth <= tosa_level.MAX_KERNEL, "dilation_d * KD should be smaller than or equal to MAX_KERNEL");
- LEVEL_CHECK(dilation_y * f_height <= tosa_level.MAX_KERNEL, "dilation_y * KH should be smaller than or equal to MAX_KERNEL");
- LEVEL_CHECK(dilation_x * f_width <= tosa_level.MAX_KERNEL, "dilation_x * KW should be smaller than or equal to MAX_KERNEL");
+ LEVEL_CHECK(dilation_d * f_depth <= tosa_level.MAX_KERNEL,
+ "dilation_d * KD should be smaller than or equal to MAX_KERNEL");
+ LEVEL_CHECK(dilation_y * f_height <= tosa_level.MAX_KERNEL,
+ "dilation_y * KH should be smaller than or equal to MAX_KERNEL");
+ LEVEL_CHECK(dilation_x * f_width <= tosa_level.MAX_KERNEL,
+ "dilation_x * KW should be smaller than or equal to MAX_KERNEL");
LEVEL_CHECK(pad_d0 <= tosa_level.MAX_KERNEL, "pad_d0 should be smaller than or equal to MAX_KERNEL");
LEVEL_CHECK(pad_d1 <= tosa_level.MAX_KERNEL, "pad_d1 should be smaller than or equal to MAX_KERNEL");
LEVEL_CHECK(pad_top <= tosa_level.MAX_KERNEL, "pad_top should be smaller than or equal to MAX_KERNEL");
@@ -1103,7 +1093,7 @@ int OpDepthwiseConv2d<InDtype, WeightDtype, OutDtype>::checkTensorAttributes()
}
ERROR_IF(outputs[0]->getDtype() != OutDtype,
- "OpDepthwiseConv2d: Output data type not supported for this configuration of operator");
+ "OpDepthwiseConv2d: Output data type not supported for this configuration of operator");
input = dynamic_cast<TosaReference::TensorTemplate<TIn>*>(inputs[0]);
weight = dynamic_cast<TosaReference::TensorTemplate<TWeight>*>(inputs[1]);
@@ -1112,7 +1102,7 @@ int OpDepthwiseConv2d<InDtype, WeightDtype, OutDtype>::checkTensorAttributes()
std::string msg;
if (check_conv_attribute(attribute, 2 /* conv_dimension */, input->getShape(), output->getShape(),
- weight->getShape(), 0 /* offset_kernel */, InDtype, WeightDtype, msg))
+ weight->getShape(), 0 /* offset_kernel */, InDtype, WeightDtype, msg))
{
msg = "OpDepthwiseConv2d: " + msg;
printNodeValidationError(msg.c_str());
@@ -1155,15 +1145,17 @@ int OpDepthwiseConv2d<InDtype, WeightDtype, OutDtype>::eval()
int pad_left = this->attribute->pad()[2];
int pad_right = this->attribute->pad()[3];
- int stride_y = this->attribute->stride()[0];
- int stride_x = this->attribute->stride()[1];
- int dilation_y = this->attribute->dilation()[0];
- int dilation_x = this->attribute->dilation()[1];
+ int stride_y = this->attribute->stride()[0];
+ int stride_x = this->attribute->stride()[1];
+ int dilation_y = this->attribute->dilation()[0];
+ int dilation_x = this->attribute->dilation()[1];
// Check Tosa Level
auto tosa_level = g_func_config.tosa_level;
- LEVEL_CHECK(dilation_y * f_height <= tosa_level.MAX_KERNEL, "dilation_y * KH should be smaller than or equal to MAX_KERNEL");
- LEVEL_CHECK(dilation_x * f_width <= tosa_level.MAX_KERNEL, "dilation_x * KW should be smaller than or equal to MAX_KERNEL");
+ LEVEL_CHECK(dilation_y * f_height <= tosa_level.MAX_KERNEL,
+ "dilation_y * KH should be smaller than or equal to MAX_KERNEL");
+ LEVEL_CHECK(dilation_x * f_width <= tosa_level.MAX_KERNEL,
+ "dilation_x * KW should be smaller than or equal to MAX_KERNEL");
LEVEL_CHECK(pad_top <= tosa_level.MAX_KERNEL, "pad_top should be smaller than or equal to MAX_KERNEL");
LEVEL_CHECK(pad_bottom <= tosa_level.MAX_KERNEL, "pad_bottom should be smaller than or equal to MAX_KERNEL");
LEVEL_CHECK(pad_left <= tosa_level.MAX_KERNEL, "pad_left should be smaller than or equal to MAX_KERNEL");
@@ -1175,8 +1167,8 @@ int OpDepthwiseConv2d<InDtype, WeightDtype, OutDtype>::eval()
"perform OpDepthwiseConv2d, input.shape=[%d,%d,%d,%d], weight.shape=[%d,%d,%d,%d], "
"output.shape=[%d,%d,%d,%d], stride=[%d,%d], dilation=[%d,%d], pad=[%d,%d,%d,%d]",
in_batch, in_height, in_width, in_channels, f_height, f_width, f_in_channels, f_multiplier, out_batch,
- out_height, out_width, out_channels, stride_y, stride_x, dilation_y, dilation_x, pad_top,
- pad_bottom, pad_left, pad_right);
+ out_height, out_width, out_channels, stride_y, stride_x, dilation_y, dilation_x, pad_top, pad_bottom,
+ pad_left, pad_right);
Eigen::array<std::pair<int32_t, int32_t>, 4> pad;
pad[0] = std::make_pair(0, 0);
@@ -1241,9 +1233,9 @@ int OpDepthwiseConv2d<InDtype, WeightDtype, OutDtype>::eval()
for (int fw = 0; fw < f_width; fw++)
{
// Perform multiplication in AccEigenType then cast to OutEigenType
- this->output->getTensor()(ob, oh, ow, ic * f_multiplier + cm) +=
- (OutEigenType)((AccEigenType)input_extract_patches(ob, fh, fw, ow * out_height + oh, ic) *
- (AccEigenType)weight_val(fh, fw, ic, cm));
+ this->output->getTensor()(ob, oh, ow, ic * f_multiplier + cm) += (OutEigenType)(
+ (AccEigenType)input_extract_patches(ob, fh, fw, ow * out_height + oh, ic) *
+ (AccEigenType)weight_val(fh, fw, ic, cm));
}
}
}
@@ -1308,7 +1300,7 @@ int OpFullyConnected<InDtype, WeightDtype, OutDtype>::checkTensorAttributes()
}
ERROR_IF(outputs[0]->getDtype() != OutDtype,
- "OpFullyConnected: Output data type not supported for this configuration of operator");
+ "OpFullyConnected: Output data type not supported for this configuration of operator");
output = dynamic_cast<TosaReference::TensorTemplate<TOut>*>(outputs[0]);
@@ -1368,9 +1360,7 @@ int OpFullyConnected<InDtype, WeightDtype, OutDtype>::eval()
}
template <TOSA_REF_TYPE Dtype, TOSA_REF_TYPE OutDtype>
-OpMatMul<Dtype, OutDtype>::OpMatMul(SubgraphTraverser* sgt_,
- TosaAttributeBase* attribute_,
- uint64_t id_)
+OpMatMul<Dtype, OutDtype>::OpMatMul(SubgraphTraverser* sgt_, TosaAttributeBase* attribute_, uint64_t id_)
: GraphNode(sgt_, Op_MATMUL, id_)
{
setRequiredOperands(2, 1);
@@ -1398,7 +1388,7 @@ int OpMatMul<Dtype, OutDtype>::checkTensorAttributes()
}
ERROR_IF(outputs[0]->getDtype() != OutDtype,
- "OpMatMul: Output data type not supported for this configuration of operator");
+ "OpMatMul: Output data type not supported for this configuration of operator");
a = dynamic_cast<TosaReference::TensorTemplate<TIn>*>(inputs[0]);
b = dynamic_cast<TosaReference::TensorTemplate<TIn>*>(inputs[1]);
@@ -1513,9 +1503,7 @@ int OpMatMul<Dtype, OutDtype>::eval()
}
template <TOSA_REF_TYPE Dtype>
-OpMaxPool2d<Dtype>::OpMaxPool2d(SubgraphTraverser* sgt_,
- TosaAttributeBase* attribute_,
- uint64_t id_)
+OpMaxPool2d<Dtype>::OpMaxPool2d(SubgraphTraverser* sgt_, TosaAttributeBase* attribute_, uint64_t id_)
: GraphNode(sgt_, Op_MAX_POOL2D, id_)
{
setRequiredOperands(1, 1);
@@ -1583,10 +1571,10 @@ int OpMaxPool2d<Dtype>::eval()
int pad_left = this->attribute->pad()[2];
int pad_right = this->attribute->pad()[3];
- int kernel_y = this->attribute->kernel()[0];
- int kernel_x = this->attribute->kernel()[1];
- int stride_y = this->attribute->stride()[0];
- int stride_x = this->attribute->stride()[1];
+ int kernel_y = this->attribute->kernel()[0];
+ int kernel_x = this->attribute->kernel()[1];
+ int stride_y = this->attribute->stride()[0];
+ int stride_x = this->attribute->stride()[1];
// Check Tosa Level
auto tosa_level = g_func_config.tosa_level;
@@ -1678,14 +1666,13 @@ int OpFFT2d<Dtype>::checkTensorAttributes()
if (validateRequiredOperands())
return 1;
- if (validateRequiredRank(inputs[0]) || validateRequiredRank(inputs[1]) ||
- validateRequiredRank(outputs[0]) || validateRequiredRank(outputs[1]))
+ if (validateRequiredRank(inputs[0]) || validateRequiredRank(inputs[1]) || validateRequiredRank(outputs[0]) ||
+ validateRequiredRank(outputs[1]))
{
return 1;
}
- if (inputs[0]->matchType(*outputs[0]) || inputs[1]->matchType(*outputs[1]) ||
- inputs[0]->matchType(*inputs[1]))
+ if (inputs[0]->matchType(*outputs[0]) || inputs[1]->matchType(*outputs[1]) || inputs[0]->matchType(*inputs[1]))
{
printNodeValidationError("OpFFT2d: input and output tensor type mismatch");
return 1;
@@ -1699,8 +1686,7 @@ int OpFFT2d<Dtype>::checkTensorAttributes()
ASSERT_MEM(in_real && in_imag && out_real && out_imag);
std::string msg;
- if (check_fft_shape(in_real->getShape(), in_imag->getShape(),
- out_real->getShape(), out_imag->getShape(), msg))
+ if (check_fft_shape(in_real->getShape(), in_imag->getShape(), out_real->getShape(), out_imag->getShape(), msg))
{
msg = "OpFFT2d: " + msg;
printNodeValidationError(msg.c_str());
@@ -1713,37 +1699,35 @@ int OpFFT2d<Dtype>::checkTensorAttributes()
template <TOSA_REF_TYPE Dtype>
int OpFFT2d<Dtype>::eval()
{
- int in_real_batch = this->in_real->getShape()[0];
+ int in_real_batch = this->in_real->getShape()[0];
int in_real_height = this->in_real->getShape()[1];
- int in_real_width = this->in_real->getShape()[2];
+ int in_real_width = this->in_real->getShape()[2];
- int in_imag_batch = this->in_imag->getShape()[0];
+ int in_imag_batch = this->in_imag->getShape()[0];
int in_imag_height = this->in_imag->getShape()[1];
- int in_imag_width = this->in_imag->getShape()[2];
+ int in_imag_width = this->in_imag->getShape()[2];
- int out_real_batch = this->out_real->getShape()[0];
+ int out_real_batch = this->out_real->getShape()[0];
int out_real_height = this->out_real->getShape()[1];
- int out_real_width = this->out_real->getShape()[2];
+ int out_real_width = this->out_real->getShape()[2];
- int out_imag_batch = this->out_imag->getShape()[0];
+ int out_imag_batch = this->out_imag->getShape()[0];
int out_imag_height = this->out_imag->getShape()[1];
- int out_imag_width = this->out_imag->getShape()[2];
+ int out_imag_width = this->out_imag->getShape()[2];
// Check Tosa Level
auto tosa_level = g_func_config.tosa_level;
LEVEL_CHECK(in_real_height <= tosa_level.MAX_KERNEL, "H should be smaller than or equal to MAX_KERNEL");
LEVEL_CHECK(in_real_width <= tosa_level.MAX_KERNEL, "W should be smaller than or equal to MAX_KERNEL");
- DEBUG_INFO(OP,
- "perform OpFFT2d, input.shapes=[[%d,%d,%d],[%d,%d,%d]], output.shapes=[[%d,%d,%d],[%d,%d,%d]]",
- in_real_batch, in_real_height, in_real_width,
- in_imag_batch, in_imag_height, in_imag_width,
- out_real_batch, out_real_height, out_real_width,
- out_imag_batch, out_imag_height, out_imag_width);
+ DEBUG_INFO(OP, "perform OpFFT2d, input.shapes=[[%d,%d,%d],[%d,%d,%d]], output.shapes=[[%d,%d,%d],[%d,%d,%d]]",
+ in_real_batch, in_real_height, in_real_width, in_imag_batch, in_imag_height, in_imag_width,
+ out_real_batch, out_real_height, out_real_width, out_imag_batch, out_imag_height, out_imag_width);
OutEigenType sum_real, sum_imag, a, sign_val = 1.0;
- if (attribute->inverse()) {
+ if (attribute->inverse())
+ {
sign_val = -1.0;
}
@@ -1772,7 +1756,8 @@ int OpFFT2d<Dtype>::eval()
OutEigenType val_real = in_real_val(n, iy, ix);
OutEigenType val_imag = in_imag_val(n, iy, ix);
// Use explicit cast to ensure intermmediate calculations are completed using OutEigenType
- a = sign_val * 2 * M_PI * ((iy * (OutEigenType)oy) / in_real_height + (ix * (OutEigenType)ox) / in_real_width);
+ a = sign_val * 2 * M_PI *
+ ((iy * (OutEigenType)oy) / in_real_height + (ix * (OutEigenType)ox) / in_real_width);
sum_real += val_real * cos(a) + val_imag * sin(a);
sum_imag += -val_real * sin(a) + val_imag * cos(a);
}
@@ -1787,9 +1772,7 @@ int OpFFT2d<Dtype>::eval()
}
template <TOSA_REF_TYPE Dtype>
-OpRFFT2d<Dtype>::OpRFFT2d(SubgraphTraverser* sgt_,
- TosaAttributeBase* attribute_,
- uint64_t id_)
+OpRFFT2d<Dtype>::OpRFFT2d(SubgraphTraverser* sgt_, TosaAttributeBase* attribute_, uint64_t id_)
: GraphNode(sgt_, Op_RFFT2D, id_)
{
setRequiredOperands(1, 2);
@@ -1797,8 +1780,8 @@ OpRFFT2d<Dtype>::OpRFFT2d(SubgraphTraverser* sgt_,
}
template <TOSA_REF_TYPE Dtype>
-OpRFFT2d<Dtype>::~OpRFFT2d() {}
-
+OpRFFT2d<Dtype>::~OpRFFT2d()
+{}
template <TOSA_REF_TYPE Dtype>
int OpRFFT2d<Dtype>::checkTensorAttributes()
@@ -1806,8 +1789,7 @@ int OpRFFT2d<Dtype>::checkTensorAttributes()
if (validateRequiredOperands())
return 1;
- if (validateRequiredRank(inputs[0]) || validateRequiredRank(outputs[0]) ||
- validateRequiredRank(outputs[1]))
+ if (validateRequiredRank(inputs[0]) || validateRequiredRank(outputs[0]) || validateRequiredRank(outputs[1]))
{
return 1;
}
@@ -1818,15 +1800,14 @@ int OpRFFT2d<Dtype>::checkTensorAttributes()
return 1;
}
- in = dynamic_cast<TosaReference::TensorTemplate<TIn>*>(inputs[0]);
+ in = dynamic_cast<TosaReference::TensorTemplate<TIn>*>(inputs[0]);
out_real = dynamic_cast<TosaReference::TensorTemplate<TOut>*>(outputs[0]);
out_imag = dynamic_cast<TosaReference::TensorTemplate<TOut>*>(outputs[1]);
ASSERT_MEM(in && out_real && out_imag);
std::string msg;
- if (check_fft_shape(in->getShape(), {},
- out_real->getShape(), out_imag->getShape(), msg))
+ if (check_fft_shape(in->getShape(), {}, out_real->getShape(), out_imag->getShape(), msg))
{
msg = "OpRFFT2d: " + msg;
printNodeValidationError(msg.c_str());
@@ -1839,17 +1820,17 @@ int OpRFFT2d<Dtype>::checkTensorAttributes()
template <TOSA_REF_TYPE Dtype>
int OpRFFT2d<Dtype>::eval()
{
- int32_t in_batch = in->getShape()[0];
+ int32_t in_batch = in->getShape()[0];
int32_t in_height = in->getShape()[1];
- int32_t in_width = in->getShape()[2];
+ int32_t in_width = in->getShape()[2];
- int32_t out_real_batch = out_real->getShape()[0];
+ int32_t out_real_batch = out_real->getShape()[0];
int32_t out_real_height = out_real->getShape()[1];
- int32_t out_real_width = out_real->getShape()[2];
+ int32_t out_real_width = out_real->getShape()[2];
- int32_t out_imag_batch = out_imag->getShape()[0];
+ int32_t out_imag_batch = out_imag->getShape()[0];
int32_t out_imag_height = out_imag->getShape()[1];
- int32_t out_imag_width = out_imag->getShape()[2];
+ int32_t out_imag_width = out_imag->getShape()[2];
// Check Tosa Level
auto tosa_level = g_func_config.tosa_level;
@@ -1859,9 +1840,8 @@ int OpRFFT2d<Dtype>::eval()
DEBUG_INFO(OP,
"perform OpRFFT2d, input.shape=[%d,%d,%d], output_real.shape=[%d,%d,%d], "
"output_imag.shape=[%d,%d,%d]",
- in_batch, in_height, in_width,
- out_real_batch, out_real_height, out_real_width,
- out_imag_batch, out_imag_height, out_imag_width);
+ in_batch, in_height, in_width, out_real_batch, out_real_height, out_real_width, out_imag_batch,
+ out_imag_height, out_imag_width);
OutEigenType sum_real, sum_imag, a;
@@ -1931,7 +1911,7 @@ int OpTransposeConv2d<InDtype, WeightDtype, OutDtype>::checkTensorAttributes()
}
ERROR_IF(outputs[0]->getDtype() != OutDtype,
- "OpTransposeConv2d: Output data type not supported for this configuration of operator");
+ "OpTransposeConv2d: Output data type not supported for this configuration of operator");
input = dynamic_cast<TosaReference::TensorTemplate<TIn>*>(inputs[0]);
weight = dynamic_cast<TosaReference::TensorTemplate<TWeight>*>(inputs[1]);
@@ -1956,8 +1936,6 @@ int OpTransposeConv2d<InDtype, WeightDtype, OutDtype>::checkTensorAttributes()
return 1;
}
-
-
for (int32_t i : attribute->stride())
{
if (i < 1)
@@ -1993,7 +1971,8 @@ int OpTransposeConv2d<InDtype, WeightDtype, OutDtype>::checkTensorAttributes()
for (size_t i = 0; i < attribute->out_pad().size(); i++)
{
- ERROR_IF(attribute->out_pad()[i] <= -(weight->getShape()[(i / 2) + 1]), "OpTransposeConv2d: At least one out_pad value is larger than kernel size");
+ ERROR_IF(attribute->out_pad()[i] <= -(weight->getShape()[(i / 2) + 1]),
+ "OpTransposeConv2d: At least one out_pad value is larger than kernel size");
}
int32_t H = (IH - 1) * stride_y + out_pad_top + out_pad_bottom + kernel_h;
@@ -2002,8 +1981,7 @@ int OpTransposeConv2d<InDtype, WeightDtype, OutDtype>::checkTensorAttributes()
if ((OH != H) || (OW != W))
{
std::string msg = "OpTransposeConv2d: Mismatch between output shape provided and expected output shape (" +
- std::to_string(H) + "," +
- std::to_string(W) + ")";
+ std::to_string(H) + "," + std::to_string(W) + ")";
printNodeValidationError(msg.c_str());
return 1;
}
@@ -2057,7 +2035,8 @@ int OpTransposeConv2d<InDtype, WeightDtype, OutDtype>::eval()
LEVEL_CHECK(f_height <= tosa_level.MAX_KERNEL, "KH should be smaller than or equal to MAX_KERNEL");
LEVEL_CHECK(f_width <= tosa_level.MAX_KERNEL, "KW should be smaller than or equal to MAX_KERNEL");
LEVEL_CHECK(out_pad_top <= tosa_level.MAX_KERNEL, "out_pad_top should be smaller than or equal to MAX_KERNEL");
- LEVEL_CHECK(out_pad_bottom <= tosa_level.MAX_KERNEL, "out_pad_bottom should be smaller than or equal to MAX_KERNEL");
+ LEVEL_CHECK(out_pad_bottom <= tosa_level.MAX_KERNEL,
+ "out_pad_bottom should be smaller than or equal to MAX_KERNEL");
LEVEL_CHECK(out_pad_left <= tosa_level.MAX_KERNEL, "out_pad_left should be smaller than or equal to MAX_KERNEL");
LEVEL_CHECK(out_pad_right <= tosa_level.MAX_KERNEL, "out_pad_right should be smaller than or equal to MAX_KERNEL");
LEVEL_CHECK(stride_y <= tosa_level.MAX_STRIDE, "stride_y should be smaller than or equal to MAX_STRIDE");
@@ -2066,9 +2045,9 @@ int OpTransposeConv2d<InDtype, WeightDtype, OutDtype>::eval()
DEBUG_INFO(OP,
"perform OpTransposeConv2d, input.shape=[%d,%d,%d,%d], weight.shape=[%d,%d,%d,%d], "
"output.shape=[%d,%d,%d,%d], stride=[%d,%d], out_pad=[%d,%d,%d,%d]",
- in_batch, in_height, in_width, in_channels, f_height, f_width, f_out_channels, f_in_channels,
- out_batch, out_height, out_width, out_channels, stride_y, stride_x, out_pad_top,
- out_pad_bottom, out_pad_left, out_pad_right);
+ in_batch, in_height, in_width, in_channels, f_height, f_width, f_out_channels, f_in_channels, out_batch,
+ out_height, out_width, out_channels, stride_y, stride_x, out_pad_top, out_pad_bottom, out_pad_left,
+ out_pad_right);
TIn input_val = this->input->getTensor();
TWeight weight_val = this->weight->getTensor();
@@ -2126,8 +2105,8 @@ int OpTransposeConv2d<InDtype, WeightDtype, OutDtype>::eval()
if ((out_x >= 0 && out_x < out_width) && (out_y >= 0 && out_y < out_height))
{
this->output->getTensor()(ob, out_y, out_x, oc) +=
- (OutEigenType) ((AccEigenType)input_val(ob, ih, iw, ic) *
- (AccEigenType)weight_val(oc, fh, fw, ic));
+ (OutEigenType)((AccEigenType)input_val(ob, ih, iw, ic) *
+ (AccEigenType)weight_val(oc, fh, fw, ic));
}
}
}
@@ -2162,7 +2141,7 @@ DEF_INSTANTIATE_TWO_TYPE(OpAvgPool2d, INT8, INT32);
DEF_INSTANTIATE_TWO_TYPE(OpAvgPool2d, INT16, INT32);
DEF_INSTANTIATE_TWO_TYPE(OpAvgPool2d, FP64, FP64);
- // [in_t, weight_t, out_t]
+// [in_t, weight_t, out_t]
DEF_INSTANTIATE_THREE_TYPE(OpConv2d, FP16, FP16, FP16);
DEF_INSTANTIATE_THREE_TYPE(OpConv2d, FP16, FP16, FP32);
DEF_INSTANTIATE_THREE_TYPE(OpConv2d, BF16, BF16, FP32);
diff --git a/reference_model/src/ops/tensor_ops.h b/reference_model/src/ops/tensor_ops.h
index df53f2b..f5fcd7f 100644
--- a/reference_model/src/ops/tensor_ops.h
+++ b/reference_model/src/ops/tensor_ops.h
@@ -55,11 +55,11 @@ public:
virtual int checkTensorAttributes();
virtual int eval();
- using InEigenType = typename GetEigenType<Dtype>::type;
- using AccEigenType = typename GetAccEigenType<AccDtype>::type; // Note: different from GetEigenType
- using OutEigenType = typename GetEigenType<Dtype>::type;
- using TIn = Eigen::Tensor<InEigenType, 4>;
- using TOut = Eigen::Tensor<OutEigenType, 4>;
+ using InEigenType = typename GetEigenType<Dtype>::type;
+ using AccEigenType = typename GetAccEigenType<AccDtype>::type; // Note: different from GetEigenType
+ using OutEigenType = typename GetEigenType<Dtype>::type;
+ using TIn = Eigen::Tensor<InEigenType, 4>;
+ using TOut = Eigen::Tensor<OutEigenType, 4>;
static constexpr int64_t QMin = GetQMin<Dtype>::value;
static constexpr int64_t QMax = GetQMax<Dtype>::value;
@@ -71,7 +71,8 @@ protected:
protected:
// return a 1D [N] tensor that describes a how many valid elements covered in the input space
- ETensor1<int32_t> calculate_div_map_1d(int in_size, int out_size, int kernel_size, int stride, int32_t padding_left, int32_t padding_right);
+ ETensor1<int32_t> calculate_div_map_1d(
+ int in_size, int out_size, int kernel_size, int stride, int32_t padding_left, int32_t padding_right);
};
template <TOSA_REF_TYPE InDtype, TOSA_REF_TYPE WeightDtype, TOSA_REF_TYPE OutDtype>
@@ -86,7 +87,7 @@ public:
using InEigenType = typename GetEigenType<InDtype>::type;
using WeightEigenType = typename GetEigenType<WeightDtype>::type;
- using AccEigenType = typename GetAccEigenType<OutDtype>::type; // Note: different from GetEigenType
+ using AccEigenType = typename GetAccEigenType<OutDtype>::type; // Note: different from GetEigenType
using OutEigenType = typename GetEigenType<OutDtype>::type;
using TIn = Eigen::Tensor<InEigenType, 4>;
using TWeight = Eigen::Tensor<WeightEigenType, 4>;
@@ -116,7 +117,7 @@ public:
using InEigenType = typename GetEigenType<InDtype>::type;
using WeightEigenType = typename GetEigenType<WeightDtype>::type;
- using AccEigenType = typename GetAccEigenType<OutDtype>::type; // Note: different from GetEigenType
+ using AccEigenType = typename GetAccEigenType<OutDtype>::type; // Note: different from GetEigenType
using OutEigenType = typename GetEigenType<OutDtype>::type;
using TIn = Eigen::Tensor<InEigenType, 5>;
using TWeight = Eigen::Tensor<WeightEigenType, 5>;
@@ -146,7 +147,7 @@ public:
using InEigenType = typename GetEigenType<InDtype>::type;
using WeightEigenType = typename GetEigenType<WeightDtype>::type;
- using AccEigenType = typename GetAccEigenType<OutDtype>::type; // Note: different from GetEigenType
+ using AccEigenType = typename GetAccEigenType<OutDtype>::type; // Note: different from GetEigenType
using OutEigenType = typename GetEigenType<OutDtype>::type;
using TIn = Eigen::Tensor<InEigenType, 4>;
using TWeight = Eigen::Tensor<WeightEigenType, 4>;
@@ -174,14 +175,14 @@ public:
virtual int checkTensorAttributes() final;
virtual int eval() final;
- using InEigenType = typename GetEigenType<InDtype>::type;
- using WeightEigenType = typename GetEigenType<WeightDtype>::type;
- using AccEigenType = typename GetAccEigenType<OutDtype>::type; // Note: different from GetEigenType
- using OutEigenType = typename GetEigenType<OutDtype>::type;
- using TIn = Eigen::Tensor<InEigenType, 2>;
- using TWeight = Eigen::Tensor<WeightEigenType, 2>;
- using TBias = Eigen::Tensor<OutEigenType, 1>;
- using TOut = Eigen::Tensor<OutEigenType, 2>;
+ using InEigenType = typename GetEigenType<InDtype>::type;
+ using WeightEigenType = typename GetEigenType<WeightDtype>::type;
+ using AccEigenType = typename GetAccEigenType<OutDtype>::type; // Note: different from GetEigenType
+ using OutEigenType = typename GetEigenType<OutDtype>::type;
+ using TIn = Eigen::Tensor<InEigenType, 2>;
+ using TWeight = Eigen::Tensor<WeightEigenType, 2>;
+ using TBias = Eigen::Tensor<OutEigenType, 1>;
+ using TOut = Eigen::Tensor<OutEigenType, 2>;
static constexpr int64_t AccQMin = GetQMin<OutDtype>::value;
static constexpr int64_t AccQMax = GetQMax<OutDtype>::value;
@@ -206,7 +207,7 @@ public:
virtual int eval() final;
using InEigenType = typename GetEigenType<Dtype>::type;
- using AccEigenType = typename GetAccEigenType<OutDtype>::type; // Note: different from GetEigenType
+ using AccEigenType = typename GetAccEigenType<OutDtype>::type; // Note: different from GetEigenType
using OutEigenType = typename GetEigenType<OutDtype>::type;
using TIn = Eigen::Tensor<InEigenType, 3>;
using TOut = Eigen::Tensor<OutEigenType, 3>;
@@ -258,10 +259,10 @@ public:
virtual int checkTensorAttributes() final;
virtual int eval() final;
- using InEigenType = typename GetEigenType<Dtype>::type;
- using OutEigenType = typename GetEigenType<Dtype>::type;
- using TIn = Eigen::Tensor<InEigenType, 3>;
- using TOut = Eigen::Tensor<OutEigenType, 3>;
+ using InEigenType = typename GetEigenType<Dtype>::type;
+ using OutEigenType = typename GetEigenType<Dtype>::type;
+ using TIn = Eigen::Tensor<InEigenType, 3>;
+ using TOut = Eigen::Tensor<OutEigenType, 3>;
protected:
TosaReference::TensorTemplate<TIn>* in_real;
@@ -281,10 +282,10 @@ public:
virtual int checkTensorAttributes() final;
virtual int eval() final;
- using InEigenType = typename GetEigenType<Dtype>::type;
- using OutEigenType = typename GetEigenType<Dtype>::type;
- using TIn = Eigen::Tensor<InEigenType, 3>;
- using TOut = Eigen::Tensor<OutEigenType, 3>;
+ using InEigenType = typename GetEigenType<Dtype>::type;
+ using OutEigenType = typename GetEigenType<Dtype>::type;
+ using TIn = Eigen::Tensor<InEigenType, 3>;
+ using TOut = Eigen::Tensor<OutEigenType, 3>;
protected:
TosaReference::TensorTemplate<TIn>* in;
@@ -304,7 +305,7 @@ public:
using InEigenType = typename GetEigenType<InDtype>::type;
using WeightEigenType = typename GetEigenType<WeightDtype>::type;
- using AccEigenType = typename GetAccEigenType<OutDtype>::type; // Note: different from GetEigenType
+ using AccEigenType = typename GetAccEigenType<OutDtype>::type; // Note: different from GetEigenType
using OutEigenType = typename GetEigenType<OutDtype>::type;
using TIn = Eigen::Tensor<InEigenType, 4>;
using TWeight = Eigen::Tensor<WeightEigenType, 4>;
diff --git a/reference_model/src/ops/type_conversion.cc b/reference_model/src/ops/type_conversion.cc
index fce8e7c..9464fd9 100644
--- a/reference_model/src/ops/type_conversion.cc
+++ b/reference_model/src/ops/type_conversion.cc
@@ -14,20 +14,18 @@
// limitations under the License.
#include "type_conversion.h"
-#include "quant_util.h"
#include "arith_util.h"
+#include "half.hpp"
+#include "quant_util.h"
#include "template_types.h"
#include <cmath>
-#include "half.hpp"
using namespace TosaReference;
using namespace Eigen;
using namespace tosa;
template <int Rank, TOSA_REF_TYPE InDtype, TOSA_REF_TYPE OutDtype>
-OpRescale<Rank, InDtype, OutDtype>::OpRescale(SubgraphTraverser* sgt_,
- TosaAttributeBase* attribute_,
- uint64_t id_)
+OpRescale<Rank, InDtype, OutDtype>::OpRescale(SubgraphTraverser* sgt_, TosaAttributeBase* attribute_, uint64_t id_)
: GraphNode(sgt_, Op_RESCALE, id_)
{
setRequiredOperands(1, 1);
@@ -160,12 +158,13 @@ int OpRescale<Rank, InDtype, OutDtype>::eval()
else
scaled = TosaReference::QuantUtil::apply_scale_16(input_zp_shifted, channel_multiplier,
channel_shift);
- int64_t res_in_64 = static_cast<int64_t>(scaled) + output_zp;
+ int64_t res_in_64 = static_cast<int64_t>(scaled) + output_zp;
int64_t i32_max_in_64 = static_cast<int64_t>(std::numeric_limits<int32_t>::max());
int64_t i32_min_in_64 = static_cast<int64_t>(std::numeric_limits<int32_t>::min());
if (res_in_64 > i32_max_in_64 || res_in_64 < i32_min_in_64)
{
- std::string desc = "scaling result [" + std::to_string(scaled) + "] plus output_zp [" + std::to_string(output_zp) + "] not in i32 range";
+ std::string desc = "scaling result [" + std::to_string(scaled) + "] plus output_zp [" +
+ std::to_string(output_zp) + "] not in i32 range";
throw desc;
}
OutEigenType out_val = static_cast<OutEigenType>(res_in_64);
@@ -201,12 +200,13 @@ int OpRescale<Rank, InDtype, OutDtype>::eval()
else
scaled =
TosaReference::QuantUtil::apply_scale_16(input_zp_shifted, tensor_multiplier, tensor_shift);
- int64_t res_in_64 = static_cast<int64_t>(scaled) + output_zp;
+ int64_t res_in_64 = static_cast<int64_t>(scaled) + output_zp;
int64_t i32_max_in_64 = static_cast<int64_t>(std::numeric_limits<int32_t>::max());
int64_t i32_min_in_64 = static_cast<int64_t>(std::numeric_limits<int32_t>::min());
if (res_in_64 > i32_max_in_64 || res_in_64 < i32_min_in_64)
{
- std::string desc = "scaling result [" + std::to_string(scaled) + "] plus output_zp [" + std::to_string(output_zp) + "] not in i32 range";
+ std::string desc = "scaling result [" + std::to_string(scaled) + "] plus output_zp [" +
+ std::to_string(output_zp) + "] not in i32 range";
throw desc;
}
@@ -234,9 +234,7 @@ int OpRescale<Rank, InDtype, OutDtype>::eval()
}
template <int Rank, TOSA_REF_TYPE InDtype, TOSA_REF_TYPE OutDtype>
-OpCast<Rank, InDtype, OutDtype>::OpCast(SubgraphTraverser* sgt_,
- TosaAttributeBase* attribute_,
- uint64_t id_)
+OpCast<Rank, InDtype, OutDtype>::OpCast(SubgraphTraverser* sgt_, TosaAttributeBase* attribute_, uint64_t id_)
: GraphNode(sgt_, Op_CAST, id_)
{
setRequiredOperands(1, 1);
@@ -315,7 +313,7 @@ CastHelper<InDtype, TOSA_REF_TYPE_FP16>::CastHelper()
// Integer data converted to fp16 (stored as fp32)
fcn = [](InEigenType in) -> float {
half_float::half h = half_float::half(in);
- float out = half_float::half_cast<float, half_float::half>(h);
+ float out = half_float::half_cast<float, half_float::half>(h);
return out;
};
}
@@ -354,10 +352,10 @@ CastHelper<TOSA_REF_TYPE_FP16, OutDtype>::CastHelper()
fcn = [](float in) -> OutEigenType {
// Cast from float representation back to half_float before rounding
half_float::half h = half_float::half(in);
- h = std::rint(h);
- OutEigenType out = half_float::half_cast<OutEigenType, half_float::half>(h);
- out = std::max<OutEigenType>(out, OutMin);
- out = std::min<OutEigenType>(out, OutMax);
+ h = std::rint(h);
+ OutEigenType out = half_float::half_cast<OutEigenType, half_float::half>(h);
+ out = std::max<OutEigenType>(out, OutMin);
+ out = std::min<OutEigenType>(out, OutMax);
return out;
};
}
@@ -365,9 +363,7 @@ CastHelper<TOSA_REF_TYPE_FP16, OutDtype>::CastHelper()
CastHelper<TOSA_REF_TYPE_FP16, TOSA_REF_TYPE_FP32>::CastHelper()
{
// No-op since fp16 values treated internally as their fp32 representation
- fcn = [](float in) -> OutEigenType {
- return in;
- };
+ fcn = [](float in) -> OutEigenType { return in; };
}
template <TOSA_REF_TYPE OutDtype>
@@ -385,9 +381,7 @@ CastHelper<TOSA_REF_TYPE_BF16, OutDtype>::CastHelper()
CastHelper<TOSA_REF_TYPE_BF16, TOSA_REF_TYPE_FP32>::CastHelper()
{
// No-op since bf16 values treated as truncated fp32 internally
- fcn = [](InEigenType in) -> OutEigenType {
- return in;
- };
+ fcn = [](InEigenType in) -> OutEigenType { return in; };
}
template <TOSA_REF_TYPE InDtype>
diff --git a/reference_model/src/subgraph_traverser.cc b/reference_model/src/subgraph_traverser.cc
index 5f6fd01..a7ef5e9 100644
--- a/reference_model/src/subgraph_traverser.cc
+++ b/reference_model/src/subgraph_traverser.cc
@@ -14,8 +14,8 @@
// limitations under the License.
#include "subgraph_traverser.h"
-#include "tosa_model_types.h"
#include "arith_util.h"
+#include "tosa_model_types.h"
#ifndef SUBGRAPH_ERROR_IF
#define SUBGRAPH_ERROR_IF(COND, fmt, ...) \
@@ -37,13 +37,15 @@ using namespace TosaReference;
using namespace Eigen;
using namespace tosa;
-SubgraphTraverser::SubgraphTraverser(TosaSerializationBasicBlock* _block, TosaSerializationHandler* _tsh, SubgraphTraverser* _parent_sgt)
+SubgraphTraverser::SubgraphTraverser(TosaSerializationBasicBlock* _block,
+ TosaSerializationHandler* _tsh,
+ SubgraphTraverser* _parent_sgt)
{
graph_status = GraphStatus::TOSA_VALID;
- block = _block;
+ block = _block;
- tsh = _tsh;
+ tsh = _tsh;
parent_sgt = _parent_sgt;
tensors.clear();
nodes.clear();
@@ -151,11 +153,11 @@ int SubgraphTraverser::initializeGraph()
TOSA_REF_TYPE input_dtype = TOSA_REF_TYPE_UNKNOWN;
TOSA_REF_TYPE output_dtype = TOSA_REF_TYPE_UNKNOWN;
TOSA_REF_TYPE weight_dtype = TOSA_REF_TYPE_UNKNOWN;
- uint32_t input_rank = 0;
- uint32_t output_rank = 0;
- uint32_t weight_rank = 0;
- int32_t input_index = -1;
- int32_t weight_index = -1;
+ uint32_t input_rank = 0;
+ uint32_t output_rank = 0;
+ uint32_t weight_rank = 0;
+ int32_t input_index = -1;
+ int32_t weight_index = -1;
switch (op->GetOp())
{
@@ -185,8 +187,10 @@ int SubgraphTraverser::initializeGraph()
std::string input_name = op->GetInputTensorNames()[input_index];
TosaSerializationTensor* input_tensor = nullptr;
- for (auto ser_tensor : ser_tensor_vec) {
- if (ser_tensor->GetName() == input_name) {
+ for (auto ser_tensor : ser_tensor_vec)
+ {
+ if (ser_tensor->GetName() == input_name)
+ {
input_tensor = ser_tensor;
}
}
@@ -207,8 +211,10 @@ int SubgraphTraverser::initializeGraph()
EnumNamesOp()[op->GetOp()], weight_index);
std::string weight_name = op->GetInputTensorNames()[weight_index];
TosaSerializationTensor* weight_tensor = nullptr;
- for (auto ser_tensor : ser_tensor_vec) {
- if (ser_tensor->GetName() == weight_name) {
+ for (auto ser_tensor : ser_tensor_vec)
+ {
+ if (ser_tensor->GetName() == weight_name)
+ {
weight_tensor = ser_tensor;
}
}
@@ -237,14 +243,18 @@ int SubgraphTraverser::initializeGraph()
EnumNamesOp()[op->GetOp()], op->GetInputTensorNames().size(), op->GetOutputTensorNames().size());
GraphNode* node = nullptr;
- if (this->parent_sgt) {
+ if (this->parent_sgt)
+ {
node = OpFactory::newOp(this->parent_sgt, tsh, op->GetOp(), op->GetAttribute(), idx, input_dtype,
- input_rank, output_dtype, output_rank, weight_dtype, weight_rank);
+ input_rank, output_dtype, output_rank, weight_dtype, weight_rank);
node->setInMainBlock(false);
- } else {
- node = OpFactory::newOp(this, tsh, op->GetOp(), op->GetAttribute(), idx, input_dtype,
- input_rank, output_dtype, output_rank, weight_dtype, weight_rank);
- if (node) {
+ }
+ else
+ {
+ node = OpFactory::newOp(this, tsh, op->GetOp(), op->GetAttribute(), idx, input_dtype, input_rank,
+ output_dtype, output_rank, weight_dtype, weight_rank);
+ if (node)
+ {
node->setInMainBlock(true);
}
}
@@ -305,7 +315,9 @@ int SubgraphTraverser::initializeGraph()
if (op->GetInputTensorNames().empty() && !node->getOnNextNodeList())
{
addToNextNodeList(node);
- } else if (!node->getInMainBlock()) {
+ }
+ else if (!node->getInMainBlock())
+ {
non_const_node_vec.push_back(node);
}
@@ -364,18 +376,21 @@ int SubgraphTraverser::initializeGraph()
}
// If the node is not in mainblock and not const
- for (auto node : non_const_node_vec) {
+ for (auto node : non_const_node_vec)
+ {
bool all_inputs_from_parent = true;
for (std::string& name : node->getInputNames())
{
TosaReference::Tensor* t = findTensorByName(name);
- if (!t->getIsParentGraphOutput()) {
+ if (!t->getIsParentGraphOutput())
+ {
all_inputs_from_parent = false;
}
}
// In the children block, when a node has all its inputs from parent
// block, we have to manually add this node to the evaluation list
- if (all_inputs_from_parent && !node->getOnNextNodeList()) {
+ if (all_inputs_from_parent && !node->getOnNextNodeList())
+ {
addToNextNodeList(node);
}
}
@@ -395,7 +410,8 @@ int SubgraphTraverser::allocateTensor()
{
if (dim <= 0)
{
- DEBUG_INFO(GT, "Failed to allocate tensor %s with invalid dimension of %d", ts->GetName().c_str(), dim);
+ DEBUG_INFO(GT, "Failed to allocate tensor %s with invalid dimension of %d", ts->GetName().c_str(),
+ dim);
this->setGraphStatus(GraphStatus::TOSA_UNPREDICTABLE);
return 1;
}
@@ -591,13 +607,15 @@ int SubgraphTraverser::evaluateNextNode()
}
// free input tensor if all of its consumers have all of their outputs ready and it's not block's output
- if (!currNode->getInMainBlock()) { // we don't free it if the node is in main block and has nested blocks
+ if (!currNode->getInMainBlock())
+ { // we don't free it if the node is in main block and has nested blocks
for (auto tensor : currNode->getInputs())
{
bool in_use = false;
auto tensor_check = findTensorByName(tensor->getName());
- if (tensor_check->getIsParentGraphOutput()) {
+ if (tensor_check->getIsParentGraphOutput())
+ {
// if it's parent's block output tensor, we can't free it
continue;
}
@@ -609,7 +627,6 @@ int SubgraphTraverser::evaluateNextNode()
{
in_use = true;
}
-
}
for (auto name : block->GetOutputs())
{
diff --git a/reference_model/src/subgraph_traverser.h b/reference_model/src/subgraph_traverser.h
index 1cf582e..00989ee 100644
--- a/reference_model/src/subgraph_traverser.h
+++ b/reference_model/src/subgraph_traverser.h
@@ -16,8 +16,8 @@
#ifndef SUBGRAPH_TRAVERSER_H
#define SUBGRAPH_TRAVERSER_H
-#include "graph_status.h"
#include "graph_node.h"
+#include "graph_status.h"
#include "model_common.h"
#include "ops/op_factory.h"
#include "tensor.h"
diff --git a/reference_model/src/tensor.cc b/reference_model/src/tensor.cc
index c5f5e02..4982c99 100644
--- a/reference_model/src/tensor.cc
+++ b/reference_model/src/tensor.cc
@@ -30,11 +30,11 @@ TosaReference::Tensor::Tensor(const std::string tensorName_,
, shape(shape_)
, tensorDtype(ConvertDType(serializationDtype_))
{
- producer = nullptr;
- isValid = false;
+ producer = nullptr;
+ isValid = false;
consumers.clear();
- isSubgraphInput = false;
- isSubgraphOutput = false;
+ isSubgraphInput = false;
+ isSubgraphOutput = false;
isParentGraphOutput = false;
}
@@ -94,16 +94,16 @@ int TosaReference::Tensor::dumpTensorParams(std::ostream& out) const
int TosaReference::Tensor::readFromNpyFile(const char* filename)
{
- uint32_t elements = getElementCount();
+ uint32_t elements = getElementCount();
double* f64databuf = nullptr;
float* f32databuf = nullptr;
half_float::half* f16databuf = nullptr;
- int32_t* i32databuf = nullptr;
- int64_t* i64databuf = nullptr;
- bool* bdatabuf = nullptr;
+ int32_t* i32databuf = nullptr;
+ int64_t* i64databuf = nullptr;
+ bool* bdatabuf = nullptr;
NumpyUtilities::NPError nperror;
- TOSA_REF_TYPE dtype = getDtype();
- DType serialization_dtype = getSerializationDtype();
+ TOSA_REF_TYPE dtype = getDtype();
+ DType serialization_dtype = getSerializationDtype();
assert(dtype == ConvertDType(serialization_dtype));
// if dtype is FP64, serialization_dtype must be one of FP32, FP16, BF16
@@ -178,7 +178,8 @@ int TosaReference::Tensor::readFromNpyFile(const char* filename)
// Convert from fp16 to fp32 so that fp16 values can be manipulated as float
f32databuf = (float*)calloc(sizeof(float), elements);
ASSERT_MEM(f32databuf);
- for (uint32_t i=0; i < elements; i++) {
+ for (uint32_t i = 0; i < elements; i++)
+ {
f32databuf[i] = half_float::half_cast<float, half_float::half>(f16databuf[i]);
}
if (setTensorValueFloat(elements, f32databuf))
@@ -189,12 +190,9 @@ int TosaReference::Tensor::readFromNpyFile(const char* filename)
}
break;
case TOSA_REF_TYPE_BF16:
- for (uint32_t i=0; i < elements; i++)
+ for (uint32_t i = 0; i < elements; i++)
{
- ASSERT_MSG(
- checkValidBFloat(f32databuf[i]),
- "Input float value not a valid bfloat16 value."
- );
+ ASSERT_MSG(checkValidBFloat(f32databuf[i]), "Input float value not a valid bfloat16 value.");
}
if (setTensorValueFloat(elements, f32databuf))
{
@@ -313,15 +311,15 @@ int TosaReference::Tensor::readFromNpyFile(const char* filename)
int TosaReference::Tensor::writeToNpyFile(const char* filename) const
{
- float* f32databuf = nullptr;
- double* f64databuf = nullptr;
- half_float::half* f16databuf = nullptr;
- int32_t* i32databuf = nullptr;
- int64_t* i64databuf = nullptr;
- bool* bdatabuf = nullptr;
+ float* f32databuf = nullptr;
+ double* f64databuf = nullptr;
+ half_float::half* f16databuf = nullptr;
+ int32_t* i32databuf = nullptr;
+ int64_t* i64databuf = nullptr;
+ bool* bdatabuf = nullptr;
NumpyUtilities::NPError nperror = NumpyUtilities::NO_ERROR;
- uint32_t elements = getElementCount();
- const TOSA_REF_TYPE dtype = getDtype();
+ uint32_t elements = getElementCount();
+ const TOSA_REF_TYPE dtype = getDtype();
switch (dtype)
{
@@ -352,7 +350,8 @@ int TosaReference::Tensor::writeToNpyFile(const char* filename) const
return 1;
}
// Convert fp32 to fp16 so that output file contains valid fp16 data
- for (uint32_t i=0; i < elements; i++) {
+ for (uint32_t i = 0; i < elements; i++)
+ {
f16databuf[i] = half_float::half_cast<half_float::half, float>(f32databuf[i]);
}
nperror = NumpyUtilities::writeToNpyFile(filename, shape, f16databuf);
@@ -592,10 +591,7 @@ int TosaReference::Tensor::readfromVector(const ArrayProxy<float> vals)
for (auto v : vals)
{
- ASSERT_MSG(
- checkValidBFloat(v),
- "Input float value not a valid bfloat16 value."
- );
+ ASSERT_MSG(checkValidBFloat(v), "Input float value not a valid bfloat16 value.");
}
setTensorValueFloat(elements, vals.data());
@@ -625,7 +621,7 @@ int TosaReference::Tensor::readfromVector(const ArrayProxy<half_float::half> val
}
// Convert from fp16 to fp32
- for (uint32_t i=0; i < elements; i++)
+ for (uint32_t i = 0; i < elements; i++)
{
tensor[i] = half_float::half_cast<float, half_float::half>(vals[i]);
}
@@ -772,10 +768,7 @@ int TosaReference::Tensor::writeToVector(ArrayProxy<float> vals)
for (auto v : vals)
{
- ASSERT_MSG(
- checkValidBFloat(v),
- "Float value not a valid bfloat16 value."
- );
+ ASSERT_MSG(checkValidBFloat(v), "Float value not a valid bfloat16 value.");
}
break;
@@ -805,7 +798,7 @@ int TosaReference::Tensor::writeToVector(ArrayProxy<half_float::half> vals)
getTensorValueFloat(elements, tensor.data());
// Convert fp32 to fp16
- for (uint32_t i=0; i < elements; i++)
+ for (uint32_t i = 0; i < elements; i++)
{
vals[i] = half_float::half_cast<half_float::half, float>(tensor[i]);
}
diff --git a/reference_model/src/tensor.h b/reference_model/src/tensor.h
index d49e004..f59a5e1 100644
--- a/reference_model/src/tensor.h
+++ b/reference_model/src/tensor.h
@@ -42,7 +42,8 @@ public:
int setIsSubgraphOutput();
int setIsParentGraphOutput();
- int getIsParentGraphOutput() const {
+ int getIsParentGraphOutput() const
+ {
return isParentGraphOutput;
}
diff --git a/reference_model/src/tosa_model_types.h b/reference_model/src/tosa_model_types.h
index 84402ae..fd7ce53 100644
--- a/reference_model/src/tosa_model_types.h
+++ b/reference_model/src/tosa_model_types.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2022, ARM Limited.
+// Copyright (c) 2022-2023, ARM Limited.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -19,4 +19,4 @@
inline const uint32_t TOSA_MAX_TENSOR_SIZE = ((1u << 31) - 1);
-#endif // TOSA_MODEL_TYPES_H \ No newline at end of file
+#endif // TOSA_MODEL_TYPES_H \ No newline at end of file
diff --git a/reference_model/src/verify.cc b/reference_model/src/verify.cc
index 584a418..89d1b67 100644
--- a/reference_model/src/verify.cc
+++ b/reference_model/src/verify.cc
@@ -100,31 +100,32 @@ CheckResult from_optional(const std::optional<double>& res)
}
} // namespace
-extern "C" {
-
-CheckResult tosa_validate_element_accfp32(double ref, double bnd, float imp, size_t KS)
+extern "C"
{
- auto err = validate_element<float>(ref, bnd, imp, KS);
- return from_optional(err);
-}
-bool tosa_validate_output_error(double err_sum, double err_sum_sq, size_t T, size_t KS, int S)
-{
- if (S != 1 && S != 2)
+ CheckResult tosa_validate_element_accfp32(double ref, double bnd, float imp, size_t KS)
{
- // Check error bias magnitude for data sets S which are not positive biased
- REQUIRE(abs(err_sum) <= 2 * sqrt(KS * T));
+ auto err = validate_element<float>(ref, bnd, imp, KS);
+ return from_optional(err);
}
- // Check error variance magnitude
- REQUIRE(err_sum_sq <= 0.4 * KS * T);
- return true;
-}
+ bool tosa_validate_output_error(double err_sum, double err_sum_sq, size_t T, size_t KS, int S)
+ {
+ if (S != 1 && S != 2)
+ {
+ // Check error bias magnitude for data sets S which are not positive biased
+ REQUIRE(abs(err_sum) <= 2 * sqrt(KS * T));
+ }
+ // Check error variance magnitude
+ REQUIRE(err_sum_sq <= 0.4 * KS * T);
+
+ return true;
+ }
-bool tosa_validate_data_fp32(const double* ref, const double* bnd, const float* imp, size_t T, size_t KS, int S)
-{
- return validate_data<float>(ref, bnd, imp, T, KS, S);
-}
+ bool tosa_validate_data_fp32(const double* ref, const double* bnd, const float* imp, size_t T, size_t KS, int S)
+ {
+ return validate_data<float>(ref, bnd, imp, T, KS, S);
+ }
-} // extern "C"
+} // extern "C"
#undef REQUIRE \ No newline at end of file