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 diff --git a/app/layer_example/CMakeLists.txt b/app/layer_example/CMakeLists.txt new file mode 100644 index 0000000..0724019 --- /dev/null +++ b/app/layer_example/CMakeLists.txt @@ -0,0 +1,9 @@ +set(ARM_DIR "${CMAKE_SOURCE_DIR}/3rdparty/ComputeLibrary") + +add_executable(ElementwiseLayer ElementwiseLayer.cpp) + +include_directories(${ARM_DIR}) +include_directories(${ARM_DIR}/include) +target_link_directories(ElementwiseLayer PUBLIC ${ARM_DIR}/build) + +target_link_libraries(ElementwiseLayer arm_compute) \ 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..58ae43a --- /dev/null +++ b/app/layer_example/ElementwiseLayer.cpp @@ -0,0 +1,76 @@ +#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, ConvertPolicy::WRAP); + 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; +} \ No newline at end of file