diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index a5c4dce..3ef8013 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -1 +1,2 @@ add_subdirectory(example) +add_subdirectory(layer_example) diff --git a/app/layer_example/CMakeLists.txt b/app/layer_example/CMakeLists.txt new file mode 100644 index 0000000..e88aaa6 --- /dev/null +++ b/app/layer_example/CMakeLists.txt @@ -0,0 +1,11 @@ +set(ARM_DIR "${CMAKE_SOURCE_DIR}/3rdparty/ComputeLibrary") + +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) +target_link_libraries(ElementwiseLayer arm_compute) diff --git a/app/layer_example/ConvolutionLayer.cpp b/app/layer_example/ConvolutionLayer.cpp new file mode 100644 index 0000000..c1d90b9 --- /dev/null +++ b/app/layer_example/ConvolutionLayer.cpp @@ -0,0 +1,40 @@ +#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); +} diff --git a/app/layer_example/ElementwiseLayer.cpp b/app/layer_example/ElementwiseLayer.cpp new file mode 100644 index 0000000..05a60f6 --- /dev/null +++ b/app/layer_example/ElementwiseLayer.cpp @@ -0,0 +1,31 @@ +#include "arm_compute/runtime/NEON/functions/NEElementwiseOperations.h" +#include "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); +}