From 80af9b0e2fca2059de14441584544f7e4900af8e Mon Sep 17 00:00:00 2001 From: blee-bot <93bslee@gmail.com> Date: Mon, 25 Nov 2024 13:56:49 +0900 Subject: [PATCH 1/9] [record-hessian] This commit introduce record hessian. This commit introduce record hessian. ONE-DCO-1.0-Signed-off-by: Banseok Lee --- .../include/record-hessian/RecordHessian.h | 53 +++++++++ compiler/record-hessian/src/RecordHessian.cpp | 110 ++++++++++++++++++ 2 files changed, 163 insertions(+) create mode 100644 compiler/record-hessian/include/record-hessian/RecordHessian.h create mode 100644 compiler/record-hessian/src/RecordHessian.cpp diff --git a/compiler/record-hessian/include/record-hessian/RecordHessian.h b/compiler/record-hessian/include/record-hessian/RecordHessian.h new file mode 100644 index 00000000000..b3a1ab84849 --- /dev/null +++ b/compiler/record-hessian/include/record-hessian/RecordHessian.h @@ -0,0 +1,53 @@ +/* + * 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_H__ +#define __RECORD_HESSIAN_H__ + +#include "record-hessian/HessianObserver.h" + +#include +#include + +namespace record_hessian +{ + +class RecordHessian +{ +public: + explicit RecordHessian() {} + + ~RecordHessian() = default; + + void initialize(luci::Module *module); + // TODO Refactor profile functions + std::unique_ptr profileData(const std::string &input_data_path); + +private: + luci_interpreter::Interpreter *getInterpreter() const { return _interpreter.get(); } + + // Never return nullptr + HessianObserver *getObserver() const { return _observer.get(); } + + luci::Module *_module; + + std::unique_ptr _interpreter; + std::unique_ptr _observer; +}; + +} // namespace record_hessian + +#endif // __RECORD_HESSIAN_H__ diff --git a/compiler/record-hessian/src/RecordHessian.cpp b/compiler/record-hessian/src/RecordHessian.cpp new file mode 100644 index 00000000000..fccf012322f --- /dev/null +++ b/compiler/record-hessian/src/RecordHessian.cpp @@ -0,0 +1,110 @@ +/* + * 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/RecordHessian.h" +#include "record-hessian/HessianObserver.h" + +#include + +#include + +using Shape = std::vector; +using DataType = loco::DataType; + +namespace +{ + +// Return a string with no whitespace from both ends +std::string trim(std::string s) +{ + // Trim left side + s.erase(s.begin(), + std::find_if(s.begin(), s.end(), [](unsigned char ch) { return !std::isspace(ch); })); + + // Trim right side + s.erase( + std::find_if(s.rbegin(), s.rend(), [](unsigned char ch) { return !std::isspace(ch); }).base(), + s.end()); + + return s; +} + +uint32_t numElements(const luci::CircleNode *node) +{ + uint32_t num_elements = 1; + for (uint32_t i = 0; i < node->rank(); i++) + num_elements *= node->dim(i).value(); + + return num_elements; +} + +void checkInputDimension(const luci::CircleInput *input) +{ + for (uint32_t i = 0; i < input->rank(); i++) + if (!input->dim(i).known()) + throw std::runtime_error("RecordHessian: " + input->name() + " has unknown dimension"); + + if (numElements(input) == 0) + throw std::runtime_error("RecordHessian: " + input->name() + " is a zero-sized input"); +} + +/** + * @brief getTensorSize will return size in bytes + */ +template size_t getTensorSize(const NodeT *node) +{ + uint32_t tensor_size = luci::size(node->dtype()); + for (uint32_t i = 0; i < node->rank(); ++i) + tensor_size *= node->dim(i).value(); + return tensor_size; +} + +/** + * @brief verifyTypeShape checks the type and the shape of CircleInput + * This throws an exception if type or shape does not match + */ +void verifyTypeShape(const luci::CircleInput *input_node, const DataType &dtype, const Shape &shape) +{ + // Type check + if (dtype != input_node->dtype()) + throw std::runtime_error("RecordHessian: Wrong input type."); + + if (shape.size() != input_node->rank()) + throw std::runtime_error("RecordHessian: Input rank mismatch."); + + for (uint32_t i = 0; i < shape.size(); i++) + { + if (not(shape.at(i) == input_node->dim(i))) + throw std::runtime_error("RecordHessian: Input shape mismatch."); + } +} + +} // namespace + +namespace record_hessian +{ + +void RecordHessian::initialize(luci::Module *module) +{ + // To Be Implemented +} + +std::unique_ptr RecordHessian::profileData(const std::string &input_data_path) +{ + // To Be Implemented +} + +} // namespace record_hessian From 2c611b9cf9b51ae131eaa6c9dc20ba1d0341f550 Mon Sep 17 00:00:00 2001 From: blee-bot <93bslee@gmail.com> Date: Mon, 25 Nov 2024 13:56:49 +0900 Subject: [PATCH 2/9] Delete unused variables and lines. Delete unused variables and lines. ONE-DCO-1.0-Signed-off-by: Banseok Lee --- .../include/record-hessian/RecordHessian.h | 10 +- compiler/record-hessian/src/RecordHessian.cpp | 94 +++++++++++++++---- 2 files changed, 78 insertions(+), 26 deletions(-) diff --git a/compiler/record-hessian/include/record-hessian/RecordHessian.h b/compiler/record-hessian/include/record-hessian/RecordHessian.h index b3a1ab84849..6d51b2184b3 100644 --- a/compiler/record-hessian/include/record-hessian/RecordHessian.h +++ b/compiler/record-hessian/include/record-hessian/RecordHessian.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __RECORD_HESSIAN_H__ -#define __RECORD_HESSIAN_H__ +#ifndef __RECORD_HESSIAN_RECORD_HESSIAN_H__ +#define __RECORD_HESSIAN_RECORD_HESSIAN_H__ #include "record-hessian/HessianObserver.h" @@ -28,9 +28,7 @@ namespace record_hessian class RecordHessian { public: - explicit RecordHessian() {} - - ~RecordHessian() = default; + RecordHessian() {} void initialize(luci::Module *module); // TODO Refactor profile functions @@ -42,7 +40,7 @@ class RecordHessian // Never return nullptr HessianObserver *getObserver() const { return _observer.get(); } - luci::Module *_module; + luci::Module *_module = nullptr; std::unique_ptr _interpreter; std::unique_ptr _observer; diff --git a/compiler/record-hessian/src/RecordHessian.cpp b/compiler/record-hessian/src/RecordHessian.cpp index fccf012322f..bfeb4331568 100644 --- a/compiler/record-hessian/src/RecordHessian.cpp +++ b/compiler/record-hessian/src/RecordHessian.cpp @@ -22,26 +22,10 @@ #include using Shape = std::vector; -using DataType = loco::DataType; namespace { -// Return a string with no whitespace from both ends -std::string trim(std::string s) -{ - // Trim left side - s.erase(s.begin(), - std::find_if(s.begin(), s.end(), [](unsigned char ch) { return !std::isspace(ch); })); - - // Trim right side - s.erase( - std::find_if(s.rbegin(), s.rend(), [](unsigned char ch) { return !std::isspace(ch); }).base(), - s.end()); - - return s; -} - uint32_t numElements(const luci::CircleNode *node) { uint32_t num_elements = 1; @@ -76,9 +60,9 @@ template size_t getTensorSize(const NodeT *node) * @brief verifyTypeShape checks the type and the shape of CircleInput * This throws an exception if type or shape does not match */ -void verifyTypeShape(const luci::CircleInput *input_node, const DataType &dtype, const Shape &shape) +void verifyTypeShape(const luci::CircleInput *input_node, const loco::DataType &dtype, + const Shape &shape) { - // Type check if (dtype != input_node->dtype()) throw std::runtime_error("RecordHessian: Wrong input type."); @@ -99,12 +83,82 @@ namespace record_hessian void RecordHessian::initialize(luci::Module *module) { - // To Be Implemented + // Create and initialize interpreters and observers + + _module = module; + + auto interpreter = std::make_unique(module); + auto observer = std::make_unique(); + + interpreter->attachObserver(observer.get()); + + _observer = std::move(observer); + _interpreter = std::move(interpreter); } std::unique_ptr RecordHessian::profileData(const std::string &input_data_path) { - // To Be Implemented + try + { + dio::hdf5::HDF5Importer importer(input_data_path); + importer.importGroup("value"); + + bool is_raw_data = importer.isRawData(); + + const auto num_records = importer.numData(); + if (num_records == 0) + throw std::runtime_error("RecordHessian: The input data file does not contain any record."); + + const auto input_nodes = loco::input_nodes(_module->graph()); + const auto num_inputs = input_nodes.size(); + + for (int32_t record_idx = 0; record_idx < num_records; record_idx++) + { + if (num_inputs != static_cast(importer.numInputs(record_idx))) + throw std::runtime_error("RecordHessian: Wrong number of inputs."); + + std::cout << "Recording " << record_idx << "'th data for hessian." << std::endl; + + for (uint32_t input_idx = 0; input_idx < num_inputs; input_idx++) + { + const auto *input_node = loco::must_cast(input_nodes[input_idx]); + assert(input_node->index() == input_idx); + checkInputDimension(input_node); + std::vector input_data(getTensorSize(input_node)); + + if (!is_raw_data) + { + loco::DataType dtype; + Shape shape; + importer.readTensor(record_idx, input_idx, &dtype, &shape, input_data.data(), + input_data.size()); + + // Check the type and the shape of the input data is valid + verifyTypeShape(input_node, dtype, shape); + } + else + { + // Skip type/shape check for raw data + importer.readTensor(record_idx, input_idx, input_data.data(), input_data.size()); + } + + // TODO: Input data is copied twice (file -> buffer (input_data) -> interpreter inputs) + // We can redcue the copy by directly writing data from file to interpreter inputs + getInterpreter()->writeInputTensor(input_node, input_data.data(), input_data.size()); + } + + getInterpreter()->interpret(); + } + + std::cout << "Recording finished. Number of recorded data: " << num_records << std::endl; + } + catch (const H5::Exception &e) + { + H5::Exception::printErrorStack(); + throw std::runtime_error("RecordHessian: HDF5 error occurred."); + } + + return getObserver()->hessianData(); } } // namespace record_hessian From 92d5ab03a9ab6afb3697e8c63fbc5832f25cb4b2 Mon Sep 17 00:00:00 2001 From: blee-bot <93bslee@gmail.com> Date: Mon, 25 Nov 2024 13:56:49 +0900 Subject: [PATCH 3/9] Apply feed back, make comment more precise. Apply feed back, make comment more precise. ONE-DCO-1.0-Signed-off-by: Banseok Lee --- compiler/record-hessian/include/record-hessian/RecordHessian.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/record-hessian/include/record-hessian/RecordHessian.h b/compiler/record-hessian/include/record-hessian/RecordHessian.h index 6d51b2184b3..31e2388d23c 100644 --- a/compiler/record-hessian/include/record-hessian/RecordHessian.h +++ b/compiler/record-hessian/include/record-hessian/RecordHessian.h @@ -48,4 +48,4 @@ class RecordHessian } // namespace record_hessian -#endif // __RECORD_HESSIAN_H__ +#endif // __RECORD_HESSIAN_RECORD_HESSIAN_H__ From adaf8bab843ef69cdeddf6448599efb03c0a2d65 Mon Sep 17 00:00:00 2001 From: blee-bot <93bslee@gmail.com> Date: Mon, 25 Nov 2024 13:56:49 +0900 Subject: [PATCH 4/9] Split code into small parts. Add maybe_unused mark to avoid compile error. ONE-DCO-1.0-Signed-off-by: Banseok Lee --- compiler/record-hessian/src/RecordHessian.cpp | 82 +------------------ 1 file changed, 4 insertions(+), 78 deletions(-) diff --git a/compiler/record-hessian/src/RecordHessian.cpp b/compiler/record-hessian/src/RecordHessian.cpp index bfeb4331568..32135630489 100644 --- a/compiler/record-hessian/src/RecordHessian.cpp +++ b/compiler/record-hessian/src/RecordHessian.cpp @@ -35,7 +35,7 @@ uint32_t numElements(const luci::CircleNode *node) return num_elements; } -void checkInputDimension(const luci::CircleInput *input) +[[maybe_unused]] void checkInputDimension(const luci::CircleInput *input) { for (uint32_t i = 0; i < input->rank(); i++) if (!input->dim(i).known()) @@ -60,7 +60,7 @@ template size_t getTensorSize(const NodeT *node) * @brief verifyTypeShape checks the type and the shape of CircleInput * This throws an exception if type or shape does not match */ -void verifyTypeShape(const luci::CircleInput *input_node, const loco::DataType &dtype, +[[maybe_unused]] void verifyTypeShape(const luci::CircleInput *input_node, const loco::DataType &dtype, const Shape &shape) { if (dtype != input_node->dtype()) @@ -81,84 +81,10 @@ void verifyTypeShape(const luci::CircleInput *input_node, const loco::DataType & namespace record_hessian { -void RecordHessian::initialize(luci::Module *module) -{ - // Create and initialize interpreters and observers - - _module = module; - - auto interpreter = std::make_unique(module); - auto observer = std::make_unique(); +// void RecordHessian::initialize(luci::Module *module); // To Be Implemented - interpreter->attachObserver(observer.get()); - _observer = std::move(observer); - _interpreter = std::move(interpreter); -} +// std::unique_ptr RecordHessian::profileData(const std::string &input_data_path); // To Be Implemented -std::unique_ptr RecordHessian::profileData(const std::string &input_data_path) -{ - try - { - dio::hdf5::HDF5Importer importer(input_data_path); - importer.importGroup("value"); - - bool is_raw_data = importer.isRawData(); - - const auto num_records = importer.numData(); - if (num_records == 0) - throw std::runtime_error("RecordHessian: The input data file does not contain any record."); - - const auto input_nodes = loco::input_nodes(_module->graph()); - const auto num_inputs = input_nodes.size(); - - for (int32_t record_idx = 0; record_idx < num_records; record_idx++) - { - if (num_inputs != static_cast(importer.numInputs(record_idx))) - throw std::runtime_error("RecordHessian: Wrong number of inputs."); - - std::cout << "Recording " << record_idx << "'th data for hessian." << std::endl; - - for (uint32_t input_idx = 0; input_idx < num_inputs; input_idx++) - { - const auto *input_node = loco::must_cast(input_nodes[input_idx]); - assert(input_node->index() == input_idx); - checkInputDimension(input_node); - std::vector input_data(getTensorSize(input_node)); - - if (!is_raw_data) - { - loco::DataType dtype; - Shape shape; - importer.readTensor(record_idx, input_idx, &dtype, &shape, input_data.data(), - input_data.size()); - - // Check the type and the shape of the input data is valid - verifyTypeShape(input_node, dtype, shape); - } - else - { - // Skip type/shape check for raw data - importer.readTensor(record_idx, input_idx, input_data.data(), input_data.size()); - } - - // TODO: Input data is copied twice (file -> buffer (input_data) -> interpreter inputs) - // We can redcue the copy by directly writing data from file to interpreter inputs - getInterpreter()->writeInputTensor(input_node, input_data.data(), input_data.size()); - } - - getInterpreter()->interpret(); - } - - std::cout << "Recording finished. Number of recorded data: " << num_records << std::endl; - } - catch (const H5::Exception &e) - { - H5::Exception::printErrorStack(); - throw std::runtime_error("RecordHessian: HDF5 error occurred."); - } - - return getObserver()->hessianData(); -} } // namespace record_hessian From 0cb4404564fe4acad216a42cb0639c57676cf41b Mon Sep 17 00:00:00 2001 From: blee-bot <93bslee@gmail.com> Date: Mon, 25 Nov 2024 13:56:49 +0900 Subject: [PATCH 5/9] Fix formatting error due to comments. Fix formatting error due to comments. ONE-DCO-1.0-Signed-off-by: Banseok Lee --- compiler/record-hessian/src/RecordHessian.cpp | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/compiler/record-hessian/src/RecordHessian.cpp b/compiler/record-hessian/src/RecordHessian.cpp index 32135630489..616109c764c 100644 --- a/compiler/record-hessian/src/RecordHessian.cpp +++ b/compiler/record-hessian/src/RecordHessian.cpp @@ -78,13 +78,8 @@ template size_t getTensorSize(const NodeT *node) } // namespace -namespace record_hessian -{ - -// void RecordHessian::initialize(luci::Module *module); // To Be Implemented - - -// std::unique_ptr RecordHessian::profileData(const std::string &input_data_path); // To Be Implemented - - -} // namespace record_hessian +// namespace record_hessian +// { +// // void RecordHessian::initialize(luci::Module *module); // To Be Implemented +// // std::unique_ptr RecordHessian::profileData(const std::string &input_data_path); // To Be Implemented +// } // namespace record_hessian From 361f2e9bc7349d7ca387c06c800ee75eb5a8bd9f Mon Sep 17 00:00:00 2001 From: blee-bot <93bslee@gmail.com> Date: Mon, 25 Nov 2024 14:18:04 +0900 Subject: [PATCH 6/9] Fix formatting error with nnas_format. Fix formatting error with nnas_format. ONE-DCO-1.0-Signed-off-by: Banseok Lee --- compiler/record-hessian/src/RecordHessian.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/compiler/record-hessian/src/RecordHessian.cpp b/compiler/record-hessian/src/RecordHessian.cpp index 616109c764c..947dd6c4daf 100644 --- a/compiler/record-hessian/src/RecordHessian.cpp +++ b/compiler/record-hessian/src/RecordHessian.cpp @@ -60,8 +60,8 @@ template size_t getTensorSize(const NodeT *node) * @brief verifyTypeShape checks the type and the shape of CircleInput * This throws an exception if type or shape does not match */ -[[maybe_unused]] void verifyTypeShape(const luci::CircleInput *input_node, const loco::DataType &dtype, - const Shape &shape) +[[maybe_unused]] void verifyTypeShape(const luci::CircleInput *input_node, + const loco::DataType &dtype, const Shape &shape) { if (dtype != input_node->dtype()) throw std::runtime_error("RecordHessian: Wrong input type."); @@ -80,6 +80,6 @@ template size_t getTensorSize(const NodeT *node) // namespace record_hessian // { -// // void RecordHessian::initialize(luci::Module *module); // To Be Implemented -// // std::unique_ptr RecordHessian::profileData(const std::string &input_data_path); // To Be Implemented -// } // namespace record_hessian +// void RecordHessian::initialize(luci::Module *module); // To Be Implemented +// std::unique_ptr RecordHessian::profileData(const std::string &input_data_path); To Be +// Implemented } // namespace record_hessian From 025d195b9e96f38e28950eeaf477f7640e72332a Mon Sep 17 00:00:00 2001 From: blee-bot <93bslee@gmail.com> Date: Mon, 25 Nov 2024 15:15:59 +0900 Subject: [PATCH 7/9] Remove useless headers and add comments Remove useless headers and add comments ONE-DCO-1.0-Signed-off-by: Banseok Lee --- .../record-hessian/include/record-hessian/RecordHessian.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/compiler/record-hessian/include/record-hessian/RecordHessian.h b/compiler/record-hessian/include/record-hessian/RecordHessian.h index 31e2388d23c..8eb2ce37470 100644 --- a/compiler/record-hessian/include/record-hessian/RecordHessian.h +++ b/compiler/record-hessian/include/record-hessian/RecordHessian.h @@ -30,9 +30,9 @@ class RecordHessian public: RecordHessian() {} - void initialize(luci::Module *module); - // TODO Refactor profile functions - std::unique_ptr profileData(const std::string &input_data_path); + // void initialize(luci::Module *module); // To be implemented + // std::unique_ptr profileData(const std::string &input_data_path); // To be + // implemented private: luci_interpreter::Interpreter *getInterpreter() const { return _interpreter.get(); } From 90a69b6e24ba53a5c6be2beb0ca0f4817556f5d2 Mon Sep 17 00:00:00 2001 From: blee-bot <93bslee@gmail.com> Date: Wed, 11 Dec 2024 13:23:45 +0900 Subject: [PATCH 8/9] Update code commits to add initialize function first. Update code commits to add initialize function first. ONE-DCO-1.0-Signed-off-by: Banseok Lee --- .../include/record-hessian/RecordHessian.h | 5 +- compiler/record-hessian/src/RecordHessian.cpp | 69 ++++++------------- 2 files changed, 23 insertions(+), 51 deletions(-) diff --git a/compiler/record-hessian/include/record-hessian/RecordHessian.h b/compiler/record-hessian/include/record-hessian/RecordHessian.h index 8eb2ce37470..c29dd0ce199 100644 --- a/compiler/record-hessian/include/record-hessian/RecordHessian.h +++ b/compiler/record-hessian/include/record-hessian/RecordHessian.h @@ -30,9 +30,8 @@ class RecordHessian public: RecordHessian() {} - // void initialize(luci::Module *module); // To be implemented - // std::unique_ptr profileData(const std::string &input_data_path); // To be - // implemented + void initialize(luci::Module *module); + std::unique_ptr profileData(const std::string &input_data_path); private: luci_interpreter::Interpreter *getInterpreter() const { return _interpreter.get(); } diff --git a/compiler/record-hessian/src/RecordHessian.cpp b/compiler/record-hessian/src/RecordHessian.cpp index 947dd6c4daf..4e9a42aa479 100644 --- a/compiler/record-hessian/src/RecordHessian.cpp +++ b/compiler/record-hessian/src/RecordHessian.cpp @@ -23,63 +23,36 @@ using Shape = std::vector; -namespace +namespace record_hessian { - -uint32_t numElements(const luci::CircleNode *node) +void RecordHessian::initialize(luci::Module *module) { - uint32_t num_elements = 1; - for (uint32_t i = 0; i < node->rank(); i++) - num_elements *= node->dim(i).value(); + // Create and initialize interpreters and observers - return num_elements; -} + _module = module; -[[maybe_unused]] void checkInputDimension(const luci::CircleInput *input) -{ - for (uint32_t i = 0; i < input->rank(); i++) - if (!input->dim(i).known()) - throw std::runtime_error("RecordHessian: " + input->name() + " has unknown dimension"); + auto interpreter = std::make_unique(module); + auto observer = std::make_unique(); - if (numElements(input) == 0) - throw std::runtime_error("RecordHessian: " + input->name() + " is a zero-sized input"); -} + interpreter->attachObserver(observer.get()); -/** - * @brief getTensorSize will return size in bytes - */ -template size_t getTensorSize(const NodeT *node) -{ - uint32_t tensor_size = luci::size(node->dtype()); - for (uint32_t i = 0; i < node->rank(); ++i) - tensor_size *= node->dim(i).value(); - return tensor_size; + _observer = std::move(observer); + _interpreter = std::move(interpreter); } - -/** - * @brief verifyTypeShape checks the type and the shape of CircleInput - * This throws an exception if type or shape does not match - */ -[[maybe_unused]] void verifyTypeShape(const luci::CircleInput *input_node, - const loco::DataType &dtype, const Shape &shape) +std::unique_ptr RecordHessian::profileData(const std::string &input_data_path) { - if (dtype != input_node->dtype()) - throw std::runtime_error("RecordHessian: Wrong input type."); - - if (shape.size() != input_node->rank()) - throw std::runtime_error("RecordHessian: Input rank mismatch."); - - for (uint32_t i = 0; i < shape.size(); i++) + try { - if (not(shape.at(i) == input_node->dim(i))) - throw std::runtime_error("RecordHessian: Input shape mismatch."); + dio::hdf5::HDF5Importer importer(input_data_path); + // To be implemented + } + catch (const H5::Exception &e) + { + H5::Exception::printErrorStack(); + throw std::runtime_error("RecordHessian: HDF5 error occurred."); } -} -} // namespace + return getObserver()->hessianData(); +} -// namespace record_hessian -// { -// void RecordHessian::initialize(luci::Module *module); // To Be Implemented -// std::unique_ptr RecordHessian::profileData(const std::string &input_data_path); To Be -// Implemented } // namespace record_hessian +} // namespace record_hessian From 0027d7ce285958abd0dfa2d34648028108795e44 Mon Sep 17 00:00:00 2001 From: blee-bot <93bslee@gmail.com> Date: Thu, 12 Dec 2024 13:47:19 +0900 Subject: [PATCH 9/9] Remove redundant code lines and add two space. Remove redundant code lines and add two space. ONE-DCO-1.0-Signed-off-by: Banseok Lee --- compiler/record-hessian/src/RecordHessian.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/compiler/record-hessian/src/RecordHessian.cpp b/compiler/record-hessian/src/RecordHessian.cpp index 4e9a42aa479..1ff686b63d7 100644 --- a/compiler/record-hessian/src/RecordHessian.cpp +++ b/compiler/record-hessian/src/RecordHessian.cpp @@ -25,6 +25,7 @@ using Shape = std::vector; namespace record_hessian { + void RecordHessian::initialize(luci::Module *module) { // Create and initialize interpreters and observers @@ -35,10 +36,8 @@ void RecordHessian::initialize(luci::Module *module) auto observer = std::make_unique(); interpreter->attachObserver(observer.get()); - - _observer = std::move(observer); - _interpreter = std::move(interpreter); } + std::unique_ptr RecordHessian::profileData(const std::string &input_data_path) { try