From 5f1561bc280f41d698513fae281dda3a29c793d3 Mon Sep 17 00:00:00 2001 From: chekalexey Date: Wed, 8 Jan 2025 16:27:04 +0300 Subject: [PATCH 1/8] Add layer examples --- app/layer_example/CMakeLists.txt | 9 ++++++ app/layer_example/ConvolutionLayer.cpp | 40 ++++++++++++++++++++++++++ app/layer_example/ElementwiseLayer.cpp | 31 ++++++++++++++++++++ 3 files changed, 80 insertions(+) create mode 100644 app/layer_example/CMakeLists.txt create mode 100644 app/layer_example/ConvolutionLayer.cpp create mode 100644 app/layer_example/ElementwiseLayer.cpp diff --git a/app/layer_example/CMakeLists.txt b/app/layer_example/CMakeLists.txt new file mode 100644 index 0000000..8eec088 --- /dev/null +++ b/app/layer_example/CMakeLists.txt @@ -0,0 +1,9 @@ +set(ARM_DIR "/3rdparty/ComputeLibrary") + +include_directories(${ARM_DIR}/include) +link_directories(${ARM_DIR}/build) + +add_executable(ConvolutionLayer ConvolutionLayer.cpp) +add_executable(ElementwiseLayer ElementwiseLayer.cpp) + +target_link_libraries(ConvolutionLayer arm_compute) \ No newline at end of file diff --git a/app/layer_example/ConvolutionLayer.cpp b/app/layer_example/ConvolutionLayer.cpp new file mode 100644 index 0000000..377b320 --- /dev/null +++ b/app/layer_example/ConvolutionLayer.cpp @@ -0,0 +1,40 @@ +#include "../ComputeLibrary/arm_compute/runtime/NEON/NEFunctions.h" +#include "../ComputeLibrary/utils/Utils.h" + +#include +using namespace arm_compute; +using namespace utils; + +int main(){ + Tensor input; + Tensor weight; + Tensor bias; + Tensor output; + + const unsigned int N = 1; + const unsigned int Hin = 3; + const unsigned int Win = 3; + const unsigned int Cin = 1; + + const unsigned int Hf = 3; + const unsigned int Wf = 3; + + const unsigned int Hout = Hin - Hf + 1; + const unsigned int Wout = Win - Wf + 1; + const unsigned int Cout = 1; + + input.allocator()->init(TensorInfo(TensorShape(Hin, Win, Cin), 1, DataType::F32)); + weight.allocator()->init(TensorInfo(TensorShape(Hf, Wf, Cin, Cout), 1, DataType::F32)); + output.allocator()->init(TensorInfo(TensorShape(Hout, Wout, Cout), 1, DataType::F32)); + + input.allocator()->allocate(); + weight.allocator()->allocate(); + output.allocator()->allocate(); + + NEConvolutionLayer conv; + conv.configure(&input, &weight, nullptr, &output, PadStrideInfo(1, 1, 0, 0)); + + conv.run(); + + output.print(std::cout); +} \ No newline at end of file diff --git a/app/layer_example/ElementwiseLayer.cpp b/app/layer_example/ElementwiseLayer.cpp new file mode 100644 index 0000000..eeeb30d --- /dev/null +++ b/app/layer_example/ElementwiseLayer.cpp @@ -0,0 +1,31 @@ +#include "../ComputeLibrary/arm_compute/runtime/NEON/functions/NEElementwiseOperations.h" +#include "../ComputeLibrary/utils/Utils.h" + +#include +using namespace arm_compute; +using namespace utils; + +int main() { + const int input_width = 5; + const int input_height = 5; + + Tensor input1, input2, output; + + input1.allocator()->init(TensorInfo(TensorShape(input_width, input_height, 1), 1, DataType::F32)); + input2.allocator()->init(TensorInfo(TensorShape(input_width, input_height, 1), 1, DataType::F32)); + output.allocator()->init(TensorInfo(TensorShape(input_width, input_height, 1), 1, DataType::F32)); + + input1.allocator()->allocate(); + input2.allocator()->allocate(); + output.allocator()->allocate(); + + fill_random_tensor(input1, 0.f, 1.f); + fill_random_tensor(input2, 0.f, 1.f); + + NEElementwiseSquaredDiff elementwise; + elementwise.configure(&input1, &input2, &output); + + elementwise.run(); + + output.print(std::cout); +} From 58a016c3d4a0e8acb7d0363fd8ef0f4ffe0512fd Mon Sep 17 00:00:00 2001 From: chekalexey Date: Wed, 8 Jan 2025 18:09:40 +0300 Subject: [PATCH 2/8] Add layer examples --- app/CMakeLists.txt | 1 + app/example/CMakeLists.txt | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index a5c4dce..b704bc8 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -1 +1,2 @@ add_subdirectory(example) +add_subdirectory(layer_example) \ No newline at end of file diff --git a/app/example/CMakeLists.txt b/app/example/CMakeLists.txt index 033d285..5ac1ad8 100644 --- a/app/example/CMakeLists.txt +++ b/app/example/CMakeLists.txt @@ -1 +1 @@ -add_executable(example main.cpp) +add_executable(example main.cpp) \ No newline at end of file From a19ca04da31733cfc523d07c51d320fe70aeebbf Mon Sep 17 00:00:00 2001 From: chekalexey Date: Tue, 11 Feb 2025 21:28:24 +0300 Subject: [PATCH 3/8] fixed --- app/layer_example/CMakeLists.txt | 7 ++++--- app/layer_example/ConvolutionLayer.cpp | 4 ++-- app/layer_example/ElementwiseLayer.cpp | 4 ++-- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/app/layer_example/CMakeLists.txt b/app/layer_example/CMakeLists.txt index 8eec088..b89ef42 100644 --- a/app/layer_example/CMakeLists.txt +++ b/app/layer_example/CMakeLists.txt @@ -1,9 +1,10 @@ -set(ARM_DIR "/3rdparty/ComputeLibrary") +set(ARM_DIR "${CMAKE_SOURCE_DIR}/3rdparty/ComputeLibrary") -include_directories(${ARM_DIR}/include) +include_directories(${ARM_DIR}) link_directories(${ARM_DIR}/build) add_executable(ConvolutionLayer ConvolutionLayer.cpp) add_executable(ElementwiseLayer ElementwiseLayer.cpp) -target_link_libraries(ConvolutionLayer arm_compute) \ No newline at end of file +target_link_libraries(ConvolutionLayer arm_compute) +target_link_libraries(ElementwiseLayer arm_compute) \ No newline at end of file diff --git a/app/layer_example/ConvolutionLayer.cpp b/app/layer_example/ConvolutionLayer.cpp index 377b320..618629b 100644 --- a/app/layer_example/ConvolutionLayer.cpp +++ b/app/layer_example/ConvolutionLayer.cpp @@ -1,5 +1,5 @@ -#include "../ComputeLibrary/arm_compute/runtime/NEON/NEFunctions.h" -#include "../ComputeLibrary/utils/Utils.h" +#include "ComputeLibrary/arm_compute/runtime/NEON/NEFunctions.h" +#include "ComputeLibrary/utils/Utils.h" #include using namespace arm_compute; diff --git a/app/layer_example/ElementwiseLayer.cpp b/app/layer_example/ElementwiseLayer.cpp index eeeb30d..3522621 100644 --- a/app/layer_example/ElementwiseLayer.cpp +++ b/app/layer_example/ElementwiseLayer.cpp @@ -1,5 +1,5 @@ -#include "../ComputeLibrary/arm_compute/runtime/NEON/functions/NEElementwiseOperations.h" -#include "../ComputeLibrary/utils/Utils.h" +#include "ComputeLibrary/arm_compute/runtime/NEON/functions/NEElementwiseOperations.h" +#include "ComputeLibrary/utils/Utils.h" #include using namespace arm_compute; From 6f75b736bfd71e6d0379768a2f6e70a81d0f48ef Mon Sep 17 00:00:00 2001 From: chekalexey Date: Tue, 25 Feb 2025 12:25:52 +0300 Subject: [PATCH 4/8] correction of inclusions --- app/layer_example/CMakeLists.txt | 6 +++--- app/layer_example/ConvolutionLayer.cpp | 4 ++-- app/layer_example/ElementwiseLayer.cpp | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/layer_example/CMakeLists.txt b/app/layer_example/CMakeLists.txt index b89ef42..f51b953 100644 --- a/app/layer_example/CMakeLists.txt +++ b/app/layer_example/CMakeLists.txt @@ -1,10 +1,10 @@ set(ARM_DIR "${CMAKE_SOURCE_DIR}/3rdparty/ComputeLibrary") -include_directories(${ARM_DIR}) -link_directories(${ARM_DIR}/build) - add_executable(ConvolutionLayer ConvolutionLayer.cpp) add_executable(ElementwiseLayer ElementwiseLayer.cpp) +include_directories(${ARM_DIR}) +link_directories(${ARM_DIR}/build) + target_link_libraries(ConvolutionLayer arm_compute) target_link_libraries(ElementwiseLayer arm_compute) \ No newline at end of file diff --git a/app/layer_example/ConvolutionLayer.cpp b/app/layer_example/ConvolutionLayer.cpp index 618629b..60ed50a 100644 --- a/app/layer_example/ConvolutionLayer.cpp +++ b/app/layer_example/ConvolutionLayer.cpp @@ -1,5 +1,5 @@ -#include "ComputeLibrary/arm_compute/runtime/NEON/NEFunctions.h" -#include "ComputeLibrary/utils/Utils.h" +#include "arm_compute/runtime/NEON/NEFunctions.h" +#include "utils/Utils.h" #include using namespace arm_compute; diff --git a/app/layer_example/ElementwiseLayer.cpp b/app/layer_example/ElementwiseLayer.cpp index 3522621..05a60f6 100644 --- a/app/layer_example/ElementwiseLayer.cpp +++ b/app/layer_example/ElementwiseLayer.cpp @@ -1,5 +1,5 @@ -#include "ComputeLibrary/arm_compute/runtime/NEON/functions/NEElementwiseOperations.h" -#include "ComputeLibrary/utils/Utils.h" +#include "arm_compute/runtime/NEON/functions/NEElementwiseOperations.h" +#include "utils/Utils.h" #include using namespace arm_compute; From 968c92a790760926332827307f2101d4359fb3ae Mon Sep 17 00:00:00 2001 From: chekalexey Date: Tue, 25 Feb 2025 16:21:25 +0300 Subject: [PATCH 5/8] Update cmakelist --- app/layer_example/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/app/layer_example/CMakeLists.txt b/app/layer_example/CMakeLists.txt index f51b953..5e80638 100644 --- a/app/layer_example/CMakeLists.txt +++ b/app/layer_example/CMakeLists.txt @@ -4,6 +4,7 @@ add_executable(ConvolutionLayer ConvolutionLayer.cpp) add_executable(ElementwiseLayer ElementwiseLayer.cpp) include_directories(${ARM_DIR}) +include_directories(${ARM_DIR/include}) link_directories(${ARM_DIR}/build) target_link_libraries(ConvolutionLayer arm_compute) From 7c87d3d8b04ab5c3000cbb0f6fe79246a343ab19 Mon Sep 17 00:00:00 2001 From: chekalexey Date: Tue, 11 Mar 2025 15:19:27 +0300 Subject: [PATCH 6/8] Add a ElementwiseLayer Example --- app/layer_example/ElementwiseLayer.cpp | 73 +++++++++++++++++++++----- 1 file changed, 59 insertions(+), 14 deletions(-) diff --git a/app/layer_example/ElementwiseLayer.cpp b/app/layer_example/ElementwiseLayer.cpp index 05a60f6..6ac7794 100644 --- a/app/layer_example/ElementwiseLayer.cpp +++ b/app/layer_example/ElementwiseLayer.cpp @@ -1,31 +1,76 @@ -#include "arm_compute/runtime/NEON/functions/NEElementwiseOperations.h" +#include "arm_compute/runtime/NEON/NEFunctions.h" #include "utils/Utils.h" #include using namespace arm_compute; using namespace utils; -int main() { +class ElementwiseLayer { const int input_width = 5; const int input_height = 5; Tensor input1, input2, output; - input1.allocator()->init(TensorInfo(TensorShape(input_width, input_height, 1), 1, DataType::F32)); - input2.allocator()->init(TensorInfo(TensorShape(input_width, input_height, 1), 1, DataType::F32)); - output.allocator()->init(TensorInfo(TensorShape(input_width, input_height, 1), 1, DataType::F32)); +public: + void fill() { + input1.allocator()->init(TensorInfo(TensorShape(input_width, input_height, 1), 1, DataType::F32)); + input2.allocator()->init(TensorInfo(TensorShape(input_width, input_height, 1), 1, DataType::F32)); + output.allocator()->init(TensorInfo(TensorShape(input_width, input_height, 1), 1, DataType::F32)); + + input1.allocator()->allocate(); + input2.allocator()->allocate(); + output.allocator()->allocate(); - input1.allocator()->allocate(); - input2.allocator()->allocate(); - output.allocator()->allocate(); + fill_random_tensor(input1, 0.f, 1.f); + fill_random_tensor(input2, 0.f, 1.f); + } - fill_random_tensor(input1, 0.f, 1.f); - fill_random_tensor(input2, 0.f, 1.f); + void SquaredDiff() { + NEElementwiseSquaredDiff elementwise; + elementwise.configure(&input1, &input2, &output); + elementwise.run(); + } + + void Division() { + NEElementwiseDivision elementwise; + elementwise.configure(&input1, &input2, &output); + elementwise.run(); + } + + void Addition() { + NEArithmeticAddition add; + add.configure(&input1, &input2, &output); + add.run(); + } + + void Swish() { + NEActivationLayer act; + act.configure(&input1, &input2, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::SWISH)); + act.run(); + } + + void Abs() { + NEActivationLayer act; + act.configure(&input1, &input2, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::ABS)); + act.run(); + } - NEElementwiseSquaredDiff elementwise; - elementwise.configure(&input1, &input2, &output); + void Sigmoid() { + NEActivationLayer act; + act.configure(&input1, &input2, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LOGISTIC)); + act.run(); + } - elementwise.run(); + void print() { + output.print(std::cout); + } +}; + +int main() { + ElementwiseLayer a; + a.fill(); + a.Addition(); + a.print(); - output.print(std::cout); + return 0; } From 9bfa382fe3cd43b60ea718e1d0cb3ed23aec2033 Mon Sep 17 00:00:00 2001 From: chekalexey Date: Tue, 18 Mar 2025 12:47:59 +0300 Subject: [PATCH 7/8] Add a pooling layer example --- app/layer_example/PoolingLayer.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 app/layer_example/PoolingLayer.cpp diff --git a/app/layer_example/PoolingLayer.cpp b/app/layer_example/PoolingLayer.cpp new file mode 100644 index 0000000..885e63f --- /dev/null +++ b/app/layer_example/PoolingLayer.cpp @@ -0,0 +1,28 @@ +#include "arm_compute/runtime/NEON/NEFunctions.h" +#include "utils/Utils.h" + +#include +using namespace arm_compute; +using namespace utils; + +int main() { + Tensor input; + Tensor output; + + const int input_width = 5; + const int input_height = 5; + + input.allocator()->init(TensorInfo(TensorShape(input_width, input_height, 1), 1, DataType::F32)); + output.allocator()->init(TensorInfo(TensorShape(input_width, input_height, 1), 1, DataType::F32)); + + input.allocator()->allocate(); + output.allocator()->allocate(); + + fill_random_tensor(input, 0.f, 1.f); + + NEPoolingLayer pool; + pool.configure(&input, &output, PoolingLayerInfo(PoolingType::MAX, DataLayout::NHWC)); + pool.run(); + + output.print(std::cout); +} \ No newline at end of file From a484a75945eb587b919c718223225b07b21b4a69 Mon Sep 17 00:00:00 2001 From: chekalexey Date: Tue, 15 Apr 2025 11:42:52 +0300 Subject: [PATCH 8/8] Update CMakeLists --- app/layer_example/CMakeLists.txt | 10 ++-- app/layer_example/ConvolutionLayer.cpp | 40 -------------- app/layer_example/ElementwiseLayer.cpp | 76 -------------------------- 3 files changed, 4 insertions(+), 122 deletions(-) delete mode 100644 app/layer_example/ConvolutionLayer.cpp delete mode 100644 app/layer_example/ElementwiseLayer.cpp diff --git a/app/layer_example/CMakeLists.txt b/app/layer_example/CMakeLists.txt index 5e80638..0c94175 100644 --- a/app/layer_example/CMakeLists.txt +++ b/app/layer_example/CMakeLists.txt @@ -1,11 +1,9 @@ set(ARM_DIR "${CMAKE_SOURCE_DIR}/3rdparty/ComputeLibrary") -add_executable(ConvolutionLayer ConvolutionLayer.cpp) -add_executable(ElementwiseLayer ElementwiseLayer.cpp) +add_executable(PoolingLayer PoolingLayer.cpp) include_directories(${ARM_DIR}) -include_directories(${ARM_DIR/include}) -link_directories(${ARM_DIR}/build) +include_directories(${ARM_DIR}/include) +target_link_directories(PoolingLayer PUBLIC ${ARM_DIR}/build) -target_link_libraries(ConvolutionLayer arm_compute) -target_link_libraries(ElementwiseLayer arm_compute) \ No newline at end of file +target_link_libraries(PoolingLayer arm_compute) \ No newline at end of file diff --git a/app/layer_example/ConvolutionLayer.cpp b/app/layer_example/ConvolutionLayer.cpp deleted file mode 100644 index 60ed50a..0000000 --- a/app/layer_example/ConvolutionLayer.cpp +++ /dev/null @@ -1,40 +0,0 @@ -#include "arm_compute/runtime/NEON/NEFunctions.h" -#include "utils/Utils.h" - -#include -using namespace arm_compute; -using namespace utils; - -int main(){ - Tensor input; - Tensor weight; - Tensor bias; - Tensor output; - - const unsigned int N = 1; - const unsigned int Hin = 3; - const unsigned int Win = 3; - const unsigned int Cin = 1; - - const unsigned int Hf = 3; - const unsigned int Wf = 3; - - const unsigned int Hout = Hin - Hf + 1; - const unsigned int Wout = Win - Wf + 1; - const unsigned int Cout = 1; - - input.allocator()->init(TensorInfo(TensorShape(Hin, Win, Cin), 1, DataType::F32)); - weight.allocator()->init(TensorInfo(TensorShape(Hf, Wf, Cin, Cout), 1, DataType::F32)); - output.allocator()->init(TensorInfo(TensorShape(Hout, Wout, Cout), 1, DataType::F32)); - - input.allocator()->allocate(); - weight.allocator()->allocate(); - output.allocator()->allocate(); - - NEConvolutionLayer conv; - conv.configure(&input, &weight, nullptr, &output, PadStrideInfo(1, 1, 0, 0)); - - conv.run(); - - output.print(std::cout); -} \ No newline at end of file diff --git a/app/layer_example/ElementwiseLayer.cpp b/app/layer_example/ElementwiseLayer.cpp deleted file mode 100644 index 6ac7794..0000000 --- a/app/layer_example/ElementwiseLayer.cpp +++ /dev/null @@ -1,76 +0,0 @@ -#include "arm_compute/runtime/NEON/NEFunctions.h" -#include "utils/Utils.h" - -#include -using namespace arm_compute; -using namespace utils; - -class ElementwiseLayer { - const int input_width = 5; - const int input_height = 5; - - Tensor input1, input2, output; - -public: - void fill() { - input1.allocator()->init(TensorInfo(TensorShape(input_width, input_height, 1), 1, DataType::F32)); - input2.allocator()->init(TensorInfo(TensorShape(input_width, input_height, 1), 1, DataType::F32)); - output.allocator()->init(TensorInfo(TensorShape(input_width, input_height, 1), 1, DataType::F32)); - - input1.allocator()->allocate(); - input2.allocator()->allocate(); - output.allocator()->allocate(); - - fill_random_tensor(input1, 0.f, 1.f); - fill_random_tensor(input2, 0.f, 1.f); - } - - void SquaredDiff() { - NEElementwiseSquaredDiff elementwise; - elementwise.configure(&input1, &input2, &output); - elementwise.run(); - } - - void Division() { - NEElementwiseDivision elementwise; - elementwise.configure(&input1, &input2, &output); - elementwise.run(); - } - - void Addition() { - NEArithmeticAddition add; - add.configure(&input1, &input2, &output); - add.run(); - } - - void Swish() { - NEActivationLayer act; - act.configure(&input1, &input2, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::SWISH)); - act.run(); - } - - void Abs() { - NEActivationLayer act; - act.configure(&input1, &input2, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::ABS)); - act.run(); - } - - void Sigmoid() { - NEActivationLayer act; - act.configure(&input1, &input2, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LOGISTIC)); - act.run(); - } - - void print() { - output.print(std::cout); - } -}; - -int main() { - ElementwiseLayer a; - a.fill(); - a.Addition(); - a.print(); - - return 0; -}