From 1b54938f3ff2cc39da716c351b9844af5ae50451 Mon Sep 17 00:00:00 2001 From: blee-bot <93bslee@gmail.com> Date: Mon, 4 Nov 2024 11:09:26 +0900 Subject: [PATCH 1/5] This commit introduce hessian observer. This commit introduce hessian observer. ONE-DCO-1.0-Signed-off-by: Banseok Lee --- .../include/record-hessian/HessianObserver.h | 45 +++++++++++++++++++ .../record-hessian/src/HessianObserver.cpp | 44 ++++++++++++++++++ 2 files changed, 89 insertions(+) create mode 100644 compiler/record-hessian/include/record-hessian/HessianObserver.h create mode 100644 compiler/record-hessian/src/HessianObserver.cpp diff --git a/compiler/record-hessian/include/record-hessian/HessianObserver.h b/compiler/record-hessian/include/record-hessian/HessianObserver.h new file mode 100644 index 00000000000..46a39b28b46 --- /dev/null +++ b/compiler/record-hessian/include/record-hessian/HessianObserver.h @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2024 Samsung Electronics Co., Ltd. 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __RECORD_HESSIAN_HESSIANOBSERVER_H__ +#define __RECORD_HESSIAN_HESSIANOBSERVER_H__ + +#include "record-hessian/HessianComputer.h" + +#include +#include +#include + +namespace record_hessian +{ + +class HessianObserver : public luci_interpreter::ExecutionObserver +{ +public: + HessianObserver() = default; + + void postTensorWrite(const luci::CircleNode *node, + const luci_interpreter::Tensor *tensor) override; + + std::unique_ptr hessianData() { return _hessian_computer.getMap(); } + +private: + HessianComputer _hessian_computer; +}; + +} // namespace record_hessian + +#endif // __RECORD_HESSIAN_HESSIANOBSERVER_H__ diff --git a/compiler/record-hessian/src/HessianObserver.cpp b/compiler/record-hessian/src/HessianObserver.cpp new file mode 100644 index 00000000000..4740024dea5 --- /dev/null +++ b/compiler/record-hessian/src/HessianObserver.cpp @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024 Samsung Electronics Co., Ltd. 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "record-hessian/HessianObserver.h" + +#include +#include + +using DataType = luci_interpreter::DataType; + +namespace record_hessian +{ + +void HessianObserver::postTensorWrite(const luci::CircleNode *node, + const luci_interpreter::Tensor *tensor) +{ + + auto node_outputs = loco::succs(node); + for (auto node : node_outputs) + { + auto _node = dynamic_cast(node); + // TODO : ADD TCONV/DepthCONV cases + if (_node->opcode() == luci::CircleOpcode::FULLY_CONNECTED || + _node->opcode() == luci::CircleOpcode::CONV_2D) + { + _hessian_computer.recordHessian(_node, tensor); + } + } +} + +} // namespace record_hessian From 4ff49860a965ff8bcc66895c52d12725b4b4d8d3 Mon Sep 17 00:00:00 2001 From: blee-bot <93bslee@gmail.com> Date: Mon, 4 Nov 2024 15:49:05 +0900 Subject: [PATCH 2/5] Change local variable naming and remove redundant includes. Change local variable naming and remove redundant includes. ONE-DCO-1.0-Signed-off-by: Banseok Lee --- .../include/record-hessian/HessianObserver.h | 4 ---- compiler/record-hessian/src/HessianObserver.cpp | 14 ++++++-------- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/compiler/record-hessian/include/record-hessian/HessianObserver.h b/compiler/record-hessian/include/record-hessian/HessianObserver.h index 46a39b28b46..6bd9abb3102 100644 --- a/compiler/record-hessian/include/record-hessian/HessianObserver.h +++ b/compiler/record-hessian/include/record-hessian/HessianObserver.h @@ -19,10 +19,6 @@ #include "record-hessian/HessianComputer.h" -#include -#include -#include - namespace record_hessian { diff --git a/compiler/record-hessian/src/HessianObserver.cpp b/compiler/record-hessian/src/HessianObserver.cpp index 4740024dea5..be481969889 100644 --- a/compiler/record-hessian/src/HessianObserver.cpp +++ b/compiler/record-hessian/src/HessianObserver.cpp @@ -16,9 +16,6 @@ #include "record-hessian/HessianObserver.h" -#include -#include - using DataType = luci_interpreter::DataType; namespace record_hessian @@ -29,14 +26,15 @@ void HessianObserver::postTensorWrite(const luci::CircleNode *node, { auto node_outputs = loco::succs(node); - for (auto node : node_outputs) + for (auto node_output : node_outputs) { - auto _node = dynamic_cast(node); + auto cur_node = dynamic_cast(node_output); + assert(cur_node != nullptr); // TODO : ADD TCONV/DepthCONV cases - if (_node->opcode() == luci::CircleOpcode::FULLY_CONNECTED || - _node->opcode() == luci::CircleOpcode::CONV_2D) + if (cur_node->opcode() == luci::CircleOpcode::FULLY_CONNECTED || + cur_node->opcode() == luci::CircleOpcode::CONV_2D) { - _hessian_computer.recordHessian(_node, tensor); + _hessian_computer.recordHessian(cur_node, tensor); } } } From 99ea1dfd38372a86ebccf2fa155f505f2f6d2898 Mon Sep 17 00:00:00 2001 From: blee-bot <93bslee@gmail.com> Date: Mon, 4 Nov 2024 16:23:14 +0900 Subject: [PATCH 3/5] Add header for unique_ptr, change assert to throw. Add header for unique_ptr, change assert to throw. ONE-DCO-1.0-Signed-off-by: Banseok Lee --- .../record-hessian/include/record-hessian/HessianObserver.h | 2 ++ compiler/record-hessian/src/HessianObserver.cpp | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/compiler/record-hessian/include/record-hessian/HessianObserver.h b/compiler/record-hessian/include/record-hessian/HessianObserver.h index 6bd9abb3102..bc3159474b1 100644 --- a/compiler/record-hessian/include/record-hessian/HessianObserver.h +++ b/compiler/record-hessian/include/record-hessian/HessianObserver.h @@ -19,6 +19,8 @@ #include "record-hessian/HessianComputer.h" +#include + namespace record_hessian { diff --git a/compiler/record-hessian/src/HessianObserver.cpp b/compiler/record-hessian/src/HessianObserver.cpp index be481969889..6278e45fc2f 100644 --- a/compiler/record-hessian/src/HessianObserver.cpp +++ b/compiler/record-hessian/src/HessianObserver.cpp @@ -29,7 +29,10 @@ void HessianObserver::postTensorWrite(const luci::CircleNode *node, for (auto node_output : node_outputs) { auto cur_node = dynamic_cast(node_output); - assert(cur_node != nullptr); + if (cur_node == nullptr) + { + throw std::runtime_error("Record Hessian: Node shouldn't be null."); + } // TODO : ADD TCONV/DepthCONV cases if (cur_node->opcode() == luci::CircleOpcode::FULLY_CONNECTED || cur_node->opcode() == luci::CircleOpcode::CONV_2D) From 2ec87c63ba97f84f169278be03c0a189ed8ec0ba Mon Sep 17 00:00:00 2001 From: blee-bot <93bslee@gmail.com> Date: Mon, 4 Nov 2024 16:30:22 +0900 Subject: [PATCH 4/5] Remove useless line, and add more headers. Remove useless line, and add more headers. ONE-DCO-1.0-Signed-off-by: Banseok Lee --- .../record-hessian/include/record-hessian/HessianObserver.h | 3 +++ compiler/record-hessian/src/HessianObserver.cpp | 4 +--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/compiler/record-hessian/include/record-hessian/HessianObserver.h b/compiler/record-hessian/include/record-hessian/HessianObserver.h index bc3159474b1..283d9e2a377 100644 --- a/compiler/record-hessian/include/record-hessian/HessianObserver.h +++ b/compiler/record-hessian/include/record-hessian/HessianObserver.h @@ -19,6 +19,9 @@ #include "record-hessian/HessianComputer.h" +#include +#include + #include namespace record_hessian diff --git a/compiler/record-hessian/src/HessianObserver.cpp b/compiler/record-hessian/src/HessianObserver.cpp index 6278e45fc2f..58bbf0e8da5 100644 --- a/compiler/record-hessian/src/HessianObserver.cpp +++ b/compiler/record-hessian/src/HessianObserver.cpp @@ -16,8 +16,6 @@ #include "record-hessian/HessianObserver.h" -using DataType = luci_interpreter::DataType; - namespace record_hessian { @@ -31,7 +29,7 @@ void HessianObserver::postTensorWrite(const luci::CircleNode *node, auto cur_node = dynamic_cast(node_output); if (cur_node == nullptr) { - throw std::runtime_error("Record Hessian: Node shouldn't be null."); + throw std::runtime_error("Record Hessian: node output shouldn't be null."); } // TODO : ADD TCONV/DepthCONV cases if (cur_node->opcode() == luci::CircleOpcode::FULLY_CONNECTED || From cb52002daab694d74e8665a9d8fdd323708b4f99 Mon Sep 17 00:00:00 2001 From: blee-bot <93bslee@gmail.com> Date: Mon, 4 Nov 2024 16:41:45 +0900 Subject: [PATCH 5/5] Add assertion check for node and tensor pointer. Add assertion check for node and tensor pointer. ONE-DCO-1.0-Signed-off-by: Banseok Lee --- compiler/record-hessian/src/HessianObserver.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/compiler/record-hessian/src/HessianObserver.cpp b/compiler/record-hessian/src/HessianObserver.cpp index 58bbf0e8da5..aef981b0d51 100644 --- a/compiler/record-hessian/src/HessianObserver.cpp +++ b/compiler/record-hessian/src/HessianObserver.cpp @@ -22,6 +22,8 @@ namespace record_hessian void HessianObserver::postTensorWrite(const luci::CircleNode *node, const luci_interpreter::Tensor *tensor) { + assert(node != nullptr); + assert(tensor != nullptr); auto node_outputs = loco::succs(node); for (auto node_output : node_outputs)