From e3e325faffee3286de64f1dc0ec689e598d52843 Mon Sep 17 00:00:00 2001 From: blee-bot <93bslee@gmail.com> Date: Tue, 5 Nov 2024 09:45:49 +0900 Subject: [PATCH 1/4] [record-hessian] Add linking nncc_common to record-hessian (#14298) This add linking nncc_common in CMakeLists. Fixes errors with strict compilation option. ONE-DCO-1.0-Signed-off-by: Banseok Lee --- compiler/record-hessian/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/compiler/record-hessian/CMakeLists.txt b/compiler/record-hessian/CMakeLists.txt index 75281e6c8cb..6f55911ce17 100644 --- a/compiler/record-hessian/CMakeLists.txt +++ b/compiler/record-hessian/CMakeLists.txt @@ -13,6 +13,7 @@ target_link_libraries(record-hessian luci_export) target_link_libraries(record-hessian luci_interpreter) target_link_libraries(record-hessian luci_log) target_link_libraries(record-hessian dio_hdf5) +target_link_libraries(record-hessian nncc_common) install(TARGETS record-hessian DESTINATION lib) install(DIRECTORY include/ DESTINATION include From 1c97c104417ab49983fa41bab9db2504f4ff1b32 Mon Sep 17 00:00:00 2001 From: blee-bot <93bslee@gmail.com> Date: Tue, 5 Nov 2024 09:46:39 +0900 Subject: [PATCH 2/4] [record-hessian]Fix build errors due to add nncc_common. Fix build errors due to add nncc_common. Change int -> uint32_t. ONE-DCO-1.0-Signed-off-by: Banseok Lee --- .../record-hessian/src/HessianComputer.cpp | 35 +++++++++---------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/compiler/record-hessian/src/HessianComputer.cpp b/compiler/record-hessian/src/HessianComputer.cpp index 6ae36cf0797..097f99bdbd1 100644 --- a/compiler/record-hessian/src/HessianComputer.cpp +++ b/compiler/record-hessian/src/HessianComputer.cpp @@ -37,24 +37,24 @@ void unfold(std::vector &buf, uint32_t input_n, uint32_t input_h, uint32_ if (input_c != kernel_ic) throw std::runtime_error("RecordHessian: Input channels do not match kernel channels."); - int out_height = (input_h - dilation_h * (kernel_h - 1) - 1) / stride_h + 1; - int out_width = (input_w - dilation_w * (kernel_w - 1) - 1) / stride_w + 1; - int patch_size = kernel_h * kernel_w * kernel_ic; + uint32_t out_height = (input_h - dilation_h * (kernel_h - 1) - 1) / stride_h + 1; + uint32_t out_width = (input_w - dilation_w * (kernel_w - 1) - 1) / stride_w + 1; + uint32_t patch_size = kernel_h * kernel_w * kernel_ic; std::vector unfolded_buf(input_n * out_height * out_width * patch_size, 0.0f); - int index = 0; - int in_y, in_x; - for (int n = 0; n < input_n; ++n) + uint32_t index = 0; + uint32_t in_y, in_x; + for (uint32_t n = 0; n < input_n; ++n) { - for (int y = 0; y < out_height; ++y) + for (uint32_t y = 0; y < out_height; ++y) { - for (int x = 0; x < out_width; ++x) + for (uint32_t x = 0; x < out_width; ++x) { - for (int in_c = 0; in_c < input_c; ++in_c) + for (uint32_t in_c = 0; in_c < input_c; ++in_c) { - for (int ky = 0; ky < kernel_h; ++ky) + for (uint32_t ky = 0; ky < kernel_h; ++ky) { - for (int kx = 0; kx < kernel_w; ++kx) + for (uint32_t kx = 0; kx < kernel_w; ++kx) { in_y = y * stride_h + ky * dilation_h; in_x = x * stride_w + kx * dilation_w; @@ -102,12 +102,12 @@ void HessianComputer::recordHessianForFullyConnected(const luci::CircleNode *nod std::vector hessian(size_in_ch * size_in_ch, 0); - for (int i = 0; i < size_in_ch; ++i) + for (uint32_t i = 0; i < size_in_ch; ++i) { - for (int j = 0; j < size_in_ch; ++j) + for (uint32_t j = 0; j < size_in_ch; ++j) { float sum = 0; - for (int k = 0; k < length; ++k) + for (uint32_t k = 0; k < length; ++k) { sum += buf[i + k * size_in_ch] * buf[j + k * size_in_ch]; } @@ -130,7 +130,6 @@ void HessianComputer::recordHessianForConv2D(const luci::CircleNode *node) assert(node_filter->dtype() == loco::DataType::FLOAT32); assert(node_filter->rank() == 4); - uint32_t size_filter = node_filter->size(); uint32_t size_in_ch = node_filter->size() / circle_conv2d->dim(3).value(); @@ -161,12 +160,12 @@ void HessianComputer::recordHessianForConv2D(const luci::CircleNode *node) uint32_t length = buf.size() / size_in_ch; std::vector hessian(size_in_ch * size_in_ch, 0); - for (int i = 0; i < size_in_ch; ++i) + for (uint32_t i = 0; i < size_in_ch; ++i) { - for (int j = 0; j < size_in_ch; ++j) + for (uint32_t j = 0; j < size_in_ch; ++j) { float sum = 0; - for (int k = 0; k < length; ++k) + for (uint32_t k = 0; k < length; ++k) { sum += buf[i + k * size_in_ch] * buf[j + k * size_in_ch]; } From 353c065e75dc354938f5aedbdb6f4793bae53736 Mon Sep 17 00:00:00 2001 From: blee-bot <93bslee@gmail.com> Date: Tue, 5 Nov 2024 17:18:09 +0900 Subject: [PATCH 3/4] [record-hessian]Delete unused variable and argument. Delete unused variable and argument. ONE-DCO-1.0-Signed-off-by: Banseok Lee --- .../include/record-hessian/HessianComputer.h | 3 +-- compiler/record-hessian/src/HessianComputer.cpp | 8 +++----- compiler/record-hessian/src/HessianComputer.test.cpp | 8 ++++---- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/compiler/record-hessian/include/record-hessian/HessianComputer.h b/compiler/record-hessian/include/record-hessian/HessianComputer.h index fc3cdebcb93..cc704d49f71 100644 --- a/compiler/record-hessian/include/record-hessian/HessianComputer.h +++ b/compiler/record-hessian/include/record-hessian/HessianComputer.h @@ -54,8 +54,7 @@ class HessianComputer void unfold(std::vector &buf, uint32_t input_n, uint32_t input_h, uint32_t input_w, uint32_t input_c, uint32_t stride_h, uint32_t stride_w, uint32_t dilation_h, - uint32_t dilation_w, uint32_t kernel_oc, uint32_t kernel_h, uint32_t kernel_w, - uint32_t kernel_ic); + uint32_t dilation_w, uint32_t kernel_h, uint32_t kernel_w, uint32_t kernel_ic); } // namespace record_hessian diff --git a/compiler/record-hessian/src/HessianComputer.cpp b/compiler/record-hessian/src/HessianComputer.cpp index 097f99bdbd1..d19dab1cf7e 100644 --- a/compiler/record-hessian/src/HessianComputer.cpp +++ b/compiler/record-hessian/src/HessianComputer.cpp @@ -28,12 +28,11 @@ namespace record_hessian */ void unfold(std::vector &buf, uint32_t input_n, uint32_t input_h, uint32_t input_w, uint32_t input_c, uint32_t stride_h, uint32_t stride_w, uint32_t dilation_h, - uint32_t dilation_w, uint32_t kernel_oc, uint32_t kernel_h, uint32_t kernel_w, - uint32_t kernel_ic) + uint32_t dilation_w, uint32_t kernel_h, uint32_t kernel_w, uint32_t kernel_ic) { assert(input_n > 0 && input_h > 0 && input_w > 0 && input_c > 0); assert(stride_h > 0 && stride_w > 0); - assert(kernel_oc > 0 && kernel_h > 0 && kernel_w > 0 && kernel_ic > 0); + assert(kernel_h > 0 && kernel_w > 0 && kernel_ic > 0); if (input_c != kernel_ic) throw std::runtime_error("RecordHessian: Input channels do not match kernel channels."); @@ -143,7 +142,6 @@ void HessianComputer::recordHessianForConv2D(const luci::CircleNode *node) uint32_t dilation_h = circle_conv2d->dilation()->h(); uint32_t dilation_w = circle_conv2d->dilation()->w(); - uint32_t kernel_oc = node_filter->dim(0).value(); uint32_t kernel_h = node_filter->dim(1).value(); uint32_t kernel_w = node_filter->dim(2).value(); uint32_t kernel_ic = node_filter->dim(3).value(); @@ -155,7 +153,7 @@ void HessianComputer::recordHessianForConv2D(const luci::CircleNode *node) std::vector buf(data, data + num_elements); unfold(buf, input_n, input_h, input_w, input_c, stride_h, stride_w, dilation_h, dilation_w, - kernel_oc, kernel_h, kernel_w, kernel_ic); + kernel_h, kernel_w, kernel_ic); assert(size_in_ch != 0); uint32_t length = buf.size() / size_in_ch; diff --git a/compiler/record-hessian/src/HessianComputer.test.cpp b/compiler/record-hessian/src/HessianComputer.test.cpp index d64ab99678d..e8be604762f 100644 --- a/compiler/record-hessian/src/HessianComputer.test.cpp +++ b/compiler/record-hessian/src/HessianComputer.test.cpp @@ -87,10 +87,10 @@ TEST(HessianComputerTest, unfoldValidInput) std::vector buf = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0}; uint32_t input_n = 1, input_h = 2, input_w = 2, input_c = 2; uint32_t stride_h = 1, stride_w = 1, dilation_h = 1, dilation_w = 1; - uint32_t kernel_oc = 1, kernel_h = 2, kernel_w = 2, kernel_ic = 2; + uint32_t kernel_h = 2, kernel_w = 2, kernel_ic = 2; unfold(buf, input_n, input_h, input_w, input_c, stride_h, stride_w, dilation_h, dilation_w, - kernel_oc, kernel_h, kernel_w, kernel_ic); + kernel_h, kernel_w, kernel_ic); std::vector expected_output = {1.0, 3.0, 5.0, 7.0, 2.0, 4.0, 6.0, 8.0}; EXPECT_EQ(buf, expected_output); @@ -101,8 +101,8 @@ TEST(HessianComputerTest, unfoldInvalidInput_NEG) std::vector buf = {1.0, 2.0, 3.0, 4.0}; uint32_t input_n = 1, input_h = 2, input_w = 2, input_c = 1; uint32_t stride_h = 1, stride_w = 1, dilation_h = 1, dilation_w = 1; - uint32_t kernel_oc = 1, kernel_h = 2, kernel_w = 2, kernel_ic = 2; + uint32_t kernel_h = 2, kernel_w = 2, kernel_ic = 2; EXPECT_ANY_THROW(unfold(buf, input_n, input_h, input_w, input_c, stride_h, stride_w, dilation_h, - dilation_w, kernel_oc, kernel_h, kernel_w, kernel_ic)); + dilation_w, kernel_h, kernel_w, kernel_ic)); } From af785a3b3962bb3fe39d726a907cda944c769c5e Mon Sep 17 00:00:00 2001 From: blee-bot <93bslee@gmail.com> Date: Wed, 6 Nov 2024 09:26:35 +0900 Subject: [PATCH 4/4] [record-hessian]Fix build errors due to AffineQuantization. Fix build errors due to AffineQuantization. ONE-DCO-1.0-Signed-off-by: Banseok Lee --- compiler/record-hessian/src/HessianComputer.test.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/compiler/record-hessian/src/HessianComputer.test.cpp b/compiler/record-hessian/src/HessianComputer.test.cpp index e8be604762f..1057267c0a4 100644 --- a/compiler/record-hessian/src/HessianComputer.test.cpp +++ b/compiler/record-hessian/src/HessianComputer.test.cpp @@ -33,11 +33,11 @@ TEST(HessianComputerTest, recordHessianValidInput) luci_interpreter::DataType data_type = luci_interpreter::DataType::FLOAT32; luci_interpreter::Shape shape({1, 4}); - luci_interpreter::AffineQuantization quantization; std::string tensor_name = "input_tensor"; - luci_interpreter::Tensor input_tensor(data_type, shape, quantization, tensor_name); + luci_interpreter::Tensor input_tensor(data_type, shape, luci_interpreter::AffineQuantization{}, + tensor_name); size_t data_size = input_data.size() * sizeof(float); std::vector buffer(data_size); @@ -58,11 +58,11 @@ TEST(HessianComputerTest, recordHessian_wrong_op_NEG) luci_interpreter::DataType data_type = luci_interpreter::DataType::FLOAT32; luci_interpreter::Shape shape({1, 2, 2, 1}); - luci_interpreter::AffineQuantization quantization; std::string tensor_name = "input_tensor"; - luci_interpreter::Tensor input_tensor(data_type, shape, quantization, tensor_name); + luci_interpreter::Tensor input_tensor(data_type, shape, luci_interpreter::AffineQuantization{}, + tensor_name); size_t data_size = input_data.size() * sizeof(float); std::vector buffer(data_size);