From 0119f0f4dc94044db523cd4bc12d4f6df717b0c8 Mon Sep 17 00:00:00 2001 From: blee-bot <93bslee@gmail.com> Date: Mon, 28 Oct 2024 16:10:53 +0900 Subject: [PATCH] fix text formatting ONE-DCO-1.0-Signed-off-by: Banseok Lee bs93.lee@samsung.com --- .../include/record-hessian/HessianComputer.h | 8 +- .../record-hessian/src/HessianComputer.cpp | 18 +-- .../tests/HessianComputer.test.cpp | 103 +++++++++--------- 3 files changed, 68 insertions(+), 61 deletions(-) diff --git a/compiler/record-hessian/include/record-hessian/HessianComputer.h b/compiler/record-hessian/include/record-hessian/HessianComputer.h index e7c232af445..1ef2cc9b7d5 100644 --- a/compiler/record-hessian/include/record-hessian/HessianComputer.h +++ b/compiler/record-hessian/include/record-hessian/HessianComputer.h @@ -31,9 +31,11 @@ class HessianComputer // Record min/max of node void recordHessian(const luci::CircleNode *node, const luci_interpreter::Tensor *input_tensor); - void recordHessianForConv2D(const luci::CircleNode *node, const luci_interpreter::Tensor *input_tensor); - - void recordHessianForFullyConnected(const luci::CircleNode *node, const luci_interpreter::Tensor *input_tensor); + void recordHessianForConv2D(const luci::CircleNode *node, + const luci_interpreter::Tensor *input_tensor); + + void recordHessianForFullyConnected(const luci::CircleNode *node, + const luci_interpreter::Tensor *input_tensor); 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, diff --git a/compiler/record-hessian/src/HessianComputer.cpp b/compiler/record-hessian/src/HessianComputer.cpp index a6bb16ecb0e..9c25d7fd61b 100644 --- a/compiler/record-hessian/src/HessianComputer.cpp +++ b/compiler/record-hessian/src/HessianComputer.cpp @@ -31,7 +31,8 @@ void HessianComputer::unfold(std::vector &buf, uint32_t input_n, uint32_t uint32_t kernel_oc, uint32_t kernel_h, uint32_t kernel_w, uint32_t kernel_ic) { - if (input_c != kernel_ic) { + if (input_c != kernel_ic) + { throw std::runtime_error("Input channels do not match kernel channels."); } int out_height = (input_h - dilation_h * (kernel_h - 1) - 1) / stride_h + 1; @@ -70,7 +71,7 @@ void HessianComputer::unfold(std::vector &buf, uint32_t input_n, uint32_t buf.swap(unfolded_buf); } -void HessianComputer::recordHessianForFullyConnected(const luci::CircleNode *node, +void HessianComputer::recordHessianForFullyConnected(const luci::CircleNode *node, const luci_interpreter::Tensor *input_tensor) { uint32_t size_in_ch; @@ -118,11 +119,11 @@ void HessianComputer::recordHessianForConv2D(const luci::CircleNode *node, const luci_interpreter::Tensor *input_tensor) { const auto node_filter = loco::must_cast( - loco::must_cast(node)->filter()); - const auto node_bias = loco::must_cast( - loco::must_cast(node)->bias()); + loco::must_cast(node)->filter()); + const auto node_bias = + loco::must_cast(loco::must_cast(node)->bias()); uint32_t size_in_ch = - node_filter->size() / node_bias->size(); + node_filter->size() / node_bias->size(); uint32_t input_n = input_tensor->shape().dim(0); uint32_t input_h = input_tensor->shape().dim(1); @@ -144,7 +145,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_oc, kernel_h, kernel_w, kernel_ic); uint32_t length = buf.size() / size_in_ch; std::vector hessian(size_in_ch * size_in_ch, 0); @@ -186,7 +187,8 @@ void HessianComputer::recordHessian(const luci::CircleNode *node, { recordHessianForConv2D(node, input_tensor); } - else{ + else + { throw std::runtime_error(node->name() + " is unsupported op for record hessian."); } } diff --git a/compiler/record-hessian/tests/HessianComputer.test.cpp b/compiler/record-hessian/tests/HessianComputer.test.cpp index e0edf5be847..0a89ec824d6 100644 --- a/compiler/record-hessian/tests/HessianComputer.test.cpp +++ b/compiler/record-hessian/tests/HessianComputer.test.cpp @@ -9,86 +9,89 @@ using namespace record_hessian; TEST(HessianComputerTest, recordHessianValidInput) { - luci::CircleFullyConnected node; + luci::CircleFullyConnected node; - std::vector input_data = {1.0, 2.0, 3.0, 4.0}; + std::vector input_data = {1.0, 2.0, 3.0, 4.0}; - luci_interpreter::DataType data_type = luci_interpreter::DataType::FLOAT32; - luci_interpreter::Shape shape({1, 4}); - luci_interpreter::AffineQuantization quantization; - quantization.scale = {1.0}; - quantization.zero_point = {0}; + luci_interpreter::DataType data_type = luci_interpreter::DataType::FLOAT32; + luci_interpreter::Shape shape({1, 4}); + luci_interpreter::AffineQuantization quantization; + quantization.scale = {1.0}; + quantization.zero_point = {0}; - std::string tensor_name = "input_tensor"; + 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, quantization, tensor_name); - size_t data_size = input_data.size() * sizeof(float); - std::vector buffer(data_size); + size_t data_size = input_data.size() * sizeof(float); + std::vector buffer(data_size); - input_tensor.set_data_buffer(buffer.data()); - input_tensor.writeData(input_data.data(), data_size); + input_tensor.set_data_buffer(buffer.data()); + input_tensor.writeData(input_data.data(), data_size); - HessianComputer computer; + HessianComputer computer; - EXPECT_NO_THROW(computer.recordHessian(&node, &input_tensor)); + EXPECT_NO_THROW(computer.recordHessian(&node, &input_tensor)); } TEST(HessianComputerTest, recordHessianValidInput_NEG) { - luci::CircleAdd node; + luci::CircleAdd node; - std::vector input_data = {1.0, 2.0, 3.0, 4.0}; - - luci_interpreter::DataType data_type = luci_interpreter::DataType::FLOAT32; - luci_interpreter::Shape shape({1, 2, 2, 1}); - luci_interpreter::AffineQuantization quantization; - quantization.scale = {1.0}; - quantization.zero_point = {0}; + std::vector input_data = {1.0, 2.0, 3.0, 4.0}; - std::string tensor_name = "input_tensor"; + luci_interpreter::DataType data_type = luci_interpreter::DataType::FLOAT32; + luci_interpreter::Shape shape({1, 2, 2, 1}); + luci_interpreter::AffineQuantization quantization; + quantization.scale = {1.0}; + quantization.zero_point = {0}; - luci_interpreter::Tensor input_tensor(data_type, shape, quantization, tensor_name); + std::string tensor_name = "input_tensor"; - size_t data_size = input_data.size() * sizeof(float); - std::vector buffer(data_size); + luci_interpreter::Tensor input_tensor(data_type, shape, quantization, tensor_name); - input_tensor.set_data_buffer(buffer.data()); - input_tensor.writeData(input_data.data(), data_size); + size_t data_size = input_data.size() * sizeof(float); + std::vector buffer(data_size); - HessianComputer computer; + input_tensor.set_data_buffer(buffer.data()); + input_tensor.writeData(input_data.data(), data_size); - EXPECT_ANY_THROW(computer.recordHessian(&node, &input_tensor)); + HessianComputer computer; + + EXPECT_ANY_THROW(computer.recordHessian(&node, &input_tensor)); } TEST(HessianComputerTest, recordHessianNullTensor_NEG) { - luci::CircleAdd node; - HessianComputer computer; - EXPECT_ANY_THROW(computer.recordHessian(&node, nullptr)); + luci::CircleAdd node; + HessianComputer computer; + EXPECT_ANY_THROW(computer.recordHessian(&node, nullptr)); } 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; + 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; - HessianComputer computer; - computer.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); - std::vector expected_output = {1.0, 3.0, 5.0, 7.0, 2.0, 4.0, 6.0, 8.0}; + HessianComputer computer; + computer.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); + 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); + EXPECT_EQ(buf, expected_output); } 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; - - HessianComputer computer; - EXPECT_ANY_THROW(computer.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)); -} \ No newline at end of file + 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; + + HessianComputer computer; + EXPECT_ANY_THROW(computer.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)); +}