From f0180a2baab8908d6ce9528d2505ea870b465171 Mon Sep 17 00:00:00 2001 From: songmingyang Date: Sat, 27 Aug 2022 14:10:49 +0800 Subject: [PATCH 01/17] cleancode --- parser/common/tbe_plugin_loader.cc | 2 +- parser/common/tbe_plugin_loader.h | 4 ++-- parser/common/thread_pool.cc | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/parser/common/tbe_plugin_loader.cc b/parser/common/tbe_plugin_loader.cc index 08ff44a..291487d 100644 --- a/parser/common/tbe_plugin_loader.cc +++ b/parser/common/tbe_plugin_loader.cc @@ -1,5 +1,5 @@ /** - * Copyright 2020 Huawei Technologies Co., Ltd + * Copyright (c) Huawei Technologies Co., Ltd. 2022. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/parser/common/tbe_plugin_loader.h b/parser/common/tbe_plugin_loader.h index c8bf65c..1a75bef 100644 --- a/parser/common/tbe_plugin_loader.h +++ b/parser/common/tbe_plugin_loader.h @@ -1,5 +1,5 @@ /** - * Copyright 2020 Huawei Technologies Co., Ltd + * Copyright (c) Huawei Technologies Co., Ltd. 2022. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -55,4 +55,4 @@ private: }; } // namespace ge -#endif //PARSER_COMMON_TBE_PLUGIN_LOADER_H_ +#endif // PARSER_COMMON_TBE_PLUGIN_LOADER_H_ diff --git a/parser/common/thread_pool.cc b/parser/common/thread_pool.cc index 7c90109..9e9e4ca 100644 --- a/parser/common/thread_pool.cc +++ b/parser/common/thread_pool.cc @@ -1,5 +1,5 @@ /** - * Copyright 2020 Huawei Technologies Co., Ltd + * Copyright (c) Huawei Technologies Co., Ltd. 2022. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. From 5a5e1876b28bbee8303adceef7a9f2cba26ca03d Mon Sep 17 00:00:00 2001 From: songmingyang Date: Sat, 27 Aug 2022 14:15:03 +0800 Subject: [PATCH 02/17] cleancode --- parser/common/thread_pool.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/parser/common/thread_pool.h b/parser/common/thread_pool.h index ab2f6a7..a15b1d2 100644 --- a/parser/common/thread_pool.h +++ b/parser/common/thread_pool.h @@ -25,13 +25,13 @@ #include #include #include -#include +//#include #include #include "framework/common/debug/ge_log.h" #include "framework/common/ge_inner_error_codes.h" #include "external/ge/ge_api_error_codes.h" -#include "graph/types.h" +//#include "graph/types.h" #include "parser/common/acl_graph_parser_util.h" namespace ge { From f61b76e8924ddaf92d560662a511bf673035d983 Mon Sep 17 00:00:00 2001 From: songmingyang Date: Sat, 27 Aug 2022 14:43:49 +0800 Subject: [PATCH 03/17] cleancode --- parser/common/thread_pool.h | 2 -- parser/common/types_map.h | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/parser/common/thread_pool.h b/parser/common/thread_pool.h index a15b1d2..96a9cfd 100644 --- a/parser/common/thread_pool.h +++ b/parser/common/thread_pool.h @@ -25,13 +25,11 @@ #include #include #include -//#include #include #include "framework/common/debug/ge_log.h" #include "framework/common/ge_inner_error_codes.h" #include "external/ge/ge_api_error_codes.h" -//#include "graph/types.h" #include "parser/common/acl_graph_parser_util.h" namespace ge { diff --git a/parser/common/types_map.h b/parser/common/types_map.h index 3e75990..373969a 100644 --- a/parser/common/types_map.h +++ b/parser/common/types_map.h @@ -1,5 +1,5 @@ /** - * Copyright 2020 Huawei Technologies Co., Ltd + * Copyright (c) Huawei Technologies Co., Ltd. 2022. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. From a7ea5679233d84d691fb32b76c916ccaf0b32221 Mon Sep 17 00:00:00 2001 From: songmingyang Date: Sat, 27 Aug 2022 15:04:45 +0800 Subject: [PATCH 04/17] cleancode --- parser/common/tuple.h | 59 +++++++++++++++---------------------------- 1 file changed, 20 insertions(+), 39 deletions(-) diff --git a/parser/common/tuple.h b/parser/common/tuple.h index f59eda4..683e81b 100644 --- a/parser/common/tuple.h +++ b/parser/common/tuple.h @@ -1,5 +1,5 @@ /** - * Copyright 2020 Huawei Technologies Co., Ltd + * Copyright (c) Huawei Technologies Co., Ltd. 2022. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,27 +32,23 @@ class Tuple { delete[] data_heap_; data_heap_ = nullptr; } - /// + /// @brief copy constructor from another tuple /// @param s the source tuple - /// inline Tuple(const Tuple &s) { this->assign(s.begin(), s.end()); } - /// + /// @brief constructor from initializer list /// @param init the initializer_list - /// explicit Tuple(const std::initializer_list &init) { this->assign(init.begin(), init.end()); } - /// + /// @brief constructor from vector /// @param init the vector - /// explicit Tuple(const std::vector &init) { // NOLINT(runtime/explicit) this->assign(init.begin(), init.end()); } - /// + /// @brief move constructor from Tuple /// @param src the source shape - /// inline Tuple(Tuple &&src) { // NOLINT(runtime/explicit) this->swap(src); } @@ -77,102 +73,88 @@ class Tuple { this->SetDim(end - begin); (void)std::copy(begin, end, this->begin()); } - /// + /// @brief Swap current object with other /// @param other another object to be swapped. - /// inline void swap(Tuple &other) { // NOLINT(*) std::swap(ndim_, other.ndim_); std::swap(num_heap_allocated_, other.num_heap_allocated_); std::swap(data_stack_, other.data_stack_); std::swap(data_heap_, other.data_heap_); } - /// + /// @brief assignment from another tuple. /// @param src source tuple /// @return reference of self - /// inline Tuple &operator=(const Tuple &src) { if (&src != this) { this->assign(src.begin(), src.end()); } return *this; } - /// + /// @brief assignment from rvalue of another tuple. /// @param src source tuple /// @return reference of self - /// inline Tuple &operator=(Tuple &&src) { if (&src != this) { Tuple(std::move(src)).swap(*this); } return *this; } - /// + /// @brief assignment from initializer list /// @param init the source initializer list /// @return reference of self - /// inline Tuple &operator=(std::initializer_list init) { this->assign(init.begin(), init.end()); return *this; } - /// + /// @return whether two tuple equals /// @param s the tuple to compare against - /// inline bool operator==(const Tuple &s) const { if (ndim_ != s.ndim_) { return false; } return std::equal(begin(), end(), s.begin()); } - /// + /// @return whether two tuple not equal /// @param s the tuple to compare against - /// inline bool operator!=(const Tuple &s) const { return !(*this == s); } - /// + /// @return the begin data pointer to content of the tuple - /// inline const ValueType *begin() const { return ndim_ <= STACK_CACHE_NUM ? data_stack_ : data_heap_; } - /// + /// @return the begin data pointer to content of the tuple - /// inline ValueType *begin() { return ndim_ <= STACK_CACHE_NUM ? data_stack_ : data_heap_; } - /// + /// @return the data pointer to end of the tuple - /// inline const ValueType *end() const { return ndim_ <= STACK_CACHE_NUM ? (data_stack_ + ndim_) : (data_heap_ + ndim_); } - /// + /// @return the data pointer to end the tuple - /// inline ValueType *end() { return ndim_ <= STACK_CACHE_NUM ? (data_stack_ + ndim_) : (data_heap_ + ndim_); } - /// + /// @return number of dimension of the tuple - /// inline uint32_t ndim() const { return ndim_; } - /// + /// @brief get corresponding index /// @param i dimension index /// @return the corresponding dimension size - /// inline ValueType &operator[](size_t i) { return begin()[i]; } - /// + /// @brief get corresponding index /// @param i dimension index /// @return the corresponding dimension size - /// inline const ValueType &operator[](size_t i) const { return begin()[i]; } - /// + /// @brief allow output string of tuple to ostream /// @param os the output stream /// @param t the tuple /// @return the ostream - /// friend std::ostream &operator<<(std::ostream &os, const Tuple &t) { os << '['; const ValueType *begin = t.begin(); @@ -186,12 +168,11 @@ class Tuple { os << ']'; return os; } - /// + /// @brief read tuple from the istream /// @param is the input stream /// @param t The tuple /// @return the istream - /// friend std::istream &operator>>(std::istream &is, Tuple &t) { // get ( if (!HandleLeftBracket(is, t)) { From 35229458b89970a1eea03556fff0981cd01edea6 Mon Sep 17 00:00:00 2001 From: songmingyang Date: Sat, 27 Aug 2022 15:48:11 +0800 Subject: [PATCH 05/17] cleancode --- parser/common/register_tbe.cc | 4 ++-- parser/common/register_tbe.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/parser/common/register_tbe.cc b/parser/common/register_tbe.cc index 421c9cb..9ccb6b0 100644 --- a/parser/common/register_tbe.cc +++ b/parser/common/register_tbe.cc @@ -1,5 +1,5 @@ /** - * Copyright 2020 Huawei Technologies Co., Ltd + * Copyright (c) Huawei Technologies Co., Ltd. 2022. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -42,7 +42,7 @@ FMK_FUNC_HOST_VISIBILITY OpRegistrationTbe *OpRegistrationTbe::Instance() { return &instance; } -bool OpRegistrationTbe::Finalize(const OpRegistrationData ®_data, bool is_train) { +bool OpRegistrationTbe::Finalize(const OpRegistrationData ®_data, bool is_train) onst { static std::map *> op_map = {{domi::CAFFE, &caffe_op_map}}; if (is_train) { op_map[domi::TENSORFLOW] = &tensorflow_train_op_map; diff --git a/parser/common/register_tbe.h b/parser/common/register_tbe.h index 5578054..670c221 100644 --- a/parser/common/register_tbe.h +++ b/parser/common/register_tbe.h @@ -1,5 +1,5 @@ /** - * Copyright 2020 Huawei Technologies Co., Ltd + * Copyright (c) Huawei Technologies Co., Ltd. 2022. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,7 +24,7 @@ class OpRegistrationTbe { public: static OpRegistrationTbe *Instance(); - bool Finalize(const OpRegistrationData ®_data, bool is_train = false); + bool Finalize(const OpRegistrationData ®_data, bool is_train = false) const; private: bool RegisterParser(const OpRegistrationData ®_data) const; From 781bc8e0ab9877a13b159456a2723c7bc1d98064 Mon Sep 17 00:00:00 2001 From: songmingyang Date: Sat, 27 Aug 2022 16:07:33 +0800 Subject: [PATCH 06/17] cleancode --- parser/common/proto_file_parser.h | 2 +- parser/common/prototype_pass_manager.cc | 2 +- parser/common/prototype_pass_manager.h | 2 +- parser/common/register_tbe.cc | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/parser/common/proto_file_parser.h b/parser/common/proto_file_parser.h index 55f32a5..3441c89 100644 --- a/parser/common/proto_file_parser.h +++ b/parser/common/proto_file_parser.h @@ -1,5 +1,5 @@ /** - * Copyright 2020 Huawei Technologies Co., Ltd + * Copyright (c) Huawei Technologies Co., Ltd. 2022. All rights reserved. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/parser/common/prototype_pass_manager.cc b/parser/common/prototype_pass_manager.cc index b54702c..57d2110 100644 --- a/parser/common/prototype_pass_manager.cc +++ b/parser/common/prototype_pass_manager.cc @@ -1,5 +1,5 @@ /** - * Copyright 2021 Huawei Technologies Co., Ltd + * Copyright (c) Huawei Technologies Co., Ltd. 2022. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/parser/common/prototype_pass_manager.h b/parser/common/prototype_pass_manager.h index 028ffbe..97b4f74 100644 --- a/parser/common/prototype_pass_manager.h +++ b/parser/common/prototype_pass_manager.h @@ -1,5 +1,5 @@ /** - * Copyright 2021 Huawei Technologies Co., Ltd + * Copyright (c) Huawei Technologies Co., Ltd. 2022. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/parser/common/register_tbe.cc b/parser/common/register_tbe.cc index 9ccb6b0..83f9f44 100644 --- a/parser/common/register_tbe.cc +++ b/parser/common/register_tbe.cc @@ -42,7 +42,7 @@ FMK_FUNC_HOST_VISIBILITY OpRegistrationTbe *OpRegistrationTbe::Instance() { return &instance; } -bool OpRegistrationTbe::Finalize(const OpRegistrationData ®_data, bool is_train) onst { +bool OpRegistrationTbe::Finalize(const OpRegistrationData ®_data, bool is_train) const { static std::map *> op_map = {{domi::CAFFE, &caffe_op_map}}; if (is_train) { op_map[domi::TENSORFLOW] = &tensorflow_train_op_map; From f9956a82804e459e631b8d81a1664c34d412acee Mon Sep 17 00:00:00 2001 From: songmingyang Date: Sat, 27 Aug 2022 16:34:08 +0800 Subject: [PATCH 07/17] cleancode --- parser/common/pre_checker.h | 2 +- parser/common/proto_file_parser.cc | 2 +- parser/common/register_tbe.cc | 2 +- parser/common/register_tbe.h | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/parser/common/pre_checker.h b/parser/common/pre_checker.h index 12a0327..ad04c76 100644 --- a/parser/common/pre_checker.h +++ b/parser/common/pre_checker.h @@ -1,5 +1,5 @@ /** - * Copyright 2020 Huawei Technologies Co., Ltd + * Copyright (c) Huawei Technologies Co., Ltd. 2022. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/parser/common/proto_file_parser.cc b/parser/common/proto_file_parser.cc index 0bae5db..52ca523 100644 --- a/parser/common/proto_file_parser.cc +++ b/parser/common/proto_file_parser.cc @@ -1,5 +1,5 @@ /** - * Copyright 2020 Huawei Technologies Co., Ltd + * Copyright (c) Huawei Technologies Co., Ltd. 2022. All rights reserved. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/parser/common/register_tbe.cc b/parser/common/register_tbe.cc index 83f9f44..061772c 100644 --- a/parser/common/register_tbe.cc +++ b/parser/common/register_tbe.cc @@ -42,7 +42,7 @@ FMK_FUNC_HOST_VISIBILITY OpRegistrationTbe *OpRegistrationTbe::Instance() { return &instance; } -bool OpRegistrationTbe::Finalize(const OpRegistrationData ®_data, bool is_train) const { +bool OpRegistrationTbe::Finalize(const OpRegistrationData ®_data, bool is_train) { static std::map *> op_map = {{domi::CAFFE, &caffe_op_map}}; if (is_train) { op_map[domi::TENSORFLOW] = &tensorflow_train_op_map; diff --git a/parser/common/register_tbe.h b/parser/common/register_tbe.h index 670c221..62e6acf 100644 --- a/parser/common/register_tbe.h +++ b/parser/common/register_tbe.h @@ -24,7 +24,7 @@ class OpRegistrationTbe { public: static OpRegistrationTbe *Instance(); - bool Finalize(const OpRegistrationData ®_data, bool is_train = false) const; + bool Finalize(const OpRegistrationData ®_data, bool is_train = false); private: bool RegisterParser(const OpRegistrationData ®_data) const; From d15109756c3e1d80f93e50fb2ff618300ce687d7 Mon Sep 17 00:00:00 2001 From: songmingyang Date: Sat, 27 Aug 2022 17:03:17 +0800 Subject: [PATCH 08/17] cleancode --- parser/common/pass_manager.cc | 4 ++-- parser/common/pass_manager.h | 12 +++--------- parser/common/pre_checker.cc | 2 +- 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/parser/common/pass_manager.cc b/parser/common/pass_manager.cc index f08fad3..1e2ad9e 100644 --- a/parser/common/pass_manager.cc +++ b/parser/common/pass_manager.cc @@ -1,5 +1,5 @@ /** - * Copyright 2020 Huawei Technologies Co., Ltd + * Copyright (c) Huawei Technologies Co., Ltd. 2022. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,11 +15,11 @@ */ #include "common/util.h" -#include "parser/common/pass_manager.h" #include "framework/omg/parser/parser_types.h" #include "parser/common/acl_graph_parser_util.h" #include "graph/utils/node_utils.h" #include "omg/omg_inner_types.h" +#include "parser/common/pass_manager.h" namespace ge { namespace parser { diff --git a/parser/common/pass_manager.h b/parser/common/pass_manager.h index 46ecb5a..c7c7771 100644 --- a/parser/common/pass_manager.h +++ b/parser/common/pass_manager.h @@ -30,30 +30,24 @@ namespace parser { /// class PassManager { public: - /// + /// get graph passes /// @author - /// const std::vector> &GraphPasses() const; - /// /// Add graph pass /// @param [in] pass Pass to be added, it will be destroyed when pass manager destroys. /// @author - /// Status AddPass(const string &pass_name, GraphPass *const pass); - /// /// Optimize graph with added pass /// @param [inout] graph graph to be optimized /// @return SUCCESS optimize successfully /// @return NOT_CHANGED not optimized /// @return others optimize failed /// @author - /// Status Run(const ge::ComputeGraphPtr &graph); - /// /// Optimize graph with specified pass /// @param [inout] graph graph to be optimized /// @param [in] passes passes to be used @@ -61,8 +55,8 @@ public: /// @return NOT_CHANGED not optimized /// @return others optimized failed /// @author - /// - static Status Run(const ge::ComputeGraphPtr &graph, std::vector> &names_to_passes); + static Status Run(const ge::ComputeGraphPtr &graph, + std::vector> &names_to_passes); ~PassManager(); diff --git a/parser/common/pre_checker.cc b/parser/common/pre_checker.cc index 4fc79dc..7b53340 100644 --- a/parser/common/pre_checker.cc +++ b/parser/common/pre_checker.cc @@ -1,5 +1,5 @@ /** - * Copyright 2020 Huawei Technologies Co., Ltd + * Copyright (c) Huawei Technologies Co., Ltd. 2022. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. From 8e725a2b6948928841ee40852872d7526274e6cd Mon Sep 17 00:00:00 2001 From: songmingyang Date: Sat, 27 Aug 2022 17:38:02 +0800 Subject: [PATCH 09/17] cleancode --- parser/common/parser_utils.cc | 2 +- parser/common/parser_utils.h | 4 ++-- parser/common/pass.h | 3 +-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/parser/common/parser_utils.cc b/parser/common/parser_utils.cc index d053a38..0595bba 100644 --- a/parser/common/parser_utils.cc +++ b/parser/common/parser_utils.cc @@ -1,5 +1,5 @@ /** - * Copyright 2020 Huawei Technologies Co., Ltd + * Copyright (c) Huawei Technologies Co., Ltd. 2022. All rights reserved. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/parser/common/parser_utils.h b/parser/common/parser_utils.h index 1b8764a..130e640 100644 --- a/parser/common/parser_utils.h +++ b/parser/common/parser_utils.h @@ -1,5 +1,5 @@ /** - * Copyright 2020 Huawei Technologies Co., Ltd + * Copyright (c) Huawei Technologies Co., Ltd. 2022. All rights reserved. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -41,7 +41,7 @@ class ParserUtils { static Status HandleInputContext(const NodePtr &node, const std::vector &input_nodes, const ComputeGraphPtr &compute_graph); - static Status HandleOutputContext(const NodePtr &node, + static Status HandleOutputContext(const NodePtr &node, const std::vector> &out_node_index, OutputMapping &output_mapping); }; diff --git a/parser/common/pass.h b/parser/common/pass.h index 7db45b6..80744df 100644 --- a/parser/common/pass.h +++ b/parser/common/pass.h @@ -29,10 +29,9 @@ template class Pass { public: virtual ~Pass() {} - /// + /// run pass /// @author - /// virtual Status Run(std::shared_ptr) = 0; }; } // namespace ge From 6db2bc797739b8046622d2de36ca8c657c2dd73f Mon Sep 17 00:00:00 2001 From: songmingyang Date: Mon, 29 Aug 2022 20:26:17 +0800 Subject: [PATCH 10/17] cleancode --- parser/common/parser_fp16_t.h | 2 +- parser/common/parser_inner_ctx.cc | 2 +- parser/common/parser_types.cc | 2 +- parser/common/parser_utils.cc | 2 +- parser/common/parser_utils.h | 2 +- parser/common/pass_manager.cc | 2 +- parser/common/pre_checker.cc | 2 +- parser/common/pre_checker.h | 2 +- parser/common/proto_file_parser.cc | 2 +- parser/common/proto_file_parser.h | 2 +- parser/common/prototype_pass_manager.cc | 2 +- parser/common/prototype_pass_manager.h | 2 +- parser/common/register_tbe.cc | 2 +- parser/common/register_tbe.h | 2 +- parser/common/tbe_plugin_loader.cc | 2 +- parser/common/tbe_plugin_loader.h | 2 +- parser/common/thread_pool.cc | 2 +- parser/common/tuple.h | 2 +- parser/common/types_map.h | 2 +- 19 files changed, 19 insertions(+), 19 deletions(-) diff --git a/parser/common/parser_fp16_t.h b/parser/common/parser_fp16_t.h index 2a50d2f..2d4c060 100644 --- a/parser/common/parser_fp16_t.h +++ b/parser/common/parser_fp16_t.h @@ -1,5 +1,5 @@ /** - * Copyright 2020 Huawei Technologies Co., Ltd + * Copyright (c) Huawei Technologies Co., Ltd. 2020. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/parser/common/parser_inner_ctx.cc b/parser/common/parser_inner_ctx.cc index 1e5bc84..04e44fa 100644 --- a/parser/common/parser_inner_ctx.cc +++ b/parser/common/parser_inner_ctx.cc @@ -1,5 +1,5 @@ /** - * Copyright 2020 Huawei Technologies Co., Ltd + * Copyright (c) Huawei Technologies Co., Ltd. 2020. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/parser/common/parser_types.cc b/parser/common/parser_types.cc index fbfdc57..a7bf216 100644 --- a/parser/common/parser_types.cc +++ b/parser/common/parser_types.cc @@ -1,5 +1,5 @@ /** - * Copyright 2019-2020 Huawei Technologies Co., Ltd + * Copyright (c) Huawei Technologies Co., Ltd. 2020. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/parser/common/parser_utils.cc b/parser/common/parser_utils.cc index 0595bba..7b4e886 100644 --- a/parser/common/parser_utils.cc +++ b/parser/common/parser_utils.cc @@ -1,5 +1,5 @@ /** - * Copyright (c) Huawei Technologies Co., Ltd. 2022. All rights reserved. + * Copyright (c) Huawei Technologies Co., Ltd. 2020. All rights reserved. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/parser/common/parser_utils.h b/parser/common/parser_utils.h index 130e640..d40c52a 100644 --- a/parser/common/parser_utils.h +++ b/parser/common/parser_utils.h @@ -1,5 +1,5 @@ /** - * Copyright (c) Huawei Technologies Co., Ltd. 2022. All rights reserved. + * Copyright (c) Huawei Technologies Co., Ltd. 2020. All rights reserved. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/parser/common/pass_manager.cc b/parser/common/pass_manager.cc index 1e2ad9e..19b6e5c 100644 --- a/parser/common/pass_manager.cc +++ b/parser/common/pass_manager.cc @@ -1,5 +1,5 @@ /** - * Copyright (c) Huawei Technologies Co., Ltd. 2022. All rights reserved. + * Copyright (c) Huawei Technologies Co., Ltd. 2020. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/parser/common/pre_checker.cc b/parser/common/pre_checker.cc index 7b53340..7d5c141 100644 --- a/parser/common/pre_checker.cc +++ b/parser/common/pre_checker.cc @@ -1,5 +1,5 @@ /** - * Copyright (c) Huawei Technologies Co., Ltd. 2022. All rights reserved. + * Copyright (c) Huawei Technologies Co., Ltd. 2020. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/parser/common/pre_checker.h b/parser/common/pre_checker.h index ad04c76..dce9335 100644 --- a/parser/common/pre_checker.h +++ b/parser/common/pre_checker.h @@ -1,5 +1,5 @@ /** - * Copyright (c) Huawei Technologies Co., Ltd. 2022. All rights reserved. + * Copyright (c) Huawei Technologies Co., Ltd. 2020. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/parser/common/proto_file_parser.cc b/parser/common/proto_file_parser.cc index 52ca523..d1e32c5 100644 --- a/parser/common/proto_file_parser.cc +++ b/parser/common/proto_file_parser.cc @@ -1,5 +1,5 @@ /** - * Copyright (c) Huawei Technologies Co., Ltd. 2022. All rights reserved. + * Copyright (c) Huawei Technologies Co., Ltd. 2020. All rights reserved. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/parser/common/proto_file_parser.h b/parser/common/proto_file_parser.h index 3441c89..15019fd 100644 --- a/parser/common/proto_file_parser.h +++ b/parser/common/proto_file_parser.h @@ -1,5 +1,5 @@ /** - * Copyright (c) Huawei Technologies Co., Ltd. 2022. All rights reserved. + * Copyright (c) Huawei Technologies Co., Ltd. 2020. All rights reserved. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/parser/common/prototype_pass_manager.cc b/parser/common/prototype_pass_manager.cc index 57d2110..f8e16c7 100644 --- a/parser/common/prototype_pass_manager.cc +++ b/parser/common/prototype_pass_manager.cc @@ -1,5 +1,5 @@ /** - * Copyright (c) Huawei Technologies Co., Ltd. 2022. All rights reserved. + * Copyright (c) Huawei Technologies Co., Ltd. 2020. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/parser/common/prototype_pass_manager.h b/parser/common/prototype_pass_manager.h index 97b4f74..d1b19e2 100644 --- a/parser/common/prototype_pass_manager.h +++ b/parser/common/prototype_pass_manager.h @@ -1,5 +1,5 @@ /** - * Copyright (c) Huawei Technologies Co., Ltd. 2022. All rights reserved. + * Copyright (c) Huawei Technologies Co., Ltd. 2020. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/parser/common/register_tbe.cc b/parser/common/register_tbe.cc index 061772c..c1287f2 100644 --- a/parser/common/register_tbe.cc +++ b/parser/common/register_tbe.cc @@ -1,5 +1,5 @@ /** - * Copyright (c) Huawei Technologies Co., Ltd. 2022. All rights reserved. + * Copyright (c) Huawei Technologies Co., Ltd. 2020. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/parser/common/register_tbe.h b/parser/common/register_tbe.h index 62e6acf..a20d86b 100644 --- a/parser/common/register_tbe.h +++ b/parser/common/register_tbe.h @@ -1,5 +1,5 @@ /** - * Copyright (c) Huawei Technologies Co., Ltd. 2022. All rights reserved. + * Copyright (c) Huawei Technologies Co., Ltd. 2020. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/parser/common/tbe_plugin_loader.cc b/parser/common/tbe_plugin_loader.cc index 291487d..2389852 100644 --- a/parser/common/tbe_plugin_loader.cc +++ b/parser/common/tbe_plugin_loader.cc @@ -1,5 +1,5 @@ /** - * Copyright (c) Huawei Technologies Co., Ltd. 2022. All rights reserved. + * Copyright (c) Huawei Technologies Co., Ltd. 2020. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/parser/common/tbe_plugin_loader.h b/parser/common/tbe_plugin_loader.h index 1a75bef..b5adfb5 100644 --- a/parser/common/tbe_plugin_loader.h +++ b/parser/common/tbe_plugin_loader.h @@ -1,5 +1,5 @@ /** - * Copyright (c) Huawei Technologies Co., Ltd. 2022. All rights reserved. + * Copyright (c) Huawei Technologies Co., Ltd. 2020. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/parser/common/thread_pool.cc b/parser/common/thread_pool.cc index 9e9e4ca..6f0591f 100644 --- a/parser/common/thread_pool.cc +++ b/parser/common/thread_pool.cc @@ -1,5 +1,5 @@ /** - * Copyright (c) Huawei Technologies Co., Ltd. 2022. All rights reserved. + * Copyright (c) Huawei Technologies Co., Ltd. 2020. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/parser/common/tuple.h b/parser/common/tuple.h index 683e81b..fe2fb8c 100644 --- a/parser/common/tuple.h +++ b/parser/common/tuple.h @@ -1,5 +1,5 @@ /** - * Copyright (c) Huawei Technologies Co., Ltd. 2022. All rights reserved. + * Copyright (c) Huawei Technologies Co., Ltd. 2020. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/parser/common/types_map.h b/parser/common/types_map.h index 373969a..33f7c50 100644 --- a/parser/common/types_map.h +++ b/parser/common/types_map.h @@ -1,5 +1,5 @@ /** - * Copyright (c) Huawei Technologies Co., Ltd. 2022. All rights reserved. + * Copyright (c) Huawei Technologies Co., Ltd. 2020. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. From 662414a4ebca13a35b214a64347c325dfab0cc73 Mon Sep 17 00:00:00 2001 From: songmingyang Date: Tue, 30 Aug 2022 09:25:48 +0800 Subject: [PATCH 11/17] cleancode --- parser/common/parser_fp16_t.cc | 2 +- parser/common/parser_fp16_t.h | 8 ++------ 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/parser/common/parser_fp16_t.cc b/parser/common/parser_fp16_t.cc index cf31644..f815249 100644 --- a/parser/common/parser_fp16_t.cc +++ b/parser/common/parser_fp16_t.cc @@ -1,5 +1,5 @@ /** - * Copyright 2020 Huawei Technologies Co., Ltd + * Copyright (c) Huawei Technologies Co., Ltd. 2020. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/parser/common/parser_fp16_t.h b/parser/common/parser_fp16_t.h index 2d4c060..38787d9 100644 --- a/parser/common/parser_fp16_t.h +++ b/parser/common/parser_fp16_t.h @@ -131,10 +131,6 @@ constexpr uint16_t kFp16MaxValidExp = 0x001E; /// @ingroup fp16 basic parameter /// @brief maximum mantissa value of fp16(11111 11111) constexpr uint16_t kFp16MaxMan = 0x03FF; -/// @ingroup fp16 basic parameter -/// @brief absolute minimum normal value of fp16 -/// (E=1,M=0 D=2^(-14)=0.00006103515625) -constexpr uint16_t kFp16MinNormal = 1.0f / (2 << 14); /// @ingroup fp16 basic operator /// @brief get sign of fp16 #define FP16_EXTRAC_SIGN(x) (((x) >> 15) & 1) @@ -605,14 +601,14 @@ T GetManSum(int16_t e_a, const T &m_a, int16_t e_b, const T &m_b) { T sum = 0; if (e_a != e_b) { T m_tmp = 0; - int16_t e_tmp = std::abs(e_a - e_b); + int16_t e_tmp = staic_cast(std::abs(e_a - e_b)); if (e_a > e_b) { m_tmp = m_b; m_tmp = RightShift(m_tmp, e_tmp); sum = m_a + m_tmp; } else { m_tmp = m_a; - m_tmp = RightShift(m_tmp, e_tmp); + m_tm= RightShift(m_tmp, e_tmp); sum = m_tmp + m_b; } } else { From 28641c6aa007ae800625282ffdf70221e2b211b7 Mon Sep 17 00:00:00 2001 From: songmingyang Date: Tue, 30 Aug 2022 10:00:21 +0800 Subject: [PATCH 12/17] cleancode --- parser/common/parser_fp16_t.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parser/common/parser_fp16_t.h b/parser/common/parser_fp16_t.h index 38787d9..b489b7e 100644 --- a/parser/common/parser_fp16_t.h +++ b/parser/common/parser_fp16_t.h @@ -608,7 +608,7 @@ T GetManSum(int16_t e_a, const T &m_a, int16_t e_b, const T &m_b) { sum = m_a + m_tmp; } else { m_tmp = m_a; - m_tm= RightShift(m_tmp, e_tmp); + m_tmp = RightShift(m_tmp, e_tmp); sum = m_tmp + m_b; } } else { From 8ffd6636b017100f4a2cf0ad321a590582757535 Mon Sep 17 00:00:00 2001 From: songmingyang Date: Tue, 30 Aug 2022 10:25:30 +0800 Subject: [PATCH 13/17] cleancode --- parser/common/parser_fp16_t.h | 38 ++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/parser/common/parser_fp16_t.h b/parser/common/parser_fp16_t.h index b489b7e..166112c 100644 --- a/parser/common/parser_fp16_t.h +++ b/parser/common/parser_fp16_t.h @@ -133,31 +133,49 @@ constexpr uint16_t kFp16MaxValidExp = 0x001E; constexpr uint16_t kFp16MaxMan = 0x03FF; /// @ingroup fp16 basic operator /// @brief get sign of fp16 -#define FP16_EXTRAC_SIGN(x) (((x) >> 15) & 1) +inline uint16_t FP16_EXTRAC_SIGN(const uint16_t x) { + return (((x) >> 15) & 1); +} /// @ingroup fp16 basic operator /// @brief get exponent of fp16 -#define FP16_EXTRAC_EXP(x) (((x) >> 10) & kFp16MaxExp) +inline uint16_t FP16_EXTRAC_EXP(const uint16_t x) { + return (((x) >> 10) & kFp16MaxExp); +} /// @ingroup fp16 basic operator /// @brief get mantissa of fp16 -#define FP16_EXTRAC_MAN(x) ((((x) >> 0) & 0x3FF) | (((((x) >> 10) & 0x1F) > 0 ? 1 : 0) * 0x400)) +inline uint16_t FP16_EXTRAC_MAN(const uint16_t x) { + return ((((x) >> 0) & 0x3FF) | (((((x) >> 10) & 0x1F) > 0 ? 1 : 0) * 0x400)); +} /// @ingroup fp16 basic operator /// @brief constructor of fp16 from sign exponent and mantissa -#define FP16_CONSTRUCTOR(s, e, m) (((s) << kFp16SignIndex) | ((e) << kFp16ManLen) | ((m) & kFp16MaxMan)) +inline uint16_t FP16_CONSTRUCTOR(const uint16_t s, const uint16_t e, const uint16_t m) { + return (((s) << kFp16SignIndex) | ((e) << kFp16ManLen) | ((m) & kFp16MaxMan)); +} /// @ingroup fp16 special value judgment /// @brief whether a fp16 is zero -#define FP16_IS_ZERO(x) (((x) & kFp16AbsMax) == 0) +inline bool FP16_IS_ZERO(const uint16_t x) { + return (((x) & kFp16AbsMax) == 0); +} /// @ingroup fp16 special value judgment /// @brief whether a fp16 is a denormalized value -#define FP16_IS_DENORM(x) ((((x) & kFp16ExpMask) == 0)) +inline bool FP16_IS_DENORM(const uint16_t x) { + return ((((x) & kFp16ExpMask) == 0)); +} /// @ingroup fp16 special value judgment /// @brief whether a fp16 is infinite -#define FP16_IS_INF(x) (((x)&kFp16AbsMax) == kFp16ExpMask) +inline bool FP16_IS_INF(const uint16_t x) { + return (((x)&kFp16AbsMax) == kFp16ExpMask); +} /// @ingroup fp16 special value judgment /// @brief whether a fp16 is NaN -#define FP16_IS_NAN(x) ((((x) & kFp16ExpMask) == kFp16ExpMask) && ((x) & kFp16ManMask)) +inline bool FP16_IS_NAN(const uint16_t x) { + return ((((x) & kFp16ExpMask) == kFp16ExpMask) && ((x) & kFp16ManMask)); +} /// @ingroup fp16 special value judgment /// @brief whether a fp16 is invalid -#define FP16_IS_INVALID(x) (((x) & kFp16ExpMask) == kFp16ExpMask) +inline bool FP16_IS_INVALID(const uint16_t x) { + return (((x) & kFp16ExpMask) == kFp16ExpMask); +} /// @ingroup fp32 basic parameter /// @brief fp32 exponent bias constexpr uint16_t kFp32ExpBias = 127U; @@ -601,7 +619,7 @@ T GetManSum(int16_t e_a, const T &m_a, int16_t e_b, const T &m_b) { T sum = 0; if (e_a != e_b) { T m_tmp = 0; - int16_t e_tmp = staic_cast(std::abs(e_a - e_b)); + int16_t e_tmp = std::abs(e_a - e_b); if (e_a > e_b) { m_tmp = m_b; m_tmp = RightShift(m_tmp, e_tmp); From b264b4f08a6ad0a7b8b6d717ace68c2667222219 Mon Sep 17 00:00:00 2001 From: songmingyang Date: Tue, 30 Aug 2022 11:31:09 +0800 Subject: [PATCH 14/17] cleancode --- parser/common/parser_fp16_t.h | 38 ++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/parser/common/parser_fp16_t.h b/parser/common/parser_fp16_t.h index 166112c..191ef2a 100644 --- a/parser/common/parser_fp16_t.h +++ b/parser/common/parser_fp16_t.h @@ -211,25 +211,39 @@ constexpr uint32_t kFp32MaxExp = 0xFFU; constexpr uint32_t kFp32MaxMan = 0x7FFFFFU; /// @ingroup fp32 special value judgment /// @brief whether a fp32 is NaN -#define FP32_IS_NAN(x) ((((x) & kFp32ExpMask) == kFp32ExpMask) && ((x) & kFp32ManMask)) +inline bool FP32_IS_NAN(cons uint16_t x) { + return ((((x) & kFp32ExpMask) == kFp32ExpMask) && ((x) & kFp32ManMask)); +} /// @ingroup fp32 special value judgment /// @brief whether a fp32 is infinite -#define FP32_IS_INF(x) ((((x) & kFp32ExpMask) == kFp32ExpMask) && (!((x) & kFp32ManMask))) +inline bool FP32_IS_INF(const uint16_t x) { + return ((((x) & kFp32ExpMask) == kFp32ExpMask) && (!((x) & kFp32ManMask))); +} /// @ingroup fp32 special value judgment /// @brief whether a fp32 is a denormalized value -#define FP32_IS_DENORM(x) ((((x)&kFp32ExpMask) == 0)) +inline bool FP32_IS_DENORM(const uint16_t x) { + return ((((x)&kFp32ExpMask) == 0)); +} /// @ingroup fp32 basic operator /// @brief get sign of fp32 -#define FP32_EXTRAC_SIGN(x) (((x) >> kFp32SignIndex) & 1) +inline bool FP32_EXTRAC_SIGN(const uint16_t x) { + return (((x) >> kFp32SignIndex) & 1); +} /// @ingroup fp32 basic operator /// @brief get exponent of fp16 -#define FP32_EXTRAC_EXP(x) (((x)&kFp32ExpMask) >> kFp32ManLen) +inline bool FP32_EXTRAC_EXP(const uint16_t x) { + return (((x)&kFp32ExpMask) >> kFp32ManLen); +} /// @ingroup fp32 basic operator /// @brief get mantissa of fp16 -#define FP32_EXTRAC_MAN(x) (((x)&kFp32ManMask) | (((((x) >> kFp32ManLen) & kFp32MaxExp) > 0 ? 1 : 0) * kFp32ManHideBit)) +inline uint16_t FP32_EXTRAC_MAN(const uint16_t x) { + return (((x)&kFp32ManMask) | (((((x) >> kFp32ManLen) & kFp32MaxExp) > 0 ? 1 : 0) * kFp32ManHideBit)); +} /// @ingroup fp32 basic operator /// @brief constructor of fp32 from sign exponent and mantissa -#define FP32_CONSTRUCTOR(s, e, m) (((s) << kFp32SignIndex) | ((e) << kFp32ManLen) | ((m) & kFp32MaxMan)) +inline uint16_t FP32_CONSTRUCTOR(const uint16_t s, const uint16_t e, const uint16_t m) { + return (((s) << kFp32SignIndex) | ((e) << kFp32ManLen) | ((m) & kFp32MaxMan)); +} /// @ingroup fp64 basic parameter /// @brief fp64 exponent bias constexpr uint16_t kFp64ExpBias = 1023U; @@ -265,10 +279,14 @@ constexpr uint64_t kFp64MaxExp = 0x07FF; constexpr uint64_t kFp64MaxMan = 0xFFFFFFFFFFFLLu; /// @ingroup fp64 special value judgment /// @brief whether a fp64 is NaN -#define FP64_IS_NAN(x) ((((x) & kFp64ExpMask) == kFp64ExpMask) && ((x) & kFp64ManMask)) +inline bool FP64_IS_NAN(const uint16_t x) { + return ((((x) & kFp64ExpMask) == kFp64ExpMask) && ((x) & kFp64ManMask)); +} /// @ingroup fp64 special value judgment /// @brief whether a fp64 is infinite -#define FP64_IS_INF(x) ((((x) & kFp64ExpMask) == kFp64ExpMask) && (!((x) & kFp64ManMask))) +inline bool FP64_IS_INF(const uint16_t x) { + return ((((x) & kFp64ExpMask) == kFp64ExpMask) && (!((x) & kFp64ManMask))); +} /// @ingroup integer special value judgment /// @brief maximum positive value of int8_t (0111 1111) constexpr int8_t kInt8Max = 0x7F; @@ -619,7 +637,7 @@ T GetManSum(int16_t e_a, const T &m_a, int16_t e_b, const T &m_b) { T sum = 0; if (e_a != e_b) { T m_tmp = 0; - int16_t e_tmp = std::abs(e_a - e_b); + int16_t e_tmp = static_caststd::abs(e_a - e_b); if (e_a > e_b) { m_tmp = m_b; m_tmp = RightShift(m_tmp, e_tmp); From 0571b1a75ce53e2f671cd3d36f73e801e2dff92e Mon Sep 17 00:00:00 2001 From: songmingyang Date: Tue, 30 Aug 2022 11:42:51 +0800 Subject: [PATCH 15/17] cleancode --- parser/common/parser_fp16_t.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/parser/common/parser_fp16_t.h b/parser/common/parser_fp16_t.h index 191ef2a..c36e4ae 100644 --- a/parser/common/parser_fp16_t.h +++ b/parser/common/parser_fp16_t.h @@ -211,7 +211,7 @@ constexpr uint32_t kFp32MaxExp = 0xFFU; constexpr uint32_t kFp32MaxMan = 0x7FFFFFU; /// @ingroup fp32 special value judgment /// @brief whether a fp32 is NaN -inline bool FP32_IS_NAN(cons uint16_t x) { +inline bool FP32_IS_NAN(const uint16_t x) { return ((((x) & kFp32ExpMask) == kFp32ExpMask) && ((x) & kFp32ManMask)); } /// @ingroup fp32 special value judgment @@ -637,7 +637,7 @@ T GetManSum(int16_t e_a, const T &m_a, int16_t e_b, const T &m_b) { T sum = 0; if (e_a != e_b) { T m_tmp = 0; - int16_t e_tmp = static_caststd::abs(e_a - e_b); + int16_t e_tmp = static_cast(std::abs(e_a - e_b)); if (e_a > e_b) { m_tmp = m_b; m_tmp = RightShift(m_tmp, e_tmp); From 1dfa7aeccd111ba39cb2bec72d93d3dd26bd381a Mon Sep 17 00:00:00 2001 From: songmingyang Date: Tue, 30 Aug 2022 15:34:01 +0800 Subject: [PATCH 16/17] cleancode --- parser/common/parser_fp16_t.cc | 118 ++++++++++++++++----------------- parser/common/parser_fp16_t.h | 36 +++++----- 2 files changed, 77 insertions(+), 77 deletions(-) diff --git a/parser/common/parser_fp16_t.cc b/parser/common/parser_fp16_t.cc index f815249..3ce5c6b 100644 --- a/parser/common/parser_fp16_t.cc +++ b/parser/common/parser_fp16_t.cc @@ -30,9 +30,9 @@ const TagFp16RoundMode g_round_mode = TagFp16RoundMode::kRoundToNearest; void ExtractFp16(const uint16_t &val, uint16_t &s, int16_t &e, uint16_t &m) { // 1.Extract - s = static_cast(FP16_EXTRAC_SIGN(val)); - e = static_cast(FP16_EXTRAC_EXP(val)); - m = static_cast(FP16_EXTRAC_MAN(val)); + s = static_cast(Fp16ExtracSign(val)); + e = static_cast(Fp16ExtracExp(val)); + m = static_cast(Fp16ExtracMan(val)); // Denormal if (e == 0) { e = 1; @@ -104,7 +104,7 @@ static float Fp16ToFloat(const uint16_t &fp_val) { m_ret = hf_man & kFp16ManMask; m_ret = m_ret << (kFp32ManLen - kFp16ManLen); } - uint32_t f_val = FP32_CONSTRUCTOR(s_ret, e_ret, m_ret); + uint32_t f_val = Fp32Constructor(s_ret, e_ret, m_ret); auto p_ret_v = ge::PtrToPtr(&f_val); return *p_ret_v; @@ -172,12 +172,12 @@ static int8_t Fp16ToInt8(const uint16_t &fp_val) { int8_t ret; uint8_t ret_v; // 1.get s_ret and shift it to bit0. - uint8_t s_ret = FP16_EXTRAC_SIGN(fp_val); + uint8_t s_ret = Fp16ExtracSign(fp_val); // 2.get hf_e and hf_m - uint16_t hf_e = FP16_EXTRAC_EXP(fp_val); - uint16_t hf_m = FP16_EXTRAC_MAN(fp_val); + uint16_t hf_e = Fp16ExtracExp(fp_val); + uint16_t hf_m = Fp16ExtracMan(fp_val); - if (FP16_IS_DENORM(fp_val)) { // Denormalized number + if (Fp16IsDenorm(fp_val)) { // Denormalized number ret_v = 0; ret = *(ge::PtrToPtr(&ret_v)); return ret; @@ -186,7 +186,7 @@ static int8_t Fp16ToInt8(const uint16_t &fp_val) { uint64_t long_int_m = hf_m; uint8_t overflow_flag = 0; uint16_t shift_out = 0; - if (FP16_IS_INVALID(fp_val)) { // Inf or NaN + if (Fp16IsInvalid(fp_val)) { // Inf or NaN overflow_flag = 1; } else { while (hf_e != kFp16ExpBias) { @@ -226,16 +226,16 @@ static int8_t Fp16ToInt8(const uint16_t &fp_val) { static uint8_t Fp16ToUInt8(const uint16_t &fp_val) { uint8_t m_ret = 0; // 1.get s_ret and shift it to bit0. - uint8_t s_ret = FP16_EXTRAC_SIGN(fp_val); + uint8_t s_ret = Fp16ExtracSign(fp_val); // 2.get hf_e and hf_m - uint16_t hf_e = FP16_EXTRAC_EXP(fp_val); - uint16_t hf_m = FP16_EXTRAC_MAN(fp_val); + uint16_t hf_e = Fp16ExtracExp(fp_val); + uint16_t hf_m = Fp16ExtracMan(fp_val); - if (FP16_IS_DENORM(fp_val)) { // Denormalized number + if (Fp16IsDenorm(fp_val)) { // Denormalized number return 0; } - if (FP16_IS_INVALID(fp_val)) { // Inf or NaN + if (Fp16IsInvalid(fp_val)) { // Inf or NaN m_ret = ~0; } else { uint64_t long_int_m = hf_m; @@ -301,12 +301,12 @@ static int16_t Fp16ToInt16(const uint16_t &fp_val) { int16_t ret; uint16_t ret_v; // 1.get s_ret and shift it to bit0. - uint16_t s_ret = FP16_EXTRAC_SIGN(fp_val); + uint16_t s_ret = Fp16ExtracSign(fp_val); // 2.get hf_e and hf_m - uint16_t hf_e = FP16_EXTRAC_EXP(fp_val); - uint16_t hf_m = FP16_EXTRAC_MAN(fp_val); + uint16_t hf_e = Fp16ExtracExp(fp_val); + uint16_t hf_m = Fp16ExtracMan(fp_val); - if (FP16_IS_DENORM(fp_val)) { // Denormalized number + if (Fp16IsDenorm(fp_val)) { // Denormalized number ret_v = 0; ret = *(ge::PtrToPtr(&ret_v)); return ret; @@ -315,7 +315,7 @@ static int16_t Fp16ToInt16(const uint16_t &fp_val) { uint64_t long_int_m = hf_m; uint8_t overflow_flag = 0; uint16_t shift_out = 0; - if (FP16_IS_INVALID(fp_val)) { // Inf or NaN + if (Fp16IsInvalid(fp_val)) { // Inf or NaN overflow_flag = 1; } else { while (hf_e != kFp16ExpBias) { @@ -354,16 +354,16 @@ static int16_t Fp16ToInt16(const uint16_t &fp_val) { static uint16_t Fp16ToUInt16(const uint16_t &fp_val) { uint16_t m_ret = 0; // 1.get s_ret and shift it to bit0. - uint16_t s_ret = FP16_EXTRAC_SIGN(fp_val); + uint16_t s_ret = Fp16ExtracSign(fp_val); // 2.get hf_e and hf_m - uint16_t hf_e = FP16_EXTRAC_EXP(fp_val); - uint16_t hf_m = FP16_EXTRAC_MAN(fp_val); + uint16_t hf_e = Fp16ExtracExp(fp_val); + uint16_t hf_m = Fp16ExtracMan(fp_val); - if (FP16_IS_DENORM(fp_val)) { // Denormalized number + if (Fp16IsDenorm(fp_val)) { // Denormalized number return 0; } - if (FP16_IS_INVALID(fp_val)) { // Inf or NaN + if (Fp16IsInvalid(fp_val)) { // Inf or NaN m_ret = ~0; } else { uint64_t long_int_m = hf_m; @@ -398,12 +398,12 @@ static uint16_t Fp16ToUInt16(const uint16_t &fp_val) { static int32_t Fp16ToInt32(const uint16_t &fp_val) { uint32_t ret_v; // 1.get s_ret and shift it to bit0. - uint32_t s_ret = FP16_EXTRAC_SIGN(fp_val); + uint32_t s_ret = Fp16ExtracSign(fp_val); // 2.get hf_e and hf_m - uint16_t hf_e = FP16_EXTRAC_EXP(fp_val); - uint16_t hf_m = FP16_EXTRAC_MAN(fp_val); + uint16_t hf_e = Fp16ExtracExp(fp_val); + uint16_t hf_m = Fp16ExtracMan(fp_val); - if (FP16_IS_INVALID(fp_val)) { // Inf or NaN + if (Fp16IsInvalid(fp_val)) { // Inf or NaN ret_v = kInt32Max + s_ret; } else { uint64_t long_int_m = hf_m; @@ -444,16 +444,16 @@ static int32_t Fp16ToInt32(const uint16_t &fp_val) { static uint32_t Fp16ToUInt32(const uint16_t &fp_val) { uint32_t m_ret; // 1.get s_ret and shift it to bit0. - uint32_t s_ret = FP16_EXTRAC_SIGN(fp_val); + uint32_t s_ret = Fp16ExtracSign(fp_val); // 2.get hf_e and hf_m - uint16_t hf_e = FP16_EXTRAC_EXP(fp_val); - uint16_t hf_m = FP16_EXTRAC_MAN(fp_val); + uint16_t hf_e = Fp16ExtracExp(fp_val); + uint16_t hf_m = Fp16ExtracMan(fp_val); - if (FP16_IS_DENORM(fp_val)) { // Denormalized number + if (Fp16IsDenorm(fp_val)) { // Denormalized number return 0u; } - if (FP16_IS_INVALID(fp_val)) { // Inf or NaN + if (Fp16IsInvalid(fp_val)) { // Inf or NaN m_ret = ~0u; } else { uint64_t long_int_m = hf_m; @@ -513,7 +513,7 @@ static uint16_t Fp16AddCalVal(uint16_t s_ret, int16_t e_ret, uint16_t m_ret, uin m_ret = m_ret >> 1; } Fp16Normalize(e_ret, m_ret); - uint16_t ret = FP16_CONSTRUCTOR(s_ret, static_cast(e_ret), m_ret); + uint16_t ret = Fp16Constructor(s_ret, static_cast(e_ret), m_ret); return ret; } @@ -640,7 +640,7 @@ static uint16_t Fp16Mul(uint16_t v_1, uint16_t v_2) { Fp16Normalize(e_ret, m_ret); - uint16_t ret = FP16_CONSTRUCTOR(s_ret, static_cast(e_ret), m_ret); + uint16_t ret = Fp16Constructor(s_ret, static_cast(e_ret), m_ret); return ret; } @@ -651,15 +651,15 @@ static uint16_t Fp16Mul(uint16_t v_1, uint16_t v_2) { /// @return Return fp16_t result of division this by fp static uint16_t Fp16Div(uint16_t v_1, uint16_t v_2) { uint16_t ret; - if (FP16_IS_ZERO(v_2)) { // result is inf + if (Fp16IsZero(v_2)) { // result is inf // throw "fp16_t division by zero."; uint16_t s_a, s_b; uint16_t s_ret; - s_a = FP16_EXTRAC_SIGN(v_1); - s_b = FP16_EXTRAC_SIGN(v_2); + s_a = Fp16ExtracSign(v_1); + s_b = Fp16ExtracSign(v_2); s_ret = s_a ^ s_b; - ret = FP16_CONSTRUCTOR(s_ret, kFp16MaxExp, 0u); - } else if (FP16_IS_ZERO(v_1)) { + ret = Fp16Constructor(s_ret, kFp16MaxExp, 0u); + } else if (Fp16IsZero(v_1)) { ret = 0u; } else { uint16_t s_a, s_b; @@ -747,7 +747,7 @@ fp16_t fp16_t::operator/=(const fp16_t fp) { // compare bool fp16_t::operator==(const fp16_t &fp) const { bool result = true; - if (FP16_IS_ZERO(val) && FP16_IS_ZERO(fp.val)) { + if (Fp16IsZero(val) && Fp16IsZero(fp.val)) { result = true; } else { result = ((val & kBitLen16Max) == (fp.val & kBitLen16Max)); // bit compare @@ -757,7 +757,7 @@ bool fp16_t::operator==(const fp16_t &fp) const { bool fp16_t::operator!=(const fp16_t &fp) const { bool result = true; - if (FP16_IS_ZERO(val) && FP16_IS_ZERO(fp.val)) { + if (Fp16IsZero(val) && Fp16IsZero(fp.val)) { result = false; } else { result = ((val & kBitLen16Max) != (fp.val & kBitLen16Max)); // bit compare @@ -772,17 +772,17 @@ bool fp16_t::operator>(const fp16_t &fp) const { bool result = true; // 1.Extract - s_a = FP16_EXTRAC_SIGN(val); - s_b = FP16_EXTRAC_SIGN(fp.val); - e_a = FP16_EXTRAC_EXP(val); - e_b = FP16_EXTRAC_EXP(fp.val); - m_a = FP16_EXTRAC_MAN(val); - m_b = FP16_EXTRAC_MAN(fp.val); + s_a = Fp16ExtracSign(val); + s_b = Fp16ExtracSign(fp.val); + e_a = Fp16ExtracExp(val); + e_b = Fp16ExtracExp(fp.val); + m_a = Fp16ExtracMan(val); + m_b = Fp16ExtracMan(fp.val); // Compare if ((s_a == 0) && (s_b > 0)) { // + - // -0=0 - result = !(FP16_IS_ZERO(val) && FP16_IS_ZERO(fp.val)); + result = !(Fp16IsZero(val) && Fp16IsZero(fp.val)); } else if ((s_a == 0) && (s_b == 0)) { // + + if (e_a > e_b) { // e_a - e_b >= 1; Va always larger than Vb result = true; @@ -898,7 +898,7 @@ fp16_t &fp16_t::operator=(const float &f_val) { } Fp16Normalize(e_ret, m_ret); - val = FP16_CONSTRUCTOR(s_ret, static_cast(e_ret), m_ret); + val = Fp16Constructor(s_ret, static_cast(e_ret), m_ret); return *this; } @@ -923,7 +923,7 @@ fp16_t &fp16_t::operator=(const int8_t &i_val) { e_ret = e_ret + kFp16ExpBias; } - val = FP16_CONSTRUCTOR(s_ret, e_ret, m_ret); + val = Fp16Constructor(s_ret, e_ret, m_ret); return *this; } @@ -941,7 +941,7 @@ fp16_t &fp16_t::operator=(const uint8_t &ui_val) { e_ret = e_ret + kFp16ExpBias; } - val = FP16_CONSTRUCTOR(s_ret, e_ret, m_ret); + val = Fp16Constructor(s_ret, e_ret, m_ret); return *this; } @@ -982,7 +982,7 @@ static void SetValByUint16Val(const uint16_t &input_val, const uint16_t &sign, u e_ret = e_ret + (len - 1); } auto m_ret = static_cast(m_tmp); - ret_val = FP16_CONSTRUCTOR(sign, static_cast(e_ret), m_ret); + ret_val = Fp16Constructor(sign, static_cast(e_ret), m_ret); } } @@ -1035,7 +1035,7 @@ fp16_t &fp16_t::operator=(const uint16_t &ui_val) { m_ret = m_ret >> 1; e_ret = e_ret + 1; } - if (FP16_IS_INVALID(val)) { + if (Fp16IsInvalid(val)) { val = kFp16Max; } } else { @@ -1043,7 +1043,7 @@ fp16_t &fp16_t::operator=(const uint16_t &ui_val) { m_ret = m_ret << (static_cast(kDim11) - len); e_ret = e_ret + (len - 1); } - val = FP16_CONSTRUCTOR(0u, static_cast(e_ret), m_ret); + val = Fp16Constructor(0u, static_cast(e_ret), m_ret); } return *this; } @@ -1089,7 +1089,7 @@ static void SetValByUint32Val(const uint32_t &input_val, const uint16_t &sign, u e_ret = e_ret + (len - 1); } auto m_ret = static_cast(m_tmp); - ret_val = FP16_CONSTRUCTOR(sign, static_cast(e_ret), m_ret); + ret_val = Fp16Constructor(sign, static_cast(e_ret), m_ret); } fp16_t &fp16_t::operator=(const int32_t &i_val) { @@ -1151,7 +1151,7 @@ fp16_t &fp16_t::operator=(const uint32_t &ui_val) { e_ret = e_ret + (len - 1); } auto m_ret = static_cast(m_tmp); - val = FP16_CONSTRUCTOR(0u, static_cast(e_ret), m_ret); + val = Fp16Constructor(0u, static_cast(e_ret), m_ret); } return *this; } @@ -1175,7 +1175,7 @@ fp16_t &fp16_t::operator=(const double &d_val) { if (e_d >= 0x410u) { // 0x410:1040=1023+16 e_ret = kFp16MaxExp - 1; m_ret = kFp16MaxMan; - val = FP16_CONSTRUCTOR(s_ret, static_cast(e_ret), m_ret); + val = Fp16Constructor(s_ret, static_cast(e_ret), m_ret); } else if (e_d <= 0x3F0u) { // Exponent underflow converts to denormalized half or signed zero // 0x3F0:1008=1023-15 // Signed zeros, denormalized floats, and floats with small @@ -1211,7 +1211,7 @@ fp16_t &fp16_t::operator=(const double &d_val) { } Fp16Normalize(e_ret, m_ret); - val = FP16_CONSTRUCTOR(s_ret, static_cast(e_ret), m_ret); + val = Fp16Constructor(s_ret, static_cast(e_ret), m_ret); return *this; } diff --git a/parser/common/parser_fp16_t.h b/parser/common/parser_fp16_t.h index c36e4ae..e8722f9 100644 --- a/parser/common/parser_fp16_t.h +++ b/parser/common/parser_fp16_t.h @@ -133,47 +133,47 @@ constexpr uint16_t kFp16MaxValidExp = 0x001E; constexpr uint16_t kFp16MaxMan = 0x03FF; /// @ingroup fp16 basic operator /// @brief get sign of fp16 -inline uint16_t FP16_EXTRAC_SIGN(const uint16_t x) { +inline uint16_t Fp16ExtracSign(const uint16_t x) { return (((x) >> 15) & 1); } /// @ingroup fp16 basic operator /// @brief get exponent of fp16 -inline uint16_t FP16_EXTRAC_EXP(const uint16_t x) { +inline uint16_t Fp16ExtracExp(const uint16_t x) { return (((x) >> 10) & kFp16MaxExp); } /// @ingroup fp16 basic operator /// @brief get mantissa of fp16 -inline uint16_t FP16_EXTRAC_MAN(const uint16_t x) { +inline uint16_t Fp16ExtracMan(const uint16_t x) { return ((((x) >> 0) & 0x3FF) | (((((x) >> 10) & 0x1F) > 0 ? 1 : 0) * 0x400)); } /// @ingroup fp16 basic operator /// @brief constructor of fp16 from sign exponent and mantissa -inline uint16_t FP16_CONSTRUCTOR(const uint16_t s, const uint16_t e, const uint16_t m) { +inline uint16_t Fp16Constructor(const uint16_t s, const uint16_t e, const uint16_t m) { return (((s) << kFp16SignIndex) | ((e) << kFp16ManLen) | ((m) & kFp16MaxMan)); } /// @ingroup fp16 special value judgment /// @brief whether a fp16 is zero -inline bool FP16_IS_ZERO(const uint16_t x) { +inline bool Fp16IsZero(const uint16_t x) { return (((x) & kFp16AbsMax) == 0); } /// @ingroup fp16 special value judgment /// @brief whether a fp16 is a denormalized value -inline bool FP16_IS_DENORM(const uint16_t x) { +inline bool Fp16IsDenorm(const uint16_t x) { return ((((x) & kFp16ExpMask) == 0)); } /// @ingroup fp16 special value judgment /// @brief whether a fp16 is infinite -inline bool FP16_IS_INF(const uint16_t x) { +inline bool Fp16IsInf(const uint16_t x) { return (((x)&kFp16AbsMax) == kFp16ExpMask); } /// @ingroup fp16 special value judgment /// @brief whether a fp16 is NaN -inline bool FP16_IS_NAN(const uint16_t x) { +inline bool Fp16IsNan(const uint16_t x) { return ((((x) & kFp16ExpMask) == kFp16ExpMask) && ((x) & kFp16ManMask)); } /// @ingroup fp16 special value judgment /// @brief whether a fp16 is invalid -inline bool FP16_IS_INVALID(const uint16_t x) { +inline bool Fp16IsInvalid(const uint16_t x) { return (((x) & kFp16ExpMask) == kFp16ExpMask); } /// @ingroup fp32 basic parameter @@ -211,37 +211,37 @@ constexpr uint32_t kFp32MaxExp = 0xFFU; constexpr uint32_t kFp32MaxMan = 0x7FFFFFU; /// @ingroup fp32 special value judgment /// @brief whether a fp32 is NaN -inline bool FP32_IS_NAN(const uint16_t x) { +inline bool Fp32IsNan(const uint16_t x) { return ((((x) & kFp32ExpMask) == kFp32ExpMask) && ((x) & kFp32ManMask)); } /// @ingroup fp32 special value judgment /// @brief whether a fp32 is infinite -inline bool FP32_IS_INF(const uint16_t x) { +inline bool Fp32IsInf(const uint16_t x) { return ((((x) & kFp32ExpMask) == kFp32ExpMask) && (!((x) & kFp32ManMask))); } /// @ingroup fp32 special value judgment /// @brief whether a fp32 is a denormalized value -inline bool FP32_IS_DENORM(const uint16_t x) { +inline bool Fp32IsDenorm(const uint16_t x) { return ((((x)&kFp32ExpMask) == 0)); } /// @ingroup fp32 basic operator /// @brief get sign of fp32 -inline bool FP32_EXTRAC_SIGN(const uint16_t x) { +inline bool Fp32ExtracSign(const uint16_t x) { return (((x) >> kFp32SignIndex) & 1); } /// @ingroup fp32 basic operator /// @brief get exponent of fp16 -inline bool FP32_EXTRAC_EXP(const uint16_t x) { +inline bool Fp32ExtracExp(const uint16_t x) { return (((x)&kFp32ExpMask) >> kFp32ManLen); } /// @ingroup fp32 basic operator /// @brief get mantissa of fp16 -inline uint16_t FP32_EXTRAC_MAN(const uint16_t x) { +inline uint16_t Fp32ExtracMan(const uint16_t x) { return (((x)&kFp32ManMask) | (((((x) >> kFp32ManLen) & kFp32MaxExp) > 0 ? 1 : 0) * kFp32ManHideBit)); } /// @ingroup fp32 basic operator /// @brief constructor of fp32 from sign exponent and mantissa -inline uint16_t FP32_CONSTRUCTOR(const uint16_t s, const uint16_t e, const uint16_t m) { +inline uint16_t Fp32Constructor(const uint16_t s, const uint16_t e, const uint16_t m) { return (((s) << kFp32SignIndex) | ((e) << kFp32ManLen) | ((m) & kFp32MaxMan)); } /// @ingroup fp64 basic parameter @@ -279,12 +279,12 @@ constexpr uint64_t kFp64MaxExp = 0x07FF; constexpr uint64_t kFp64MaxMan = 0xFFFFFFFFFFFLLu; /// @ingroup fp64 special value judgment /// @brief whether a fp64 is NaN -inline bool FP64_IS_NAN(const uint16_t x) { +inline bool Fp64IsNan(const uint16_t x) { return ((((x) & kFp64ExpMask) == kFp64ExpMask) && ((x) & kFp64ManMask)); } /// @ingroup fp64 special value judgment /// @brief whether a fp64 is infinite -inline bool FP64_IS_INF(const uint16_t x) { +inline bool Fp64IsInf(const uint16_t x) { return ((((x) & kFp64ExpMask) == kFp64ExpMask) && (!((x) & kFp64ManMask))); } /// @ingroup integer special value judgment From ba7e6dfcdf50d46a4833f34a2885d15378f92b06 Mon Sep 17 00:00:00 2001 From: songmingyang Date: Tue, 30 Aug 2022 17:48:30 +0800 Subject: [PATCH 17/17] cleancode --- parser/common/parser_fp16_t.cc | 4 ++-- parser/common/parser_fp16_t.h | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/parser/common/parser_fp16_t.cc b/parser/common/parser_fp16_t.cc index 3ce5c6b..fd94a9e 100644 --- a/parser/common/parser_fp16_t.cc +++ b/parser/common/parser_fp16_t.cc @@ -978,7 +978,7 @@ static void SetValByUint16Val(const uint16_t &input_val, const uint16_t &sign, u } } else { e_ret = static_cast(kFp16ExpBias); - m_tmp = m_tmp << (kManBitLength - len); + m_tmp = m_tmp << static_cast(kManBitLength - len); e_ret = e_ret + (len - 1); } auto m_ret = static_cast(m_tmp); @@ -1116,7 +1116,7 @@ fp16_t &fp16_t::operator=(const uint32_t &ui_val) { uint32_t m_min = kFp16ManHideBit; uint32_t m_max = m_min << 1; uint16_t len = static_cast(GetManBitLength(m_tmp)); - if (len > kDim11) { + if (len > static_cast<>kDim11) { e_ret = kFp16ExpBias + kFp16ManLen; uint32_t m_trunc = 0; uint32_t trunc_mask = 1; diff --git a/parser/common/parser_fp16_t.h b/parser/common/parser_fp16_t.h index e8722f9..2f970b9 100644 --- a/parser/common/parser_fp16_t.h +++ b/parser/common/parser_fp16_t.h @@ -93,8 +93,8 @@ using BitShift = enum { /// @brief fp16 exponent bias constexpr uint16_t kFp16ExpBias = 15U; /// @ingroup fp16 basic parameter -/// @brief the exponent bit length of fp16 is 5 -constexpr uint16_t kFp16ExpLen = 5U; +/// @brief the exponent bit length of fp16 is 10 +constexpr uint16_t kFp16ExpLen = 10U; /// @ingroup fp16 basic parameter /// @brief the mantissa bit length of fp16 is 10 constexpr uint16_t kFp16ManLen = 10U; @@ -134,17 +134,17 @@ constexpr uint16_t kFp16MaxMan = 0x03FF; /// @ingroup fp16 basic operator /// @brief get sign of fp16 inline uint16_t Fp16ExtracSign(const uint16_t x) { - return (((x) >> 15) & 1); + return (((x) >> kFp16SignIndex) & 1); } /// @ingroup fp16 basic operator /// @brief get exponent of fp16 inline uint16_t Fp16ExtracExp(const uint16_t x) { - return (((x) >> 10) & kFp16MaxExp); + return (((x) >> kFp16ExpLen) & kFp16MaxExp); } /// @ingroup fp16 basic operator /// @brief get mantissa of fp16 inline uint16_t Fp16ExtracMan(const uint16_t x) { - return ((((x) >> 0) & 0x3FF) | (((((x) >> 10) & 0x1F) > 0 ? 1 : 0) * 0x400)); + return ((((x) >> 0) & 0x3FF) | (((((x) >> kFp16ManLen) & 0x1F) > 0 ? 1 : 0) * 0x400)); } /// @ingroup fp16 basic operator /// @brief constructor of fp16 from sign exponent and mantissa