From feea1ce4e4a3cb8cb3d587a9a2832d7b1b40b3f2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EC=9D=B4=EC=B6=98=EC=84=9D/=EB=8F=99=EC=9E=91=EC=A0=9C?= =?utf8?q?=EC=96=B4Lab=28SR=29/Staff=20Engineer/=EC=82=BC=EC=84=B1?= =?utf8?q?=EC=A0=84=EC=9E=90?= Date: Thu, 19 Jul 2018 19:27:07 +0900 Subject: [PATCH] Remove kernal(/acl) from repo (#2023) This commit remove kernel directory from repo since runtime/nn has removed. Signed-off-by: Chunseok Lee --- libs/kernel/CMakeLists.txt | 3 - libs/kernel/acl/CMakeLists.txt | 103 ------ libs/kernel/acl/src/Add.test.h | 314 ----------------- libs/kernel/acl/src/DepthwiseConv2D.h | 100 ------ libs/kernel/acl/src/DepthwiseConv2D.test.h | 212 ------------ libs/kernel/acl/src/FullyConnected.h | 156 --------- libs/kernel/acl/src/FullyConnected.test.h | 211 ------------ libs/kernel/acl/src/IO_accessor.cpp | 363 -------------------- libs/kernel/acl/src/IO_accessor.h | 197 ----------- libs/kernel/acl/src/Init_acl.cpp | 32 -- libs/kernel/acl/src/Mul.h | 129 ------- libs/kernel/acl/src/Mul.test.data.h | 387 --------------------- libs/kernel/acl/src/Mul.test.h | 157 --------- libs/kernel/acl/src/Reshape.h | 74 ---- libs/kernel/acl/src/Reshape.test.h | 50 --- libs/kernel/acl/src/UniqueTensor.h | 62 ---- libs/kernel/acl/src/cl/Add.cpp | 106 ------ libs/kernel/acl/src/cl/Add.test.cpp | 190 ----------- libs/kernel/acl/src/cl/Concatenation.cpp | 107 ------ libs/kernel/acl/src/cl/Concatenation.test.cpp | 58 ---- libs/kernel/acl/src/cl/Conv2D.cpp | 115 ------- libs/kernel/acl/src/cl/Conv2D.test.cpp | 162 --------- libs/kernel/acl/src/cl/DepthwiseConv2D.cpp | 55 --- libs/kernel/acl/src/cl/DepthwiseConv2D.test.cpp | 20 -- libs/kernel/acl/src/cl/FullyConnected.cpp | 52 --- libs/kernel/acl/src/cl/FullyConnected.test.cpp | 20 -- libs/kernel/acl/src/cl/Mul.cpp | 40 --- libs/kernel/acl/src/cl/Mul.test.cpp | 23 -- libs/kernel/acl/src/cl/Pooling.cpp | 129 ------- libs/kernel/acl/src/cl/Pooling.test.cpp | 395 ---------------------- libs/kernel/acl/src/cl/ReLU.cpp | 83 ----- libs/kernel/acl/src/cl/ReLU.test.cpp | 103 ------ libs/kernel/acl/src/cl/ReLU6.cpp | 130 ------- libs/kernel/acl/src/cl/ReLU6.test.cpp | 203 ----------- libs/kernel/acl/src/cl/Reshape.cpp | 45 --- libs/kernel/acl/src/cl/Reshape.test.cpp | 20 -- libs/kernel/acl/src/cl/Softmax.cpp | 80 ----- libs/kernel/acl/src/cl/Softmax.test.cpp | 105 ------ libs/kernel/acl/src/gtest_env.cpp | 34 -- libs/kernel/acl/src/neon/Add.cpp | 102 ------ libs/kernel/acl/src/neon/Add.test.cpp | 189 ----------- libs/kernel/acl/src/neon/Concatenation.cpp | 109 ------ libs/kernel/acl/src/neon/Concatenation.test.cpp | 58 ---- libs/kernel/acl/src/neon/Conv2D.cpp | 114 ------- libs/kernel/acl/src/neon/Conv2D.test.cpp | 162 --------- libs/kernel/acl/src/neon/DepthwiseConv2D.cpp | 59 ---- libs/kernel/acl/src/neon/DepthwiseConv2D.test.cpp | 20 -- libs/kernel/acl/src/neon/FullyConnected.cpp | 58 ---- libs/kernel/acl/src/neon/FullyConnected.test.cpp | 20 -- libs/kernel/acl/src/neon/Mul.cpp | 54 --- libs/kernel/acl/src/neon/Mul.test.cpp | 28 -- libs/kernel/acl/src/neon/Pooling.cpp | 128 ------- libs/kernel/acl/src/neon/Pooling.test.cpp | 358 -------------------- libs/kernel/acl/src/neon/ReLU.cpp | 84 ----- libs/kernel/acl/src/neon/ReLU.test.cpp | 105 ------ libs/kernel/acl/src/neon/ReLU6.cpp | 133 -------- libs/kernel/acl/src/neon/ReLU6.test.cpp | 205 ----------- libs/kernel/acl/src/neon/Reshape.cpp | 50 --- libs/kernel/acl/src/neon/Reshape.test.cpp | 20 -- libs/kernel/acl/src/neon/Softmax.cpp | 80 ----- libs/kernel/acl/src/neon/Softmax.test.cpp | 105 ------ libs/kernel/acl/src/shape.cpp | 135 -------- libs/kernel/acl/src/shape.h | 108 ------ libs/kernel/acl/src/support.cpp | 53 --- libs/kernel/acl/src/support.h | 89 ----- libs/kernel/acl/src/util.cpp | 139 -------- libs/kernel/acl/src/util.h | 208 ------------ 67 files changed, 7798 deletions(-) delete mode 100644 libs/kernel/CMakeLists.txt delete mode 100644 libs/kernel/acl/CMakeLists.txt delete mode 100644 libs/kernel/acl/src/Add.test.h delete mode 100644 libs/kernel/acl/src/DepthwiseConv2D.h delete mode 100644 libs/kernel/acl/src/DepthwiseConv2D.test.h delete mode 100644 libs/kernel/acl/src/FullyConnected.h delete mode 100644 libs/kernel/acl/src/FullyConnected.test.h delete mode 100644 libs/kernel/acl/src/IO_accessor.cpp delete mode 100644 libs/kernel/acl/src/IO_accessor.h delete mode 100644 libs/kernel/acl/src/Init_acl.cpp delete mode 100644 libs/kernel/acl/src/Mul.h delete mode 100644 libs/kernel/acl/src/Mul.test.data.h delete mode 100644 libs/kernel/acl/src/Mul.test.h delete mode 100644 libs/kernel/acl/src/Reshape.h delete mode 100644 libs/kernel/acl/src/Reshape.test.h delete mode 100644 libs/kernel/acl/src/UniqueTensor.h delete mode 100644 libs/kernel/acl/src/cl/Add.cpp delete mode 100644 libs/kernel/acl/src/cl/Add.test.cpp delete mode 100644 libs/kernel/acl/src/cl/Concatenation.cpp delete mode 100644 libs/kernel/acl/src/cl/Concatenation.test.cpp delete mode 100644 libs/kernel/acl/src/cl/Conv2D.cpp delete mode 100644 libs/kernel/acl/src/cl/Conv2D.test.cpp delete mode 100644 libs/kernel/acl/src/cl/DepthwiseConv2D.cpp delete mode 100644 libs/kernel/acl/src/cl/DepthwiseConv2D.test.cpp delete mode 100644 libs/kernel/acl/src/cl/FullyConnected.cpp delete mode 100644 libs/kernel/acl/src/cl/FullyConnected.test.cpp delete mode 100644 libs/kernel/acl/src/cl/Mul.cpp delete mode 100644 libs/kernel/acl/src/cl/Mul.test.cpp delete mode 100644 libs/kernel/acl/src/cl/Pooling.cpp delete mode 100644 libs/kernel/acl/src/cl/Pooling.test.cpp delete mode 100644 libs/kernel/acl/src/cl/ReLU.cpp delete mode 100644 libs/kernel/acl/src/cl/ReLU.test.cpp delete mode 100644 libs/kernel/acl/src/cl/ReLU6.cpp delete mode 100644 libs/kernel/acl/src/cl/ReLU6.test.cpp delete mode 100644 libs/kernel/acl/src/cl/Reshape.cpp delete mode 100644 libs/kernel/acl/src/cl/Reshape.test.cpp delete mode 100644 libs/kernel/acl/src/cl/Softmax.cpp delete mode 100644 libs/kernel/acl/src/cl/Softmax.test.cpp delete mode 100644 libs/kernel/acl/src/gtest_env.cpp delete mode 100644 libs/kernel/acl/src/neon/Add.cpp delete mode 100644 libs/kernel/acl/src/neon/Add.test.cpp delete mode 100644 libs/kernel/acl/src/neon/Concatenation.cpp delete mode 100644 libs/kernel/acl/src/neon/Concatenation.test.cpp delete mode 100644 libs/kernel/acl/src/neon/Conv2D.cpp delete mode 100644 libs/kernel/acl/src/neon/Conv2D.test.cpp delete mode 100644 libs/kernel/acl/src/neon/DepthwiseConv2D.cpp delete mode 100644 libs/kernel/acl/src/neon/DepthwiseConv2D.test.cpp delete mode 100644 libs/kernel/acl/src/neon/FullyConnected.cpp delete mode 100644 libs/kernel/acl/src/neon/FullyConnected.test.cpp delete mode 100644 libs/kernel/acl/src/neon/Mul.cpp delete mode 100644 libs/kernel/acl/src/neon/Mul.test.cpp delete mode 100644 libs/kernel/acl/src/neon/Pooling.cpp delete mode 100644 libs/kernel/acl/src/neon/Pooling.test.cpp delete mode 100644 libs/kernel/acl/src/neon/ReLU.cpp delete mode 100644 libs/kernel/acl/src/neon/ReLU.test.cpp delete mode 100644 libs/kernel/acl/src/neon/ReLU6.cpp delete mode 100644 libs/kernel/acl/src/neon/ReLU6.test.cpp delete mode 100644 libs/kernel/acl/src/neon/Reshape.cpp delete mode 100644 libs/kernel/acl/src/neon/Reshape.test.cpp delete mode 100644 libs/kernel/acl/src/neon/Softmax.cpp delete mode 100644 libs/kernel/acl/src/neon/Softmax.test.cpp delete mode 100644 libs/kernel/acl/src/shape.cpp delete mode 100644 libs/kernel/acl/src/shape.h delete mode 100644 libs/kernel/acl/src/support.cpp delete mode 100644 libs/kernel/acl/src/support.h delete mode 100644 libs/kernel/acl/src/util.cpp delete mode 100644 libs/kernel/acl/src/util.h diff --git a/libs/kernel/CMakeLists.txt b/libs/kernel/CMakeLists.txt deleted file mode 100644 index 7da5460..0000000 --- a/libs/kernel/CMakeLists.txt +++ /dev/null @@ -1,3 +0,0 @@ -if(${TARGET_ARCH_BASE} STREQUAL "arm" OR ${TARGET_ARCH_BASE} STREQUAL "aarch64") - add_subdirectory(acl) -endif() diff --git a/libs/kernel/acl/CMakeLists.txt b/libs/kernel/acl/CMakeLists.txt deleted file mode 100644 index 72a9b66..0000000 --- a/libs/kernel/acl/CMakeLists.txt +++ /dev/null @@ -1,103 +0,0 @@ -nnfw_find_package(ARMCompute REQUIRED) - -set(LIB_KERNELACL kernelacl) -set(LIB_KERNELACL_TEST kernelacl_test) - -# runtime information -set(PATH_RUNTIME_NN ${CMAKE_SOURCE_DIR}/runtimes/nn) -SET(RUNTIME_INCLUDES ${PATH_RUNTIME_NN}/common/include - ${PATH_RUNTIME_NN}/runtime/include - ${PATH_RUNTIME_NN}/depend/hal/include - ${PATH_RUNTIME_NN}/depend/libhidl/base/include - ${PATH_RUNTIME_NN}/depend/libcutils/include - ${PATH_RUNTIME_NN}/depend/libutils/include - ${PATH_RUNTIME_NN}/depend/android-base/include - ) - -# common -link_directories(${CMAKE_INSTALL_PREFIX}/lib) - -# kernel library -set(KERNELACL_SRCS "src/Init_acl.cpp" - "src/IO_accessor.cpp" - "src/shape.cpp" - "src/support.cpp" - "src/cl/Mul.cpp" - "src/cl/Conv2D.cpp" - "src/cl/DepthwiseConv2D.cpp" - "src/cl/FullyConnected.cpp" - "src/cl/Pooling.cpp" - "src/cl/Reshape.cpp" - "src/cl/Softmax.cpp" - "src/cl/Concatenation.cpp" - "src/cl/Add.cpp" - "src/cl/ReLU.cpp" - "src/cl/ReLU6.cpp" - "src/neon/Mul.cpp" - "src/neon/Conv2D.cpp" - "src/neon/DepthwiseConv2D.cpp" - "src/neon/FullyConnected.cpp" - "src/neon/Pooling.cpp" - "src/neon/Softmax.cpp" - "src/neon/Reshape.cpp" - "src/neon/Concatenation.cpp" - "src/neon/Add.cpp" - "src/neon/ReLU.cpp" - "src/neon/ReLU6.cpp" - ) - -add_library(${LIB_KERNELACL} SHARED ${KERNELACL_SRCS}) -# TODO remove this when default goes to c++14 -set_target_properties(${LIB_KERNELACL} PROPERTIES CXX_STANDARD 14) -target_include_directories(${LIB_KERNELACL} PUBLIC - ${NNFW_INCLUDE_DIR} - ${RUNTIME_INCLUDES} - ${CMAKE_SOURCE_DIR}/include - ) -target_link_libraries(${LIB_KERNELACL} nnfw_support_nnapi) -target_link_libraries(${LIB_KERNELACL} nnfw_util arm_compute) -install(TARGETS ${LIB_KERNELACL} DESTINATION lib) - -# kernel test executable -set(KERNELACL_TEST_SRCS "src/util.cpp" - "src/gtest_env.cpp" - "src/cl/Mul.test.cpp" - "src/cl/Conv2D.test.cpp" - "src/cl/DepthwiseConv2D.test.cpp" - "src/cl/FullyConnected.test.cpp" - "src/cl/Pooling.test.cpp" - "src/cl/Reshape.test.cpp" - "src/cl/Softmax.test.cpp" - "src/cl/Concatenation.test.cpp" - "src/cl/Add.test.cpp" - "src/cl/ReLU.test.cpp" - "src/cl/ReLU6.test.cpp" - "src/neon/Mul.test.cpp" - "src/neon/Conv2D.test.cpp" - "src/neon/DepthwiseConv2D.test.cpp" - "src/neon/FullyConnected.test.cpp" - "src/neon/Pooling.test.cpp" - "src/neon/Softmax.test.cpp" - "src/neon/Reshape.test.cpp" - "src/neon/Concatenation.test.cpp" - "src/neon/Add.test.cpp" - "src/neon/ReLU.test.cpp" - "src/neon/ReLU6.test.cpp" - ) - -add_executable(${LIB_KERNELACL_TEST} ${KERNELACL_TEST_SRCS}) -# TODO remove this when default goes to c++14 -set_target_properties(${LIB_KERNELACL_TEST} PROPERTIES CXX_STANDARD 14) -target_include_directories(${LIB_KERNELACL_TEST} PUBLIC - ${NNFW_INCLUDE_DIR} - ${RUNTIME_INCLUDES} - ) -if (NOT OBS_BUILD) - add_dependencies(${LIB_KERNELACL_TEST} googletest) -endif() -target_link_libraries(${LIB_KERNELACL_TEST} - ${LIB_KERNELACL} - nnfw_util arm_compute - ${NNFW_GTEST_LIBS} - ) -install(TARGETS ${LIB_KERNELACL_TEST} DESTINATION unittest) diff --git a/libs/kernel/acl/src/Add.test.h b/libs/kernel/acl/src/Add.test.h deleted file mode 100644 index a7ce927..0000000 --- a/libs/kernel/acl/src/Add.test.h +++ /dev/null @@ -1,314 +0,0 @@ -/* - * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef __NNFW_KERNEL_ACL_ADD_TEST_H__ -#define __NNFW_KERNEL_ACL_ADD_TEST_H__ - -// generated test case data -namespace nnfw -{ -namespace add_vector_test -{ -// 1. adding two vectors: [0], [0] -static float x1[1] = { - 1.0, -}; -static float y1[1] = { - 2.0, -}; -static float expected1[1] = { - 3.0, -}; -// 2. adding two vectors: 100 random numbers -static float x2[100] = { - -6.417759, -4.7358875, -11.074962, -4.2841253, -6.1764784, -6.128378, -2.1253011, - 1.8434654, -2.147656, 5.771069, -7.1907907, -2.7715101, 3.296604, -4.272622, - 6.584896, -2.3693078, -3.1644564, 0.37782526, 5.2104087, 0.18219212, -3.053298, - -3.440207, -3.6962276, 1.1613896, 14.312525, 0.19944154, -4.6005354, 2.5095024, - 0.8347582, -7.8343153, 10.99354, 1.7297767, 4.4280763, 8.32951, -6.5384965, - 0.48049495, 0.8144837, 1.119576, -4.013504, 0.060964614, 3.707489, 1.8875263, - -0.5693004, -10.763851, 7.6864552, -6.6477323, 2.2509155, 1.4910474, 7.988678, - -2.6148214, 4.3094416, -0.13960715, 0.7423223, 10.182125, -4.5443907, 7.9473042, - -4.4420857, -7.3940916, 5.6635313, -7.921539, -0.8845104, 1.0182618, 0.96004575, - 2.046311, -3.8806505, -4.5171704, 2.078031, 7.6286087, -10.246123, -2.3268178, - -1.8535945, 5.6277847, -4.0266237, 5.865689, 12.195534, 6.451518, 8.369051, - -1.9481331, 1.1049461, -6.0240774, -3.3728948, 0.11560962, -11.842209, -2.063498, - -2.36375, 4.902294, 15.913748, -8.045401, 1.4952235, -1.4233963, 0.23940584, - -2.360528, -4.6092496, -0.9090049, -3.2113476, -4.264017, -4.1235595, 9.532226, - 2.0181265, -0.15388536, -}; -static float y2[100] = { - -4.376235, -0.08368679, -0.6216589, -5.4909983, -0.04341768, 3.8880827, -6.337233, - -3.1458812, -3.9509559, 7.857975, -10.7834425, 4.5281, 0.9354341, -3.215732, - 3.4087672, -6.6825914, -6.841583, -0.00080897403, -4.719278, 2.5903013, 6.0486693, - 2.134149, 7.3574038, -0.2822968, 0.5588348, 0.9474025, 0.5909645, 0.1402733, - -1.3347642, 9.823734, 5.2648, -3.9894438, 5.6188626, 13.165532, 9.022314, - -3.3679013, 5.729391, 2.1637747, 2.0659118, -8.675354, 4.388403, -0.2468586, - 6.348771, 6.508556, -3.9684396, -11.304377, -13.8049965, 5.3364773, -4.633437, - 1.6888955, 2.6685429, 8.21828, -1.7674841, 10.709848, -5.9754534, -2.158992, - -4.8408647, 1.0743647, 2.2654505, -1.4429128, 8.646155, 4.9324765, 1.601925, - 4.0753536, -11.165701, -1.0478585, 6.369364, 2.2799797, -2.8299212, 10.3074255, - -6.802859, -1.543623, 0.73475134, -2.2130835, -4.313091, 9.970005, -1.3316114, - 0.12234986, -1.1443465, 0.31355476, 3.8333132, 4.4205723, -1.6774553, -2.464783, - 0.90474373, 1.48355, 6.109352, 0.6740269, -0.3855688, -1.1307039, -4.2242513, - -1.9623871, 4.5256195, 0.27741814, -10.554449, -9.463591, 4.7157593, 1.6424015, - -3.0457706, 1.535701, -}; -static float expected2[100] = { - -10.793994, -4.8195744, -11.696621, -9.775124, -6.219896, -2.2402952, -8.462534, - -1.3024157, -6.098612, 13.629044, -17.974234, 1.7565899, 4.232038, -7.488354, - 9.993664, -9.051899, -10.006039, 0.37701628, 0.49113083, 2.7724934, 2.9953713, - -1.3060579, 3.6611762, 0.8790928, 14.87136, 1.146844, -4.009571, 2.6497757, - -0.500006, 1.989419, 16.258339, -2.259667, 10.046939, 21.49504, 2.4838176, - -2.8874063, 6.5438747, 3.2833507, -1.9475923, -8.614389, 8.095892, 1.6406677, - 5.7794704, -4.2552953, 3.7180157, -17.952108, -11.554081, 6.8275247, 3.3552408, - -0.92592597, 6.9779844, 8.078672, -1.0251617, 20.891973, -10.519844, 5.788312, - -9.28295, -6.319727, 7.928982, -9.364451, 7.761645, 5.9507384, 2.5619707, - 6.1216645, -15.046351, -5.565029, 8.447395, 9.908588, -13.076044, 7.980608, - -8.656453, 4.0841618, -3.2918725, 3.6526053, 7.882443, 16.421524, 7.0374393, - -1.8257833, -0.03940034, -5.7105227, 0.46041846, 4.536182, -13.519664, -4.528281, - -1.4590063, 6.385844, 22.0231, -7.3713737, 1.1096547, -2.5541003, -3.9848454, - -4.322915, -0.083630085, -0.6315868, -13.765797, -13.727608, 0.5921998, 11.174627, - -1.0276442, 1.3818157, -}; -// 3. adding two vectors with RELU: 10 random numbers -static float x3[10] = { - 6.537531, -2.8453732, -7.6423984, 2.1252766, -0.19148353, - -0.8522757, -8.211992, -1.0764704, 2.3227465, 0.46851206, -}; -static float y3[10] = { - -0.14162672, 3.124883, 3.621642, 3.3335817, -2.766206, - 1.9977486, 3.4013243, 0.13386084, 1.7938671, 2.8548512, -}; -static float expected3[10] = { - 6.395904, 0.27950978, 0.0, 5.4588585, 0.0, 1.1454729, 0.0, 0.0, 4.1166134, 3.3233633, -}; -} // end of namespace add_vector_test -} // end of namespace nnfw - -// generated test case data -namespace nnfw -{ -namespace add_matrix_test -{ -// 1. adding two 2D[2, 6] matrixes -static float x_2d_1[2][6] = { - { - -11.781693, -4.353054, -1.671133, 10.070805, 3.2932477, 1.342311, - }, - { - 2.162408, -2.451811, 5.082188, -5.4572897, -1.2731916, -1.3220589, - }, -}; - -static float y_2d_1[2][6] = { - { - 0.34682792, -1.2904167, 2.3747947, -0.13805327, -2.2537446, 6.9882517, - }, - { - 0.56959796, 8.138776, -6.082614, -4.6445856, -9.0916, 2.8669918, - }, -}; - -static float expected_2d_1[2][6] = { - { - -11.434866, -5.643471, 0.7036617, 9.932752, 1.0395031, 8.330563, - }, - { - 2.732006, 5.686965, -1.0004258, -10.101875, -10.364792, 1.5449328, - }, -}; - -// 2. adding two 3D[2, 2, 6] matrixes -static float x_3d_1[2][2][6] = { - { - { - -11.739435, 3.5148015, -4.0006204, -6.298104, -10.34379, -4.218162, - }, - { - 2.9294286, 10.458075, 4.003835, 1.1951919, 8.921467, -10.444466, - }, - }, - { - { - -4.99484, -6.130513, 2.3629217, 2.4530737, 0.7031994, 1.1325712, - }, - { - -1.9382185, 7.0596004, 4.4672494, 6.1057587, -1.5707726, -0.6705226, - }, - }, -}; - -static float y_3d_1[2][2][6] = { - { - { - -3.1040814, -1.0521729, -4.827249, -2.6814535, 8.390884, 6.560555, - }, - { - -2.1659975, 0.056673903, -10.071791, -4.3230624, -1.1000388, -0.9773496, - }, - }, - { - { - 0.09476323, -0.34966075, 3.6764574, 2.6387796, 9.583742, -3.781064, - }, - { - -0.19952096, 0.09487678, 5.503623, -1.811995, -5.784617, 12.978241, - }, - }, -}; - -static float expected_3d_1[2][2][6] = { - { - { - -14.843516, 2.4626286, -8.827869, -8.979557, -1.9529057, 2.342393, - }, - { - 0.7634311, 10.514749, -6.0679555, -3.1278706, 7.8214283, -11.421815, - }, - }, - { - { - -4.900077, -6.480174, 6.039379, 5.091853, 10.286942, -2.6484928, - }, - { - -2.1377394, 7.154477, 9.970873, 4.2937636, -7.3553896, 12.307718, - }, - }, -}; - -// 3-1. adding 4D[2, 2, 2, 6] matrixes -static float x_4d_1[2][2][2][6] = { - { - { - { - 2.6673417, -3.3184788, -7.6855893, 1.1524531, 1.7560532, 1.2704719, - }, - { - 7.7395988, -0.43159193, -3.404647, -2.897906, 0.8337215, 2.3192573, - }, - }, - { - { - -0.7607416, -8.443049, 1.8729975, 0.4258421, -3.5612493, 0.7519802, - }, - { - -7.22534, -8.101532, 0.08998617, 2.0672836, 5.8741446, 4.933796, - }, - }, - }, - { - { - { - -0.46780592, 1.1179808, -2.3199582, 4.236184, -4.972879, 1.6885902, - }, - { - -7.988202, -2.1151643, 7.0348544, -8.694667, -6.4463015, 3.3260155, - }, - }, - { - { - 2.6043868, -2.024035, 1.5550058, 5.124688, -9.455877, 2.511424, - }, - { - -5.781496, -2.3239565, 3.2334518, 3.3922048, 1.0276179, -0.25160897, - }, - }, - }, -}; - -static float y_4d_1[2][2][2][6] = { - { - { - { - 6.899332, -4.625558, 2.4026396, 1.5354595, 2.529558, -2.3921616, - }, - { - -4.0143843, 3.4959526, -7.2878175, 1.7002666, 3.4354112, -6.5723968, - }, - }, - { - { - 5.7578554, 3.2505035, 7.3167043, 1.3117188, -3.0300832, -2.0495672, - }, - { - -0.53437704, -2.2179332, -8.540702, 4.858873, -0.6322088, -0.419879, - }, - }, - }, - { - { - { - -0.51388603, 5.262271, -15.592774, 3.2813377, 2.693888, 5.0646753, - }, - { - 1.041513, -3.6372566, 2.63006, -4.5404854, 5.7266, 1.6081405, - }, - }, - { - { - -4.7152123, -4.7401147, -6.324605, 4.678475, -0.75062823, 3.4201002, - }, - { - -1.8451585, -1.4765447, -2.5728178, -1.0178493, -4.7413797, 6.706836, - }, - }, - }, -}; - -static float expected_4d_1[2][2][2][6] = { - { - { - { - 9.566673, -7.9440365, -5.2829494, 2.6879125, 4.285611, -1.1216897, - }, - { - 3.7252145, 3.0643606, -10.692465, -1.1976395, 4.2691326, -4.2531395, - }, - }, - { - { - 4.9971137, -5.192546, 9.189702, 1.737561, -6.5913324, -1.297587, - }, - { - -7.759717, -10.319466, -8.450716, 6.9261565, 5.2419357, 4.513917, - }, - }, - }, - { - { - { - -0.98169196, 6.380252, -17.912733, 7.517522, -2.278991, 6.7532654, - }, - { - -6.946689, -5.752421, 9.664914, -13.235152, -0.7197013, 4.934156, - }, - }, - { - { - -2.1108255, -6.7641497, -4.769599, 9.803164, -10.206506, 5.9315243, - }, - { - -7.6266546, -3.8005013, 0.66063404, 2.3743553, -3.7137618, 6.4552274, - }, - }, - }, -}; - -} // end of namespace add_matrix_test -} // end of namespace nnfw - -#endif // __NNFW_KERNEL_ACL_ADD_TEST_H__ diff --git a/libs/kernel/acl/src/DepthwiseConv2D.h b/libs/kernel/acl/src/DepthwiseConv2D.h deleted file mode 100644 index 0aa5ee6..0000000 --- a/libs/kernel/acl/src/DepthwiseConv2D.h +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef __NNFW_KERNEL_ACL_DEPTHWISECONV2D_COMMON_H__ -#define __NNFW_KERNEL_ACL_DEPTHWISECONV2D_COMMON_H__ - -#include -#include -#include -#include - -#include "shape.h" -#include "IO_accessor.h" - -namespace nnfw -{ -namespace kernel -{ -namespace acl -{ - -namespace common -{ - -typedef std::function sync_scheduler_f; - -template -bool depthwiseConvFloat32(const float *inputData, const nnfw::rt::Shape &inputShape, - const float *filterData, const nnfw::rt::Shape &filterShape, - const float *biasData, const nnfw::rt::Shape &biasShape, - int32_t padding_left, int32_t padding_right, int32_t padding_top, - int32_t padding_bottom, int32_t stride_width, int32_t stride_height, - int32_t depth_multiplier, int32_t activation, float *outputData, - const nnfw::rt::Shape &outputShape, sync_scheduler_f sync_scheduler) -{ - auto inputShapeACL = util::fromNNShape(inputShape); - auto weightsShapeACL = util::fromNNShape(filterShape); - auto biasShapeACL = util::fromNNShape(biasShape); - auto outputShapeACL = util::fromNNShape(outputShape); - - TensorT input(arm_compute::TensorInfo(inputShapeACL, arm_compute::Format::F32)); - TensorT weights(arm_compute::TensorInfo(weightsShapeACL, arm_compute::Format::F32)); - TensorT bias(arm_compute::TensorInfo(biasShapeACL, arm_compute::Format::F32)); - TensorT output(arm_compute::TensorInfo(outputShapeACL, arm_compute::Format::F32)); - - arm_compute::PadStrideInfo psinfo = arm_compute::PadStrideInfo( - stride_width, stride_height, padding_left, padding_right, padding_top, padding_bottom, - arm_compute::DimensionRoundingType::FLOOR); - - auto l = std::make_shared(); - l->configure(input.ptr(), weights.ptr(), bias.ptr(), output.ptr(), psinfo); - - std::vector> fns; - - fns.emplace_back(l); - - util::insertFusedActivationLayer(output, activation, fns); - - input.allocate(); - output.allocate(); - bias.allocate(); - weights.allocate(); - - // TODO: Do we need 2D tensor accessor for the input feature? - TensorAccess(input.ref(), inputData, inputShape); - TensorAccess(bias.ref(), biasData, biasShape); - TensorAccess(weights.ref(), filterData, filterShape); - - for (const auto &fn : fns) - { - fn->run(); - } - - sync_scheduler(); - - TensorAccess(output.ref(), outputData, outputShape); - - return true; -} - -} // namespace common - -} // namespace acl -} // namespace kernel -} // namespace nnfw - -#endif // __NNFW_KERNEL_ACL_DEPTHWISECONV2D_COMMON_H__ diff --git a/libs/kernel/acl/src/DepthwiseConv2D.test.h b/libs/kernel/acl/src/DepthwiseConv2D.test.h deleted file mode 100644 index b459cd7..0000000 --- a/libs/kernel/acl/src/DepthwiseConv2D.test.h +++ /dev/null @@ -1,212 +0,0 @@ -/* - * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include - -// TODO: fix include path in CMakeFiles -#include "util.h" - -#ifndef ACL_TEST -#error "ACL_TEST should be defined first!" -#endif // ACL_TEST - -#ifndef ACL_CORE_FUNC_NAME -#error "ACL_CORE_FUNC_NAME should be defined first!" -#endif // ACL_CORE_FUNC_NAME - -using namespace nnfw::kernel::acl; - -ACL_TEST(KernelACL_TC, dwise_conv2d_1) -{ - uint32_t input_n = 1; - uint32_t input_h = 3; - uint32_t input_w = 3; - uint32_t input_c = 1; - uint32_t filter_h = 3; - uint32_t filter_w = 3; - uint32_t filter_c = 1; - uint32_t out_h = 1; - uint32_t out_w = 1; - - int32_t padding_left = 0; - int32_t padding_right = 0; - int32_t padding_top = 0; - int32_t padding_bottom = 0; - int32_t stride_width = 1; - int32_t stride_height = 1; - int32_t depth_multiplier = 1; - - util::TensorWrapper input({input_n, input_h, input_w, input_c}); - util::TensorWrapper weights({1, filter_h, filter_w, filter_c}); - util::TensorWrapper bias({filter_c}); - util::TensorWrapper output({1, out_h, out_w, filter_c}); - - int32_t activation = static_cast(FusedActivationFunc::RELU); - - input.initValue([&](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { - uint32_t N = input_n; - uint32_t H = input_h; - uint32_t W = input_w; - uint32_t C = input_c; - - return n * H * W * C + h * W * C + w * C + c; - }); - weights.initValue([&](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { - uint32_t N = 1; - uint32_t H = filter_h; - uint32_t W = filter_w; - uint32_t C = filter_c; - - return n * H * W * C + h * W * C + w * C + c; - }); - bias.initValue([](uint32_t w) { return 0.f; }); - output.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { return 0.f; }); - - bool bret = ACL_CORE_FUNC_NAME( - input.ptr(), input.shape(), weights.ptr(), weights.shape(), bias.ptr(), - bias.shape(), padding_left, padding_right, padding_top, padding_bottom, stride_width, - stride_height, depth_multiplier, activation, output.ptr(), output.shape()); - - EXPECT_EQ(bret, true); - - util::TensorWrapper expected({1, out_h, out_w, filter_c}); - expected.initValue([&](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { return 204.f; }); - - EXPECT_EQ(output, expected); -} - -ACL_TEST(KernelACL_TC, dwise_conv2d_multi_channel) -{ - uint32_t input_n = 1; - uint32_t input_h = 3; - uint32_t input_w = 3; - uint32_t input_c = 3; - uint32_t filter_h = 3; - uint32_t filter_w = 3; - uint32_t filter_c = input_c; - uint32_t out_h = 1; - uint32_t out_w = 1; - - int32_t padding_left = 0; - int32_t padding_right = 0; - int32_t padding_top = 0; - int32_t padding_bottom = 0; - int32_t stride_width = 1; - int32_t stride_height = 1; - int32_t depth_multiplier = 1; - - util::TensorWrapper input({input_n, input_h, input_w, input_c}); - util::TensorWrapper weights({1, filter_h, filter_w, filter_c}); - util::TensorWrapper bias({filter_c}); - util::TensorWrapper output({1, out_h, out_w, filter_c}); - - int32_t activation = static_cast(FusedActivationFunc::RELU); - - input.initValue([&](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { - uint32_t N = input_n; - uint32_t H = input_h; - uint32_t W = input_w; - uint32_t C = input_c; - - return n * H * W * C + h * W * C + w * C + c; - }); - weights.initValue([&](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { - uint32_t N = 1; - uint32_t H = filter_h; - uint32_t W = filter_w; - uint32_t C = filter_c; - - return n * H * W * C + h * W * C + w * C + c; - }); - bias.initValue([](uint32_t w) { return 0.f; }); - output.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { return 0.f; }); - - bool bret = ACL_CORE_FUNC_NAME( - input.ptr(), input.shape(), weights.ptr(), weights.shape(), bias.ptr(), - bias.shape(), padding_left, padding_right, padding_top, padding_bottom, stride_width, - stride_height, depth_multiplier, activation, output.ptr(), output.shape()); - - EXPECT_EQ(bret, true); - - util::TensorWrapper expected({1, out_h, out_w, filter_c}); - expected.initValue({1836.f, 2061.f, 2304.f}); - - EXPECT_EQ(output, expected); -} - -ACL_TEST(KernelACL_TC, dwise_conv2d_inception_1) -{ - uint32_t input_n = 1; - uint32_t input_h = 112; - uint32_t input_w = 112; - uint32_t input_c = 32; - uint32_t filter_h = 3; - uint32_t filter_w = 3; - uint32_t filter_c = input_c; - uint32_t out_h = 112; - uint32_t out_w = 112; - - int32_t padding_left = 1; - int32_t padding_right = 1; - int32_t padding_top = 1; - int32_t padding_bottom = 1; - int32_t stride_width = 1; - int32_t stride_height = 1; - int32_t depth_multiplier = 1; - - util::TensorWrapper input({input_n, input_h, input_w, input_c}); - util::TensorWrapper weights({1, filter_h, filter_w, filter_c}); - util::TensorWrapper bias({filter_c}); - util::TensorWrapper output({1, out_h, out_w, filter_c}); - - int32_t activation = static_cast(FusedActivationFunc::RELU6); - - input.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { return c; }); - weights.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { return c; }); - bias.initValue([](uint32_t w) { return 0.f; }); - output.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { return 0.f; }); - - bool bret = ACL_CORE_FUNC_NAME( - input.ptr(), input.shape(), weights.ptr(), weights.shape(), bias.ptr(), - bias.shape(), padding_left, padding_right, padding_top, padding_bottom, stride_width, - stride_height, depth_multiplier, activation, output.ptr(), output.shape()); - - EXPECT_EQ(bret, true); - - util::TensorWrapper expected({1, out_h, out_w, filter_c}); - expected.initValue([&](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { - float v = 9.f; - if (h == 0 || h == out_h - 1) - v -= 3.f; - if (w == 0 || w == out_w - 1) - v -= 3.f; - - // four corners - if ((w == 0 && h == 0) || (w == 0 && h == out_h - 1) || (w == out_w - 1 && h == 0) || - (w == out_w - 1 && h == out_h - 1)) - v += 1.f; - - // Assumption: negative numbers cannot appear because - // only positive numbers exist in the input and weights. - float ret = c * c * v; - return std::min(ret, 6.f); - }); - - EXPECT_EQ(output, expected); -} diff --git a/libs/kernel/acl/src/FullyConnected.h b/libs/kernel/acl/src/FullyConnected.h deleted file mode 100644 index f04f91a..0000000 --- a/libs/kernel/acl/src/FullyConnected.h +++ /dev/null @@ -1,156 +0,0 @@ -/* - * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef __NNFW_KERNEL_ACL_FULLYCONNECTED_COMMON_H__ -#define __NNFW_KERNEL_ACL_FULLYCONNECTED_COMMON_H__ - -#include -#include -#include -#include - -#include "shape.h" -#include "IO_accessor.h" - -namespace nnfw -{ -namespace kernel -{ -namespace acl -{ - -namespace common -{ - -typedef std::function sync_scheduler_f; - -template -bool fullyConnectedFloat32(const float *inputData, const nnfw::rt::Shape &inputShape, - const float *weightsData, const nnfw::rt::Shape &weightsShape, - const float *biasData, const nnfw::rt::Shape &biasShape, - int32_t activation, float *outputData, - const nnfw::rt::Shape &outputShape, sync_scheduler_f sync_scheduler) -{ - - // NNAPI specification: - // https://developer.android.com/ndk/reference/group___neural_networks.html#ggaabbe492c60331b13038e39d4207940e0aaada7a3dbaf4676aba560c933ff610c5 - - // According to the NNAPI Specification, - // INPUT - // 1. input rank is up to 4. - // 2. if input rank > 2, it is flattened to rank 2 [batch_size, input_size] - nnfw::rt::Shape flattenedInputShape = inputShape; - switch (inputShape.dimensions.size()) - { - case 1: - { - assert("Need to be implemented." && 0); - break; - } - case 2: - { - // DO NOTHING. - break; - } - case 3: - { - assert("Need to be implemented." && 0); - break; - } - case 4: - { - auto N = inputShape.dimensions[0]; - auto H = inputShape.dimensions[1]; - auto W = inputShape.dimensions[2]; - auto C = inputShape.dimensions[3]; - flattenedInputShape.dimensions = {N, H * W * C}; - break; - } - default: - assert(inputShape.dimensions.size() <= 4); - } - // Finally, flattenedInputShape is a 2D tensor. - - // WEIGHTS is a 2D tensor - assert(weightsShape.dimensions.size() == 2); - - // BIAS is a 1D tensor - assert(biasShape.dimensions.size() == 1); - - // OUTPUT is a 2D tensor. - assert(outputShape.dimensions.size() == 2); - - auto input_shape = util::fromNNShape(flattenedInputShape); - auto weights_shape = util::fromNNShape(weightsShape); - auto bias_shape = util::fromNNShape(biasShape); - auto output_shape = util::fromNNShape(outputShape); - - assert(activation == ANEURALNETWORKS_FUSED_NONE || activation == ANEURALNETWORKS_FUSED_RELU); - - std::vector> fns; - - TensorT input(arm_compute::TensorInfo(input_shape, arm_compute::Format::F32)); - TensorT output(arm_compute::TensorInfo(output_shape, arm_compute::Format::F32)); - TensorT bias(arm_compute::TensorInfo(bias_shape, arm_compute::Format::F32)); - TensorT weights(arm_compute::TensorInfo(weights_shape, arm_compute::Format::F32)); - - auto fc = std::make_shared(); - fc->configure(input.ptr(), weights.ptr(), bias.ptr(), output.ptr()); - - fns.emplace_back(fc); - - if (ANEURALNETWORKS_FUSED_RELU == activation) - { - auto relu_f = std::make_shared(); - - const arm_compute::ActivationLayerInfo relu_info{ - arm_compute::ActivationLayerInfo::ActivationFunction::RELU}; - - // Do in-place update - relu_f->configure(output.ptr(), nullptr, relu_info); - - fns.emplace_back(relu_f); - } - - input.allocate(); - output.allocate(); - bias.allocate(); - weights.allocate(); - - // TODO: Do we need 2D tensor accessor for the input feature? - TensorAccess(input.ref(), inputData, inputShape); - TensorAccess(bias.ref(), biasData, biasShape); - TensorAccess(weights.ref(), weightsData, weightsShape); - - for (const auto &fn : fns) - { - fn->run(); - } - - sync_scheduler(); - - TensorAccess(output.ref(), outputData, outputShape); - - return true; -} - -} // namespace common - -} // namespace acl -} // namespace kernel -} // namespace nnfw - -#endif // __NNFW_KERNEL_ACL_FULLYCONNECTED_COMMON_H__ diff --git a/libs/kernel/acl/src/FullyConnected.test.h b/libs/kernel/acl/src/FullyConnected.test.h deleted file mode 100644 index 7c64e74..0000000 --- a/libs/kernel/acl/src/FullyConnected.test.h +++ /dev/null @@ -1,211 +0,0 @@ -/* - * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include - -// TODO: fix include path in CMakeFiles -#include "util.h" - -#ifndef ACL_TEST -#error "ACL_TEST should be defined first!" -#endif // ACL_TEST - -#ifndef ACL_CORE_FUNC_NAME -#error "ACL_CORE_FUNC_NAME should be defined first!" -#endif // ACL_CORE_FUNC_NAME - -using namespace nnfw::kernel::acl; -using fullyConnectedFloat32T = bool (*)(const float *inputData, const nnfw::rt::Shape &inputShape, - const float *weightsData, - const nnfw::rt::Shape &weightsShape, const float *biasData, - const nnfw::rt::Shape &biasShape, int32_t activation, - float *outputData, const nnfw::rt::Shape &outputShape); - -ACL_TEST(KernelACL_TC, fcFloat32_1) -{ - - util::TensorWrapper input({1, 1, 1, 100}); - util::TensorWrapper weights({1, 100}); - util::TensorWrapper bias({1}); - util::TensorWrapper output({1, 1}); - - int32_t activation = static_cast(FusedActivationFunc::RELU); - - input.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { return 1.f; }); - weights.initValue([](uint32_t h, uint32_t w) { return 1.f; }); - bias.initValue([](uint32_t w) { return 0.f; }); - output.initValue([](uint32_t h, uint32_t w) { return 0.f; }); - - bool bret = ACL_CORE_FUNC_NAME(input.ptr(), input.shape(), weights.ptr(), - weights.shape(), bias.ptr(), bias.shape(), activation, - output.ptr(), output.shape()); - - EXPECT_EQ(bret, true); - - util::TensorWrapper expected({1, 1}); - expected.initValue([](uint32_t h, uint32_t w) { return 100.f; }); - - EXPECT_EQ(output, expected); -} - -ACL_TEST(KernelACL_TC, fcFloat32_relu) -{ - - util::TensorWrapper input({1, 1, 1, 100}); - util::TensorWrapper weights({1, 100}); - util::TensorWrapper bias({1}); - util::TensorWrapper output({1, 1}); - - int32_t activation = static_cast(FusedActivationFunc::RELU); - - input.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { return 1.f; }); - weights.initValue([](uint32_t h, uint32_t w) { return -1.f; }); - bias.initValue([](uint32_t w) { return 0.f; }); - output.initValue([](uint32_t h, uint32_t w) { return 0.f; }); - - bool bret = ACL_CORE_FUNC_NAME(input.ptr(), input.shape(), weights.ptr(), - weights.shape(), bias.ptr(), bias.shape(), activation, - output.ptr(), output.shape()); - - EXPECT_EQ(bret, true); - - util::TensorWrapper expected({1, 1}); - expected.initValue([](uint32_t h, uint32_t w) { return 0.f; }); - - EXPECT_EQ(output, expected); -} - -ACL_TEST(KernelACL_TC, fcFloat32_conv_fc) -{ - uint32_t input_n = 1; - uint32_t input_c = 5; - uint32_t input_h = 4; - uint32_t input_w = 4; - uint32_t weight_n = 6; - - int32_t activation = static_cast(FusedActivationFunc::RELU); - - util::TensorWrapper input({input_n, input_h, input_w, input_c}); - util::TensorWrapper weight({weight_n, input_c * input_h * input_w}); - util::TensorWrapper bias({weight_n}); - util::TensorWrapper output({1, weight_n}); - - input.initValue([&](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { - uint32_t N = input_n; - uint32_t H = input_h; - uint32_t W = input_w; - uint32_t C = input_c; - - return n * H * W * C + h * W * C + w * C + c; - }); - - weight.initValue([&](uint32_t h, uint32_t w) { - uint32_t H = weight_n; - uint32_t W = input_c * input_h * input_w; - - return h * W + w; - }); - - bias.initValue([](uint32_t w) { return 0.f; }); - - output.initValue([](uint32_t h, uint32_t w) { return 0.f; }); - - bool bret = ACL_CORE_FUNC_NAME(input.ptr(), input.shape(), weight.ptr(), - weight.shape(), bias.ptr(), bias.shape(), activation, - output.ptr(), output.shape()); - - EXPECT_EQ(bret, true); - - util::TensorWrapper expected({1, weight_n}); - expected.initValue({167480.f, 420280.f, 673080.f, 925880.f, 1178680.f, 1431480.f}); - - EXPECT_EQ(output, expected); -} - -ACL_TEST(KernelACL_TC, fcFloat32_fc_fc) -{ - uint32_t input_n = 6; - uint32_t weight_n = 6; - - int32_t activation = static_cast(FusedActivationFunc::RELU); - - util::TensorWrapper input({1, input_n}); - util::TensorWrapper weight({weight_n, input_n}); - util::TensorWrapper bias({weight_n}); - util::TensorWrapper output({1, weight_n}); - - input.initValue([&](uint32_t h, uint32_t w) { - // not use h because h = 0. - return (float)w; - }); - - weight.initValue([&](uint32_t h, uint32_t w) { - uint32_t H = weight_n; - uint32_t W = input_n; - - return (float)(h * W + w); - }); - - bias.initValue([](uint32_t w) { return 0.f; }); - - output.initValue([](uint32_t h, uint32_t w) { return 0.f; }); - - bool bret = ACL_CORE_FUNC_NAME(input.ptr(), input.shape(), weight.ptr(), - weight.shape(), bias.ptr(), bias.shape(), activation, - output.ptr(), output.shape()); - - EXPECT_EQ(bret, true); - - util::TensorWrapper expected({1, weight_n}); - expected.initValue({ - 55.f, 145.f, 235.f, 325.f, 415.f, 505.f, - }); - - EXPECT_EQ(output, expected); -} - -ACL_TEST(KernelACL_TC, fcFloat32_inceptionv3) -{ - - uint32_t input_c = 2048; - uint32_t weight_n = 1008; - - util::TensorWrapper input({1, 1, 1, input_c}); - util::TensorWrapper weight({weight_n, input_c}); - util::TensorWrapper bias({weight_n}); - util::TensorWrapper output({1, weight_n}); - - int32_t activation = static_cast(FusedActivationFunc::RELU); - - input.initValue([&](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { return 1.f; }); - weight.initValue([&](uint32_t h, uint32_t w) { return (float)h; }); - bias.initValue([](uint32_t w) { return 0.f; }); - output.initValue([](uint32_t h, uint32_t w) { return 0.f; }); - - bool bret = ACL_CORE_FUNC_NAME(input.ptr(), input.shape(), weight.ptr(), - weight.shape(), bias.ptr(), bias.shape(), activation, - output.ptr(), output.shape()); - - EXPECT_EQ(bret, true); - - util::TensorWrapper expected({1, weight_n}); - expected.initValue([&](uint32_t h, uint32_t w) { return w * input_c; }); - - EXPECT_EQ(output, expected); -} diff --git a/libs/kernel/acl/src/IO_accessor.cpp b/libs/kernel/acl/src/IO_accessor.cpp deleted file mode 100644 index 2046ba9..0000000 --- a/libs/kernel/acl/src/IO_accessor.cpp +++ /dev/null @@ -1,363 +0,0 @@ -/* - * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "IO_accessor.h" - -#include -#include - -namespace nnfw -{ -namespace kernel -{ -namespace acl -{ - -InputAccessor::InputAccessor(const float *inputData, const nnfw::rt::Shape &inputShape) - : _inputData(inputData), _inputShape(inputShape) -{ -} - -MatrixInputAccessor::MatrixInputAccessor(const float *inputData, const nnfw::rt::Shape &inputShape) - : _inputData(inputData), _inputShape(inputShape) -{ -} - -VectorInputAccessor::VectorInputAccessor(const float *inputData, const nnfw::rt::Shape &inputShape) - : _inputData(inputData), _inputShape(inputShape) -{ -} - -WeightAccessor::WeightAccessor(const float *filterData, const nnfw::rt::Shape &filterShape) - : _filterData(filterData), _filterShape(filterShape) -{ -} - -MatrixWeightAccessor::MatrixWeightAccessor(const float *filterData, - const nnfw::rt::Shape &filterShape) - : _filterData(filterData), _filterShape(filterShape) -{ -} - -BiasAccessor::BiasAccessor(const float *biasData, const nnfw::rt::Shape &biasShape) - : _biasData(biasData), _biasShape(biasShape) -{ -} - -OutputAccessor::OutputAccessor(float *outputData, const nnfw::rt::Shape &outputShape) - : _outputData(outputData), _outputShape(outputShape) -{ -} - -MatrixOutputAccessor::MatrixOutputAccessor(float *outputData, const nnfw::rt::Shape &outputShape) - : _outputData(outputData), _outputShape(outputShape) -{ -} - -VectorOutputAccessor::VectorOutputAccessor(float *outputData, const nnfw::rt::Shape &outputShape) - : _outputData(outputData), _outputShape(outputShape) -{ -} - -static uint32_t getOffsetNCHW(const nnfw::rt::Shape &shape, const arm_compute::Coordinates &id) -{ - // get offset for ACL(NCHW) from data of NNAPI(NHWC) - uint32_t num = getSizeOfDimension(shape, 0); - uint32_t height = getSizeOfDimension(shape, 1); - uint32_t width = getSizeOfDimension(shape, 2); - uint32_t chann = getSizeOfDimension(shape, 3); - uint32_t stride = 1; - uint32_t offset = 0; - uint32_t numdim = id.num_dimensions(); - offset += numdim > 0 ? id[0] * stride : 0; - stride *= width; - offset += numdim > 1 ? id[1] * stride : 0; - stride *= height; - offset += numdim > 2 ? id[2] * stride : 0; - stride *= chann; - offset += numdim > 3 ? id[3] * stride : 0; - stride *= num; - return offset; -} - -static uint32_t getElementOffset(const nnfw::rt::Shape &shape, uint32_t ch, uint32_t row, - uint32_t col) -{ - assert(getSizeOfDimension(shape, 0) == 1); - assert(shape.dimensions.size() == 4); - - // TODO Optimize this! - const uint32_t W = getSizeOfDimension(shape, 2); - const uint32_t C = getSizeOfDimension(shape, 3); - - int offset = 0; - - // NNAPI uses NHWC ordering - offset += row * W * C; - offset += col * C; - offset += ch; - - return offset; -} - -static uint32_t getElementOffset(const nnfw::rt::Shape &shape, uint32_t nth, uint32_t ch, - uint32_t row, uint32_t col) -{ - assert(shape.dimensions.size() == 4); - - // TODO Optimize this! - const uint32_t H = getSizeOfDimension(shape, 1); - const uint32_t W = getSizeOfDimension(shape, 2); - const uint32_t C = getSizeOfDimension(shape, 3); - - int offset = 0; - - // NNAPI uses NHWC ordering - offset += nth * H * W * C; - offset += row * W * C; - offset += col * C; - offset += ch; - - return offset; -} - -bool InputAccessor::access_tensor(arm_compute::ITensor &tensor) -{ - arm_compute::Window window; - window.use_tensor_dimensions(tensor.info()->tensor_shape()); - - execute_window_loop(window, [&](const arm_compute::Coordinates &id) { - const uint32_t nth = id[3]; - const uint32_t ch = id[2]; - const uint32_t row = id[1]; - const uint32_t col = id[0]; - - uint32_t offset = getElementOffset(_inputShape, nth, ch, row, col); - - *reinterpret_cast(tensor.ptr_to_element(id)) = *(_inputData + offset); - }); - return true; -} - -bool MatrixInputAccessor::access_tensor(arm_compute::ITensor &tensor) -{ - arm_compute::Window window; - window.use_tensor_dimensions(tensor.info()->tensor_shape()); - - assert(tensor.info()->tensor_shape().num_dimensions() <= 4); - - // Note: if "= 2" is used instead of "<= 2", KernelACL_TC.softmaxFloat32_1xn fails. - if (tensor.info()->tensor_shape().num_dimensions() <= 2) // [ row * col ] tensor - { - execute_window_loop(window, [&](const arm_compute::Coordinates &id) { - const auto row = id[1]; - const auto col = id[0]; - const auto W = tensor.info()->tensor_shape().x(); - - const auto offset = row * W + col; - - *reinterpret_cast(tensor.ptr_to_element(id)) = *(_inputData + offset); - }); - } - else if (tensor.info()->tensor_shape().num_dimensions() == 3) // [ n * row * col ] tensor - { - execute_window_loop(window, [&](const arm_compute::Coordinates &id) { - const auto n = id[2]; - const auto row = id[1]; - const auto col = id[0]; - const auto W = tensor.info()->tensor_shape().x(); - const auto numIn_rc = tensor.info()->tensor_shape().x() * tensor.info()->tensor_shape().y(); - - const auto offset = (numIn_rc * n) + (row * W) + col; - - *reinterpret_cast(tensor.ptr_to_element(id)) = *(_inputData + offset); - }); - } - else if (tensor.info()->tensor_shape().num_dimensions() == 4) // [ m * n * row * col ] tensor - { - const auto numIn1d = tensor.info()->tensor_shape()[0]; - const auto numIn2d = numIn1d * tensor.info()->tensor_shape()[1]; - const auto numIn3d = numIn2d * tensor.info()->tensor_shape()[2]; - - execute_window_loop(window, [&](const arm_compute::Coordinates &id) { - const auto m = id[3]; - const auto n = id[2]; - const auto row = id[1]; - const auto col = id[0]; - - const auto offset = (numIn3d * m) + (numIn2d * n) + (numIn1d * row) + col; - - *reinterpret_cast(tensor.ptr_to_element(id)) = *(_inputData + offset); - }); - } - return true; -} - -bool VectorInputAccessor::access_tensor(arm_compute::ITensor &tensor) -{ - arm_compute::Window window; - window.use_tensor_dimensions(tensor.info()->tensor_shape()); - - assert(tensor.info()->tensor_shape().num_dimensions() == 1); - - execute_window_loop(window, [&](const arm_compute::Coordinates &id) { - uint32_t offset = id[0]; - - *reinterpret_cast(tensor.ptr_to_element(id)) = *(_inputData + offset); - }); - return true; -} - -bool WeightAccessor::access_tensor(arm_compute::ITensor &tensor) -{ - arm_compute::Window window; - window.use_tensor_dimensions(tensor.info()->tensor_shape()); - - execute_window_loop(window, [&](const arm_compute::Coordinates &id) { - const uint32_t nth = id[3]; - const uint32_t ch = id[2]; - const uint32_t row = id[1]; - const uint32_t col = id[0]; - - uint32_t offset = getElementOffset(_filterShape, nth, ch, row, col); - - *reinterpret_cast(tensor.ptr_to_element(id)) = *(_filterData + offset); - }); - return true; -} - -bool MatrixWeightAccessor::access_tensor(arm_compute::ITensor &tensor) -{ - arm_compute::Window window; - window.use_tensor_dimensions(tensor.info()->tensor_shape()); - - assert(tensor.info()->tensor_shape().num_dimensions() <= 2); - - execute_window_loop(window, [&](const arm_compute::Coordinates &id) { - const auto row = id[1]; - const auto col = id[0]; - const auto W = tensor.info()->tensor_shape().x(); - - uint32_t offset = row * W + col; - - *reinterpret_cast(tensor.ptr_to_element(id)) = *(_filterData + offset); - }); - return true; -} - -bool BiasAccessor::access_tensor(arm_compute::ITensor &tensor) -{ - arm_compute::Window window; - window.use_tensor_dimensions(tensor.info()->tensor_shape()); - - execute_window_loop(window, [&](const arm_compute::Coordinates &id) { - uint32_t offset = getOffsetNCHW(_biasShape, id); - *reinterpret_cast(tensor.ptr_to_element(id)) = *(_biasData + offset); - }); - return true; -} - -bool OutputAccessor::access_tensor(arm_compute::ITensor &tensor) -{ - arm_compute::Window window; - window.use_tensor_dimensions(tensor.info()->tensor_shape()); - - execute_window_loop(window, [&](const arm_compute::Coordinates &id) { - const uint32_t nth = id[3]; - const uint32_t ch = id[2]; - const uint32_t row = id[1]; - const uint32_t col = id[0]; - - uint32_t offset = getElementOffset(_outputShape, nth, ch, row, col); - - *(_outputData + offset) = *reinterpret_cast(tensor.ptr_to_element(id)); - }); - return false; // end the network -} - -bool VectorOutputAccessor::access_tensor(arm_compute::ITensor &tensor) -{ - arm_compute::Window window; - window.use_tensor_dimensions(tensor.info()->tensor_shape()); - - assert(tensor.info()->tensor_shape().num_dimensions() == 1); - - execute_window_loop(window, [&](const arm_compute::Coordinates &id) { - const uint32_t x = id[0]; - - uint32_t offset = x; - - *(_outputData + offset) = *reinterpret_cast(tensor.ptr_to_element(id)); - }); - return false; // end the network -} - -bool MatrixOutputAccessor::access_tensor(arm_compute::ITensor &tensor) -{ - arm_compute::Window window; - window.use_tensor_dimensions(tensor.info()->tensor_shape()); - - assert(tensor.info()->tensor_shape().num_dimensions() <= 4); - - if (tensor.info()->tensor_shape().num_dimensions() <= 2) // [ row * col ] tensor - { - execute_window_loop(window, [&](const arm_compute::Coordinates &id) { - const auto row = id[1]; - const auto col = id[0]; - const auto W = tensor.info()->tensor_shape().x(); - - const auto offset = row * W + col; - - *(_outputData + offset) = *reinterpret_cast(tensor.ptr_to_element(id)); - }); - } - else if (tensor.info()->tensor_shape().num_dimensions() == 3) // [ n * row * col ] tensor - { - execute_window_loop(window, [&](const arm_compute::Coordinates &id) { - const auto n = id[2]; - const auto row = id[1]; - const auto col = id[0]; - const auto W = tensor.info()->tensor_shape().x(); - const auto numIn_rc = tensor.info()->tensor_shape().x() * tensor.info()->tensor_shape().y(); - - const auto offset = (numIn_rc * n) + (row * W) + col; - - *(_outputData + offset) = *reinterpret_cast(tensor.ptr_to_element(id)); - }); - } - else if (tensor.info()->tensor_shape().num_dimensions() == 4) // [ m * n * row * col ] tensor - { - const auto numIn1d = tensor.info()->tensor_shape()[0]; - const auto numIn2d = numIn1d * tensor.info()->tensor_shape()[1]; - const auto numIn3d = numIn2d * tensor.info()->tensor_shape()[2]; - - execute_window_loop(window, [&](const arm_compute::Coordinates &id) { - const auto m = id[3]; - const auto n = id[2]; - const auto row = id[1]; - const auto col = id[0]; - - const auto offset = (numIn3d * m) + (numIn2d * n) + (numIn1d * row) + col; - - *(_outputData + offset) = *reinterpret_cast(tensor.ptr_to_element(id)); - }); - } - return false; // end the network -} - -} // namespace acl -} // namespace kernel -} // namespace nnfw diff --git a/libs/kernel/acl/src/IO_accessor.h b/libs/kernel/acl/src/IO_accessor.h deleted file mode 100644 index ad53cc5..0000000 --- a/libs/kernel/acl/src/IO_accessor.h +++ /dev/null @@ -1,197 +0,0 @@ -/* - * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef __NNFW_KERNEL_ACL_IO_ACCESSOR_H__ -#define __NNFW_KERNEL_ACL_IO_ACCESSOR_H__ - -#include -#include -#include - -#include // for nnfw::rt::Shape - -namespace nnfw -{ -namespace kernel -{ -namespace acl -{ - -class InputAccessor : public arm_compute::graph::ITensorAccessor -{ -public: - InputAccessor(const float *inputData, const nnfw::rt::Shape &inputShape); - InputAccessor(InputAccessor &&) = default; - - // Inherited methods overriden: - bool access_tensor(arm_compute::ITensor &tensor) override; - -private: - const float *_inputData; - const nnfw::rt::Shape &_inputShape; -}; - -class MatrixInputAccessor : public arm_compute::graph::ITensorAccessor -{ -public: - MatrixInputAccessor(const float *inputData, const nnfw::rt::Shape &inputShape); - MatrixInputAccessor(MatrixInputAccessor &&) = default; - - // Inherited methods overriden: - bool access_tensor(arm_compute::ITensor &tensor) override; - -private: - const float *_inputData; - const nnfw::rt::Shape &_inputShape; -}; - -class VectorInputAccessor : public arm_compute::graph::ITensorAccessor -{ -public: - VectorInputAccessor(const float *inputData, const nnfw::rt::Shape &inputShape); - VectorInputAccessor(VectorInputAccessor &&) = default; - - // Inherited methods overriden: - bool access_tensor(arm_compute::ITensor &tensor) override; - -private: - const float *_inputData; - const nnfw::rt::Shape &_inputShape; -}; - -class WeightAccessor : public arm_compute::graph::ITensorAccessor -{ -public: - WeightAccessor(const float *filterData, const nnfw::rt::Shape &filterShape); - WeightAccessor(WeightAccessor &&) = default; - - // Inherited methods overriden: - bool access_tensor(arm_compute::ITensor &tensor) override; - -private: - const float *_filterData; - const nnfw::rt::Shape &_filterShape; -}; - -class MatrixWeightAccessor : public arm_compute::graph::ITensorAccessor -{ -public: - MatrixWeightAccessor(const float *filterData, const nnfw::rt::Shape &filterShape); - MatrixWeightAccessor(MatrixWeightAccessor &&) = default; - - // Inherited methods overriden: - bool access_tensor(arm_compute::ITensor &tensor) override; - -private: - const float *_filterData; - const nnfw::rt::Shape &_filterShape; -}; - -class BiasAccessor : public arm_compute::graph::ITensorAccessor -{ -public: - BiasAccessor(const float *biasData, const nnfw::rt::Shape &biasShape); - BiasAccessor(BiasAccessor &&) = default; - - // Inherited methods overriden: - bool access_tensor(arm_compute::ITensor &tensor) override; - -private: - const float *_biasData; - const nnfw::rt::Shape &_biasShape; -}; - -class OutputAccessor : public arm_compute::graph::ITensorAccessor -{ -public: - OutputAccessor(float *outputData, const nnfw::rt::Shape &outputShape); - OutputAccessor(OutputAccessor &&) = default; - - // Inherited methods overriden: - bool access_tensor(arm_compute::ITensor &tensor) override; - -private: - float *_outputData; - const nnfw::rt::Shape &_outputShape; -}; - -class MatrixOutputAccessor : public arm_compute::graph::ITensorAccessor -{ -public: - MatrixOutputAccessor(float *outputData, const nnfw::rt::Shape &outputShape); - MatrixOutputAccessor(MatrixOutputAccessor &&) = default; - - // Inherited methods overriden: - bool access_tensor(arm_compute::ITensor &tensor) override; - -private: - float *_outputData; - const nnfw::rt::Shape &_outputShape; -}; - -class VectorOutputAccessor : public arm_compute::graph::ITensorAccessor -{ -public: - VectorOutputAccessor(float *outputData, const nnfw::rt::Shape &outputShape); - VectorOutputAccessor(VectorOutputAccessor &&) = default; - - // Inherited methods overriden: - bool access_tensor(arm_compute::ITensor &tensor) override; - -private: - float *_outputData; - const nnfw::rt::Shape &_outputShape; -}; - -template -inline void TensorAccess(arm_compute::CLTensor &tensor, const float *data, - const nnfw::rt::Shape &shape) -{ - tensor.map(); - AccessorType accessor(data, shape); - accessor.access_tensor(tensor); - tensor.unmap(); -} - -template -inline void TensorAccess(arm_compute::CLTensor &tensor, float *data, const nnfw::rt::Shape &shape) -{ - tensor.map(); - AccessorType accessor(data, shape); - accessor.access_tensor(tensor); - tensor.unmap(); -} - -template -inline void TensorAccess(arm_compute::Tensor &tensor, const float *data, - const nnfw::rt::Shape &shape) -{ - AccessorType accessor(data, shape); - accessor.access_tensor(tensor); -} - -template -inline void TensorAccess(arm_compute::Tensor &tensor, float *data, const nnfw::rt::Shape &shape) -{ - AccessorType accessor(data, shape); - accessor.access_tensor(tensor); -} - -} // namespace acl -} // namespace kernel -} // namespace nnfw - -#endif // __NNFW_KERNEL_ACL_IO_ACCESSOR_H__ diff --git a/libs/kernel/acl/src/Init_acl.cpp b/libs/kernel/acl/src/Init_acl.cpp deleted file mode 100644 index c2c8d79..0000000 --- a/libs/kernel/acl/src/Init_acl.cpp +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include - -namespace nnfw -{ -namespace kernel -{ -namespace acl -{ - -// This will do one time initialization but can be called multiple times -void Initialize(void) { arm_compute::CLScheduler::get().default_init(); } - -} // namespace acl -} // namespace kernel -} // namespace nnfw diff --git a/libs/kernel/acl/src/Mul.h b/libs/kernel/acl/src/Mul.h deleted file mode 100644 index 376bac7..0000000 --- a/libs/kernel/acl/src/Mul.h +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef __NNFW_KERNEL_ACL_MUL_COMMON_H__ -#define __NNFW_KERNEL_ACL_MUL_COMMON_H__ - -#include -#include -#include - -// TODO: fix include path in CMakeFiles -#include "IO_accessor.h" -#include "shape.h" -#include "UniqueTensor.h" -#include "util.h" - -namespace nnfw -{ -namespace kernel -{ -namespace acl -{ -namespace common -{ -typedef std::function sync_scheduler_f; - -// Element-wise multiplication -// -// Note : arm_compute::NEPixelWiseMultiplication.config() in neon/Mul.test.h fails -// when the shapes of a and b of Mul(a, b) are different. -// arm_compute::CLPixelWiseMultiplication.config() in cl/Mul.test.h is OK -// with different shapes of a and b of Mul(a, b). -// for example, a's shape = [3, 2, 6], b's shape = [6] can be elementwise-multiplied -// with cl/Mul.test.h -// -// TODO : current version support upto 3D multiplication -template -bool mulFloat32(const float *inputData1, const nnfw::rt::Shape &inputShape1, - const float *inputData2, const nnfw::rt::Shape &inputShape2, int32_t activation, - float *outputData, const nnfw::rt::Shape &outputShape, sync_scheduler_f sync_func) -{ - auto input_shape1 = util::fromNNShape(inputShape1, false); - auto input_shape2 = util::fromNNShape(inputShape2, false); - auto output_shape = util::fromNNShape(outputShape, false); - - TensorT input1(arm_compute::TensorInfo(input_shape1, arm_compute::Format::F32)); - TensorT input2(arm_compute::TensorInfo(input_shape2, arm_compute::Format::F32)); - TensorT output(arm_compute::TensorInfo(output_shape, arm_compute::Format::F32)); - - std::vector> fns; - - auto mul_f = std::make_shared(); - - // TODO: Regarding converting policy and rounding rule, check which is appropriate. - mul_f->configure( - input1.ptr(), input2.ptr(), output.ptr(), - 1.0, // scale - arm_compute::ConvertPolicy::SATURATE, // overflow will be FLTMAX, underflow will be FLTMIN - arm_compute::RoundingPolicy::TO_ZERO); - - fns.emplace_back(mul_f); - - util::insertFusedActivationLayer(output, activation, fns); - input1.allocate(); - input2.allocate(); - output.allocate(); - - if (inputShape1.dimensions.size() == 1) - { - TensorAccess(input1.ref(), inputData1, inputShape1); - } - else if ((inputShape1.dimensions.size() <= 4)) - { - TensorAccess(input1.ref(), inputData1, inputShape1); - } - else - assert(inputShape1.dimensions.size() <= 4); - - if (inputShape2.dimensions.size() == 1) - { - TensorAccess(input2.ref(), inputData2, inputShape2); - } - else if ((inputShape2.dimensions.size() <= 4)) - { - TensorAccess(input2.ref(), inputData2, inputShape2); - } - else - assert(inputShape2.dimensions.size() <= 4); - - for (const auto &fn : fns) - { - fn->run(); - } - - sync_func(); - - if (outputShape.dimensions.size() == 1) - { - TensorAccess(output.ref(), outputData, outputShape); - } - else if ((outputShape.dimensions.size() <= 4)) - { - TensorAccess(output.ref(), outputData, outputShape); - } - else - assert(outputShape.dimensions.size() <= 4); - - return true; -} - -} // namespace common -} // namespace acl -} // namespace kernel -} // namespace nnfw - -#endif // __NNFW_KERNEL_ACL_MUL_COMMON_H__ diff --git a/libs/kernel/acl/src/Mul.test.data.h b/libs/kernel/acl/src/Mul.test.data.h deleted file mode 100644 index 617aafc..0000000 --- a/libs/kernel/acl/src/Mul.test.data.h +++ /dev/null @@ -1,387 +0,0 @@ -/* - * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef __NNFW_KERNEL_ACL_ELEMENTWISE_MUL_TEST_H__ -#define __NNFW_KERNEL_ACL_ELEMENTWISE_MUL_TEST_H__ - -// generated test case data -namespace nnfw -{ -namespace elementwise_mul_test -{ -namespace td // test data -{ -// 1. elementwise-multiplying simple 3d x 1d -static float x1[6][1][4] = { - { - { - -6.3646917, -1.3678346, 1.4450488, -7.1651864, - }, - }, - { - { - -3.5606036, -0.36702245, -1.4057153, -5.9415154, - }, - }, - { - { - 5.4971604, 0.75693905, -3.9440963, -0.9556505, - }, - }, - { - { - -1.4454491, 3.9991646, -3.05788, -3.6598186, - }, - }, - { - { - -5.644329, -0.46533433, -3.8069267, -3.024848, - }, - }, - { - { - 3.1927416, 1.7534385, 2.7138062, -2.0129197, - }, - }, -}; - -static float y1[4] = { - 0.8061577, 0.84572744, -7.505205, -5.159459, -}; - -static float expected1[6][1][4] = { - { - { - -5.130945, -1.1568153, -10.845387, 36.968487, - }, - }, - { - { - -2.870408, -0.31040096, 10.550182, 30.655006, - }, - }, - { - { - 4.431578, 0.64016414, 29.601252, 4.9306397, - }, - }, - { - { - -1.16526, 3.3822033, 22.950016, 18.882685, - }, - }, - { - { - -4.5502195, -0.39354602, 28.571766, 15.60658, - }, - }, - { - { - 2.5738533, 1.482931, -20.367672, 10.385576, - }, - }, -}; - -// 2. elementwise-multiplying simple 3d x 3d -static float x2[2][4][6] = { - { - { - -7.2105923, 0.30081058, -0.889673, -3.798492, -11.256981, -4.7941394, - }, - { - 4.8027363, 6.3011446, 12.005095, 2.7595978, 2.4951534, 2.3010116, - }, - { - -7.2994094, -3.4345918, 5.989834, 2.3114262, 6.6348333, -3.747816, - }, - { - -1.5329068, -3.550159, 1.8455162, -2.023382, -1.9699866, 0.8133544, - }, - }, - { - { - 7.424402, 3.3664422, -8.442434, -1.6988033, 0.6310587, -2.858629, - }, - { - 2.0530667, 0.8698405, 5.885768, -1.2876986, 2.746096, -5.3008785, - }, - { - 6.6393223, 0.3517515, 2.076831, 4.2641716, 0.6083386, 3.9074566, - }, - { - 1.1794354, -2.0538042, 4.9310713, -1.1522586, 2.9209592, -4.7671423, - }, - }, -}; - -static float y2[2][4][6] = { - { - { - -1.9622567, 5.9057455, 3.2101762, -5.1325912, -3.5329905, 10.019236, - }, - { - -5.8224397, 8.399536, -5.8282924, -5.0901465, 1.1504599, -7.13942, - }, - { - -6.2722616, 2.0332947, -5.106679, 7.47806, 1.7821686, 0.68897694, - }, - { - 5.7242374, 6.836463, -1.0935534, -2.8218496, -2.6866128, 1.8836043, - }, - }, - { - { - 5.1700087, -0.5320493, 3.1291423, 6.2034464, -2.5691035, 7.434816, - }, - { - 9.900221, -6.5086193, -2.624558, 5.4042997, -3.8112097, -1.9721222, - }, - { - 7.836174, -3.27554, 0.2076529, -3.0652354, 3.172955, -5.30567, - }, - { - -0.17906672, 6.665523, 11.803064, 2.851017, -4.847868, -0.6939828, - }, - }, -}; - -static float expected2[2][4][6] = { - { - { - 14.149033, 1.7765107, -2.856007, 19.496107, 39.770805, -48.03361, - }, - { - -27.963642, 52.926693, -69.9692, -14.046757, 2.870574, -16.427889, - }, - { - 45.783806, -6.983537, -30.588158, 17.284983, 11.824391, -2.5821588, - }, - { - -8.774722, -24.27053, -2.0181706, 5.7096796, 5.292591, 1.5320377, - }, - }, - { - { - 38.384224, -1.7911133, -26.417578, -10.538435, -1.621255, -21.25338, - }, - { - 20.325813, -5.661461, -15.447539, -6.9591093, -10.465947, 10.45398, - }, - { - 52.026886, -1.1521761, 0.43126, -13.070689, 1.930231, -20.731674, - }, - { - -0.21119761, -13.689679, 58.20175, -3.285109, -14.160424, 3.3083146, - }, - }, -}; - -// 3. elementwise-multiplying simple 4d x 1d -static float x3[3][2][4][6] = { - { - { - { - 3.4511616, 6.8213983, -3.9032097, 2.7949853, -2.4810624, -5.193684, - }, - { - 0.08306229, 1.8435066, 0.71155137, 0.57163835, 3.6964777, 0.8721923, - }, - { - -1.3706003, -2.6251526, 6.111269, 3.9835145, 4.6476684, 1.7110837, - }, - { - 0.20046586, -9.296765, -0.38201705, -6.524978, -3.4010968, 0.8397062, - }, - }, - { - { - -1.1077878, -1.912447, 3.370302, -10.548304, -13.630229, 5.6805444, - }, - { - 0.1377167, 6.2926893, -1.3399599, -2.8300138, 4.136174, 5.701481, - }, - { - 1.8934447, -4.3057623, 5.4859633, 6.9906974, -2.743602, 0.0060951854, - }, - { - 5.2084804, 0.7307493, 0.041380864, 3.9017618, -2.9675317, 0.893882, - }, - }, - }, - { - { - { - 2.7736564, -4.883692, 2.724194, 3.2103822, -9.412777, -0.9386832, - }, - { - -3.0339835, -8.912085, -8.830975, -2.013668, -2.9297779, 2.408302, - }, - { - -2.0810814, -1.8345542, -2.1508193, -4.6043878, 3.0493782, 2.9568095, - }, - { - -4.0822353, -4.3395967, 4.084664, 5.4317946, 4.325478, 3.6764784, - }, - }, - { - { - -2.5416138, 7.879944, -2.0247207, -1.1500132, -4.063577, 0.99201775, - }, - { - -1.0726405, -6.3343916, 8.285111, 0.8598841, 1.5183163, 7.9626045, - }, - { - -6.54306, 5.261826, 6.2108326, 0.6986546, 7.9932504, -8.734413, - }, - { - -2.4487484, 4.8250856, -6.518466, -2.252397, 3.8628614, -1.763003, - }, - }, - }, - { - { - { - -4.7506614, -6.3858204, 1.1295259, -9.164337, -4.920489, -4.547884, - }, - { - 12.074501, -1.0219653, 2.562501, 4.4603024, 11.272025, 1.2186266, - }, - { - 0.8928604, 5.2597437, -3.8921394, -1.4161685, -1.9687729, -3.1143188, - }, - { - -1.3726944, -2.17756, 3.4230003, 2.4563243, -6.8160734, -1.6609626, - }, - }, - { - { - 4.12099, 6.351284, -3.1314368, 2.039052, -5.265438, 0.085810244, - }, - { - -2.081704, -2.0682046, -8.809668, -1.9327109, 11.162933, -5.473809, - }, - { - 6.6081295, -4.427154, -3.326314, 4.311129, -0.778096, -5.855744, - }, - { - 7.0940695, -5.3400326, -0.1266769, 0.20553468, 1.2000599, 0.098438516, - }, - }, - }, -}; - -static float y3[6] = { - 2.4239943, -2.4815967, -2.246438, 0.35926288, -0.39192855, 9.577583, -}; - -static float expected3[3][2][4][6] = { - { - { - { - 8.365596, -16.92796, 8.768319, 1.0041345, 0.9723992, -49.742943, - }, - { - 0.20134252, -4.57484, -1.598456, 0.20536844, -1.4487551, 8.353495, - }, - { - -3.3223274, 6.51457, -13.728587, 1.431129, -1.821554, 16.388046, - }, - { - 0.4859281, 23.070822, 0.8581776, -2.3441825, 1.332987, 8.042356, - }, - }, - { - { - -2.6852715, 4.745922, -7.5711746, -3.789614, 5.342076, 54.405888, - }, - { - 0.3338245, -15.615917, 3.0101368, -1.0167189, -1.6210848, 54.606407, - }, - { - 4.5896993, 10.685165, -12.323876, 2.5114982, 1.0752959, 0.058377147, - }, - { - 12.625327, -1.8134251, -0.092959546, 1.4017582, 1.1630604, 8.561229, - }, - }, - }, - { - { - { - 6.723327, 12.119353, -6.1197333, 1.1533712, 3.689136, -8.990316, - }, - { - -7.3543587, 22.1162, 19.838238, -0.7234362, 1.1482636, 23.065714, - }, - { - -5.0445294, 4.5526237, 4.831682, -1.6541857, -1.1951383, 28.31909, - }, - { - -9.895315, 10.769129, -9.175944, 1.9514422, -1.6952784, 35.211777, - }, - }, - { - { - -6.160857, -19.554842, 4.5484095, -0.41315708, 1.5926319, 9.501133, - }, - { - -2.6000745, 15.719405, -18.61199, 0.30892444, -0.5950715, 76.262505, - }, - { - -15.86034, -13.05773, -13.9522505, 0.25100067, -3.1327832, -83.65457, - }, - { - -5.935752, -11.973917, 14.64333, -0.8092027, -1.5139657, -16.885307, - }, - }, - }, - { - { - { - -11.515576, 15.847031, -2.53741, -3.292406, 1.92848, -43.55774, - }, - { - 29.268522, 2.5361056, -5.7565, 1.602421, -4.4178286, 11.671498, - }, - { - 2.1642885, -13.052563, 8.74345, -0.5087768, 0.7716183, -29.827648, - }, - { - -3.3274033, 5.4038258, -7.689558, 0.88246614, 2.671414, -15.908008, - }, - }, - { - { - 9.989256, -15.761326, 7.034579, 0.7325557, 2.0636756, 0.82185477, - }, - { - -5.0460386, 5.1324496, 19.790373, -0.6943513, -4.3750725, -52.42586, - }, - { - 16.018068, 10.986411, 7.472358, 1.5488287, 0.30495805, -56.083874, - }, - { - 17.195984, 13.251807, 0.2845718, 0.07384098, -0.47033775, 0.9428031, - }, - }, - }, -}; - -} // end of data -} // end of namespace elementwise_mul_test -} // end of namespace nnfw - -#endif // __NNFW_KERNEL_ACL_ELEMENTWISE_MUL_TEST_H__ diff --git a/libs/kernel/acl/src/Mul.test.h b/libs/kernel/acl/src/Mul.test.h deleted file mode 100644 index 303ad7d..0000000 --- a/libs/kernel/acl/src/Mul.test.h +++ /dev/null @@ -1,157 +0,0 @@ -/* - * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include - -// TODO: fix include path in CMakeFiles -#include "util.h" -#include "Mul.test.data.h" - -#ifndef ACL_TEST -#error "ACL_TEST should be defined first!" -#endif // ACL_TEST - -#ifndef ACL_CORE_FUNC_NAME -#error "ACL_CORE_FUNC_NAME should be defined first!" -#endif // ACL_CORE_FUNC_NAME - -using namespace nnfw::kernel::acl; -using namespace nnfw::elementwise_mul_test; - -// when the sape of a, b of Mul(a, b) are same -ACL_TEST(KernelACL_TC, mulFloat32_2x2_2x2) -{ - float x1[2][2] = {{1., 2.}, {-3., -4.}}; - float x2[2][2] = {{5., -6.}, {7., -8.}}; - float expected[2][2] = {{5., -12.}, {-21., 32.}}; - - const nnfw::rt::Shape x1Shape = {OperandType::FLOAT32, {2, 2}, 1.0, 0}; - const nnfw::rt::Shape x2Shape = {OperandType::FLOAT32, {2, 2}, 1.0, 0}; - - float actual[2][2]; - const nnfw::rt::Shape actualShape = {OperandType::FLOAT32, {2, 2}, 1.0, 0}; - bool bret; - - util::initData((float *)actual, sizeof(actual) / sizeof(actual[0]), 0.0); - - bret = nnfw::kernel::acl::neon::mulFloat32((float *)x1, x1Shape, (float *)x2, x2Shape, - static_cast(FusedActivationFunc::NONE), - (float *)actual, actualShape); - - EXPECT_EQ(bret, true); - - bret = util::compareData((float *)actual, (float *)expected, actualShape); - EXPECT_EQ(bret, true); -} - -ACL_TEST(KernelACL_TC, mulFloat32_2x4x6_2x4x6) -{ - const nnfw::rt::Shape xShape = {OperandType::FLOAT32, {2, 4, 6}, 1.0, 0}; - const nnfw::rt::Shape yShape = {OperandType::FLOAT32, {2, 4, 6}, 1.0, 0}; - - float actual[2][4][6]; - const nnfw::rt::Shape actualShape = {OperandType::FLOAT32, {2, 4, 6}, 1.0, 0}; - bool bret; - - util::initData((float *)actual, sizeof(actual) / sizeof(actual[0]), 0.0); - - bret = ACL_CORE_FUNC_NAME((float *)td::x2, xShape, (float *)td::y2, yShape, - static_cast(FusedActivationFunc::NONE), (float *)actual, - actualShape); - - EXPECT_EQ(bret, true); - - bret = util::compareData((float *)actual, (float *)td::expected2, actualShape); - EXPECT_EQ(bret, true); -} - -// when the shape of a, b of Mul(a, b) are different - -// Note: neon/Mul.test.h fails with this test. -// Unlike cl/Mul.test.h, arm_compute::NEPixelWiseMultiplication.config() in neon/Mul.test.h fails -// when the shapes of a and b of Mul(a, b) are different. -#ifndef GTEST_EXCLUDE_TEST -ACL_TEST(KernelACL_TC, mulFloat32_2x2_1) -{ - float x1[2][2] = {{1., 2.}, {-3., -4.}}; - float x2[1] = {2.}; - float expected[2][2] = {{2., 4.}, {-6., -8.}}; - - const nnfw::rt::Shape x1Shape = {OperandType::FLOAT32, {2, 2}, 1.0, 0}; - const nnfw::rt::Shape x2Shape = {OperandType::FLOAT32, {1}, 1.0, 0}; - - float actual[2][2]; - const nnfw::rt::Shape actualShape = {OperandType::FLOAT32, {2, 2}, 1.0, 0}; - bool bret; - - util::initData((float *)actual, sizeof(actual) / sizeof(actual[0]), 0.0); - - bret = ACL_CORE_FUNC_NAME((float *)x1, x1Shape, (float *)x2, x2Shape, - static_cast(FusedActivationFunc::NONE), (float *)actual, - actualShape); - - EXPECT_EQ(bret, true); - - bret = util::compareData((float *)actual, (float *)expected, actualShape); - EXPECT_EQ(bret, true); -} - -ACL_TEST(KernelACL_TC, mulFloat32_6x1x4_4) -{ - const nnfw::rt::Shape x1Shape = {OperandType::FLOAT32, {6, 1, 4}, 1.0, 0}; - const nnfw::rt::Shape y1Shape = {OperandType::FLOAT32, {4}, 1.0, 0}; - - float actual[6][1][4]; - const nnfw::rt::Shape actualShape = {OperandType::FLOAT32, {6, 1, 4}, 1.0, 0}; - bool bret; - - util::initData((float *)actual, sizeof(actual) / sizeof(actual[0]), 0.0); - - bret = ACL_CORE_FUNC_NAME((float *)td::x1, x1Shape, (float *)td::y1, y1Shape, - static_cast(FusedActivationFunc::NONE), (float *)actual, - actualShape); - - EXPECT_EQ(bret, true); - - bret = util::compareData((float *)actual, (float *)td::expected1, actualShape); - EXPECT_EQ(bret, true); -} - -ACL_TEST(KernelACL_TC, mulFloat32_3x2x4x6_6) -{ - const nnfw::rt::Shape x3Shape = {OperandType::FLOAT32, {3, 2, 4, 6}, 1.0, 0}; - const nnfw::rt::Shape y3Shape = {OperandType::FLOAT32, {6}, 1.0, 0}; - - float actual[3][2][4][6]; - const nnfw::rt::Shape actualShape = {OperandType::FLOAT32, {3, 2, 4, 6}, 1.0, 0}; - bool bret; - - util::initData((float *)actual, sizeof(actual) / sizeof(actual[0]), 0.0); - - bret = ACL_CORE_FUNC_NAME((float *)td::x3, x3Shape, (float *)td::y3, y3Shape, - static_cast(FusedActivationFunc::NONE), (float *)actual, - actualShape); - - EXPECT_EQ(bret, true); - - bret = util::compareData((float *)actual, (float *)td::expected3, actualShape); - EXPECT_EQ(bret, true); -} - -#endif // GTEST_EXCLUDE_TEST diff --git a/libs/kernel/acl/src/Reshape.h b/libs/kernel/acl/src/Reshape.h deleted file mode 100644 index 00bd743..0000000 --- a/libs/kernel/acl/src/Reshape.h +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef __NNFW_KERNEL_ACL_RESHAPE_COMMON_H__ -#define __NNFW_KERNEL_ACL_RESHAPE_COMMON_H__ -#include -#include -#include - -// TODO: fix include path in CMakeFiles -#include "IO_accessor.h" -#include "shape.h" - -namespace nnfw -{ -namespace kernel -{ -namespace acl -{ - -namespace common -{ - -typedef std::function sync_scheduler_f; - -template -bool reshapeGeneric(const void *inputData, const nnfw::rt::Shape &inputShape, void *outputData, - const nnfw::rt::Shape &outputShape, sync_scheduler_f sync_scheduler) -{ - - auto input_shape = util::fromNNShape(inputShape); - auto output_shape = util::fromNNShape(outputShape); - - TensorT input(arm_compute::TensorInfo(input_shape, arm_compute::Format::F32)); - TensorT output(arm_compute::TensorInfo(output_shape, arm_compute::Format::F32)); - - LayerT l; - - l.configure(input.ptr(), output.ptr()); - - input.allocate(); - output.allocate(); - - TensorAccess(input.ref(), (float *)inputData, inputShape); - - l.run(); - - sync_scheduler(); - - TensorAccess(output.ref(), (float *)outputData, outputShape); - - return true; -} - -} // namespace common - -} // namespace acl -} // namespace kernel -} // namespace nnfw - -#endif // __NNFW_KERNEL_ACL_RESHAPE_COMMON_H__ diff --git a/libs/kernel/acl/src/Reshape.test.h b/libs/kernel/acl/src/Reshape.test.h deleted file mode 100644 index a666aea..0000000 --- a/libs/kernel/acl/src/Reshape.test.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include - -// TODO: fix include path in CMakeFiles -#include "util.h" - -#ifndef ACL_TEST -#error "ACL_TEST should be defined first!" -#endif // ACL_TEST - -#ifndef ACL_CORE_FUNC_NAME -#error "ACL_CORE_FUNC_NAME should be defined first!" -#endif // ACL_CORE_FUNC_NAME - -using namespace nnfw::kernel::acl; - -ACL_TEST(KernelACL_TC, reshape_1) -{ - const nnfw::rt::Shape inputShape = {OperandType::FLOAT32, {1, 1, 9, 1}, 1.0, 0}; - float inputData[9] = {1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f}; - - const nnfw::rt::Shape outputShape = {OperandType::FLOAT32, {1, 3, 3, 1}, 1.0, 0}; - float outputData[9] = {0}; - - bool bret = ACL_CORE_FUNC_NAME(inputData, inputShape, outputData, outputShape); - - EXPECT_EQ(bret, true); - - float expectData[9] = {1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f}; - bret = util::compareData(outputData, expectData, outputShape); - EXPECT_EQ(bret, true); -} diff --git a/libs/kernel/acl/src/UniqueTensor.h b/libs/kernel/acl/src/UniqueTensor.h deleted file mode 100644 index af00f49..0000000 --- a/libs/kernel/acl/src/UniqueTensor.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef __NNFW_KERNEL_ACL_UNIQUETENSOR_H__ -#define __NNFW_KERNEL_ACL_UNIQUETENSOR_H__ - -#include -#include - -namespace nnfw -{ -namespace kernel -{ -namespace acl -{ - -template class UniqueTensor -{ -public: - UniqueTensor(const ::arm_compute::TensorInfo &info) { _tensor.allocator()->init(info); } - -public: - // Both copy and move are not allowed - UniqueTensor(const UniqueTensor &) = delete; - UniqueTensor(UniqueTensor &&) = delete; - -public: - ~UniqueTensor() { _tensor.allocator()->free(); } - -public: - void allocate() { _tensor.allocator()->allocate(); } - -public: - TensorT &ref(void) { return _tensor; } - TensorT *ptr(void) { return &_tensor; } - -private: - TensorT _tensor; -}; - -// TODO replace NEUniqueTensor implementation -using NEUniqueTensor = UniqueTensor<::arm_compute::Tensor>; -using CLUniqueTensor = UniqueTensor<::arm_compute::CLTensor>; - -} // namespace acl -} // namespace kernel -} // namespace nnfw - -#endif //__NNFW_KERNEL_ACL_UNIQUETENSOR_H__ diff --git a/libs/kernel/acl/src/cl/Add.cpp b/libs/kernel/acl/src/cl/Add.cpp deleted file mode 100644 index 77dba69..0000000 --- a/libs/kernel/acl/src/cl/Add.cpp +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include - -// TODO: fix include path in CMakeFiles -#include "../IO_accessor.h" -#include "../shape.h" -#include "../UniqueTensor.h" -#include "../util.h" - -namespace nnfw -{ -namespace kernel -{ -namespace acl -{ - -typedef std::function sync_scheduler_f; - -// TODO : Currently, handles addition of vector+vector, matrix(upto 4D)+matrix(upto 4D) -// TODO : broadcasting is not supported -static void sync_scheduler() { arm_compute::CLScheduler::get().sync(); } - -bool addFloat32(const float *inputData1, const nnfw::rt::Shape &inputShape1, - const float *inputData2, const nnfw::rt::Shape &inputShape2, int32_t activation, - float *outputData, const nnfw::rt::Shape &outputShape) -{ - // TODO: scalar addition is not implemented currently - assert((inputShape1.dimensions.size() >= 1) && (inputShape2.dimensions.size() >= 1)); - - // TODO: broadcasting is not implemented currently - assert(inputShape1.dimensions.size() == inputShape2.dimensions.size()); - - auto input_shape1 = util::fromNNShape(inputShape1, false); - auto input_shape2 = util::fromNNShape(inputShape2, false); - auto output_shape = util::fromNNShape(outputShape, false); - - CLUniqueTensor input1(arm_compute::TensorInfo(input_shape1, arm_compute::Format::F32)); - CLUniqueTensor input2(arm_compute::TensorInfo(input_shape2, arm_compute::Format::F32)); - CLUniqueTensor output(arm_compute::TensorInfo(output_shape, arm_compute::Format::F32)); - - std::vector> fns; - - auto add_f = std::make_shared(); - - // Regarding ConvertPolocy, refer to - // https://www.mathworks.com/help/fixedpoint/ug/saturation-and-wrapping.html - // TODO: check if using arm_compute::ConvertPolicy::SATURATE is correct - add_f->configure(input1.ptr(), input2.ptr(), output.ptr(), arm_compute::ConvertPolicy::SATURATE); - - fns.emplace_back(add_f); - - util::insertFusedActivationLayer(output, - activation, fns); - input1.allocate(); - input2.allocate(); - output.allocate(); - - if (inputShape1.dimensions.size() == 1) - TensorAccess(input1.ref(), (float *)inputData1, inputShape1); - else if (inputShape1.dimensions.size() >= 2) - TensorAccess(input1.ref(), (float *)inputData1, inputShape1); - else - assert("scalar addition is not implemented"); - - if (inputShape2.dimensions.size() == 1) - TensorAccess(input2.ref(), (float *)inputData2, inputShape2); - else if (inputShape2.dimensions.size() >= 2) - TensorAccess(input2.ref(), (float *)inputData2, inputShape2); - else - assert("scalar addition is not implemented"); - - for (const auto &fn : fns) - { - fn->run(); - } - - sync_scheduler(); - - if (outputShape.dimensions.size() == 1) - TensorAccess(output.ref(), (float *)outputData, outputShape); - else // outputShape.dimensions.size() >= 2 - TensorAccess(output.ref(), (float *)outputData, outputShape); - - return true; -} - -} // namespace acl -} // namespace kernel -} // namespace nnfw diff --git a/libs/kernel/acl/src/cl/Add.test.cpp b/libs/kernel/acl/src/cl/Add.test.cpp deleted file mode 100644 index f49e436..0000000 --- a/libs/kernel/acl/src/cl/Add.test.cpp +++ /dev/null @@ -1,190 +0,0 @@ -/* - * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include - -// TODO: fix include path in CMakeFiles -#include "../util.h" -#include "../Add.test.h" // test data - -using namespace nnfw::kernel::acl; -using namespace nnfw::add_vector_test; -using namespace nnfw::add_matrix_test; - -TEST(KernelACL_TC, addFloat32_vector_1) -{ - const int DIM = 1; - - const nnfw::rt::Shape inputShape1 = {OperandType::FLOAT32, {DIM}, 1.0, 0}; - const nnfw::rt::Shape inputShape2 = {OperandType::FLOAT32, {DIM}, 1.0, 0}; - - std::vector inputDataPtrs; - std::vector inputShapes; - float outputData[DIM]; - const nnfw::rt::Shape outputShape = {OperandType::FLOAT32, {DIM}, 1.0, 0}; - bool bret; - int32_t activation = static_cast(FusedActivationFunc::NONE); - - util::initData(outputData, sizeof(outputData) / sizeof(outputData[0]), 0.0); - - bret = addFloat32(nnfw::add_vector_test::x1, inputShape1, nnfw::add_vector_test::y1, inputShape2, - activation, outputData, outputShape); - - EXPECT_EQ(bret, true); - - bret = util::compareData(outputData, nnfw::add_vector_test::expected1, outputShape); - EXPECT_EQ(bret, true); -} - -TEST(KernelACL_TC, addFloat32_vector_100) -{ - const int DIM = 100; - - const nnfw::rt::Shape inputShape1 = {OperandType::FLOAT32, {DIM}, 1.0, 0}; - const nnfw::rt::Shape inputShape2 = {OperandType::FLOAT32, {DIM}, 1.0, 0}; - - std::vector inputDataPtrs; - std::vector inputShapes; - float outputData[DIM]; - const nnfw::rt::Shape outputShape = {OperandType::FLOAT32, {DIM}, 1.0, 0}; - bool bret; - int32_t activation = static_cast(FusedActivationFunc::NONE); - - util::initData(outputData, sizeof(outputData) / sizeof(outputData[0]), 0.0); - - bret = addFloat32(nnfw::add_vector_test::x2, inputShape1, nnfw::add_vector_test::y2, inputShape2, - activation, outputData, outputShape); - - EXPECT_EQ(bret, true); - - bret = util::compareData(outputData, nnfw::add_vector_test::expected2, outputShape); - EXPECT_EQ(bret, true); -} - -TEST(KernelACL_TC, addFloat32_relu_vector_100) -{ - const int DIM = 10; - - const nnfw::rt::Shape inputShape1 = {OperandType::FLOAT32, {DIM}, 1.0, 0}; - const nnfw::rt::Shape inputShape2 = {OperandType::FLOAT32, {DIM}, 1.0, 0}; - - std::vector inputDataPtrs; - std::vector inputShapes; - float outputData[DIM]; - const nnfw::rt::Shape outputShape = {OperandType::FLOAT32, {DIM}, 1.0, 0}; - bool bret; - int32_t activation = static_cast(FusedActivationFunc::RELU); - - util::initData(outputData, sizeof(outputData) / sizeof(outputData[0]), 0.0); - - bret = addFloat32(nnfw::add_vector_test::x3, inputShape1, nnfw::add_vector_test::y3, inputShape2, - activation, outputData, outputShape); - - EXPECT_EQ(bret, true); - - bret = util::compareData(outputData, nnfw::add_vector_test::expected3, outputShape); - EXPECT_EQ(bret, true); -} - -// 2D + 2D -#define GTEST_TC_DIM 2, 6 -#define GTEST_TC_OUTPUT_SIZE 12 - -TEST(KernelACL_TC, addFloat_2Dx2D) -{ - const nnfw::rt::Shape inputShape1 = {OperandType::FLOAT32, {GTEST_TC_DIM}, 1.0, 0}; - const nnfw::rt::Shape inputShape2 = {OperandType::FLOAT32, {GTEST_TC_DIM}, 1.0, 0}; - - std::vector inputDataPtrs; - std::vector inputShapes; - float outputData[GTEST_TC_OUTPUT_SIZE]; - const nnfw::rt::Shape outputShape = {OperandType::FLOAT32, {GTEST_TC_DIM}, 1.0, 0}; - bool bret; - - util::initData(outputData, sizeof(outputData) / sizeof(outputData[0]), 0.0); - - bret = addFloat32((float *)nnfw::add_matrix_test::x_2d_1, inputShape1, - (float *)nnfw::add_matrix_test::y_2d_1, inputShape2, - static_cast(FusedActivationFunc::NONE), outputData, outputShape); - - EXPECT_EQ(bret, true); - - bret = util::compareData(outputData, (float *)nnfw::add_matrix_test::expected_2d_1, outputShape); - EXPECT_EQ(bret, true); -} -#undef GTEST_TC_DIM -#undef GTEST_TC_OUTPUT_SIZE - -//-------- 3D + 3D -#define GTEST_TC_DIM 2, 2, 6 -#define GTEST_TC_OUTPUT_SIZE 2 * 2 * 6 - -TEST(KernelACL_TC, addFloat_3Dx3D) -{ - const nnfw::rt::Shape inputShape1 = {OperandType::FLOAT32, {GTEST_TC_DIM}, 1.0, 0}; - const nnfw::rt::Shape inputShape2 = {OperandType::FLOAT32, {GTEST_TC_DIM}, 1.0, 0}; - - std::vector inputDataPtrs; - std::vector inputShapes; - float outputData[GTEST_TC_OUTPUT_SIZE]; - const nnfw::rt::Shape outputShape = {OperandType::FLOAT32, {GTEST_TC_DIM}, 1.0, 0}; - bool bret; - - util::initData(outputData, sizeof(outputData) / sizeof(outputData[0]), 0.0); - - bret = addFloat32((float *)nnfw::add_matrix_test::x_3d_1, inputShape1, - (float *)nnfw::add_matrix_test::y_3d_1, inputShape2, - static_cast(FusedActivationFunc::NONE), outputData, outputShape); - - EXPECT_EQ(bret, true); - - bret = util::compareData(outputData, (float *)nnfw::add_matrix_test::expected_3d_1, outputShape); - EXPECT_EQ(bret, true); -} -#undef GTEST_TC_DIM -#undef GTEST_TC_OUTPUT_SIZE - -//----- 4D + 4D -#define GTEST_TC_DIM 2, 2, 2, 6 -#define GTEST_TC_OUTPUT_SIZE 2 * 2 * 2 * 6 - -TEST(KernelACL_TC, addFloat_4Dx4D_1) -{ - const nnfw::rt::Shape inputShape1 = {OperandType::FLOAT32, {GTEST_TC_DIM}, 1.0, 0}; - const nnfw::rt::Shape inputShape2 = {OperandType::FLOAT32, {GTEST_TC_DIM}, 1.0, 0}; - - std::vector inputDataPtrs; - std::vector inputShapes; - float outputData[GTEST_TC_OUTPUT_SIZE]; - const nnfw::rt::Shape outputShape = {OperandType::FLOAT32, {GTEST_TC_DIM}, 1.0, 0}; - bool bret; - - util::initData(outputData, sizeof(outputData) / sizeof(outputData[0]), 0.0); - - bret = addFloat32((float *)nnfw::add_matrix_test::x_4d_1, inputShape1, - (float *)nnfw::add_matrix_test::y_4d_1, inputShape2, - static_cast(FusedActivationFunc::NONE), outputData, outputShape); - - EXPECT_EQ(bret, true); - - bret = util::compareData(outputData, (float *)nnfw::add_matrix_test::expected_4d_1, outputShape); - EXPECT_EQ(bret, true); -} -#undef GTEST_TC_DIM -#undef GTEST_TC_OUTPUT_SIZE diff --git a/libs/kernel/acl/src/cl/Concatenation.cpp b/libs/kernel/acl/src/cl/Concatenation.cpp deleted file mode 100644 index effaa64..0000000 --- a/libs/kernel/acl/src/cl/Concatenation.cpp +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include - -#include - -// TODO: fix include path in CMakeFiles -#include "../IO_accessor.h" -#include "../shape.h" - -namespace nnfw -{ -namespace kernel -{ -namespace acl -{ - -bool concatenationFloat32(const std::vector &inputDataPtrs, - const std::vector &inputShapes, int32_t axis, - float *outputData, const nnfw::rt::Shape &outputShape) -{ - if (axis != 3) - { - assert("Only support axis=3 for ACL" && 0); - return false; - } - assert(inputDataPtrs.size() == inputShapes.size()); - - std::vector inputPtrs; - std::vector inputIptrs; - arm_compute::CLTensor output; - - // init Tensors - std::vector::const_iterator it_inputShape = inputShapes.begin(); - for (auto inputData : inputDataPtrs) - { - const nnfw::rt::Shape &inputShape = *it_inputShape; - arm_compute::TensorShape input_shape = util::fromNNShape(inputShape); - arm_compute::CLTensor *inputPtr = new arm_compute::CLTensor(); - - inputPtr->allocator()->init(arm_compute::TensorInfo(input_shape, arm_compute::Format::F32)); - inputPtrs.push_back(inputPtr); - inputIptrs.push_back(inputPtr); - - it_inputShape++; - } - arm_compute::TensorShape output_shape = util::fromNNShape(outputShape); - output.allocator()->init(arm_compute::TensorInfo(output_shape, arm_compute::Format::F32)); - - // prepare ACL Concatenate and configure tensors - auto concat = std::make_shared(); - concat->configure(inputIptrs, &output); - - // allocate Tensors - it_inputShape = inputShapes.begin(); - std::vector::const_iterator it_inputData = inputDataPtrs.begin(); - for (auto inputPtr : inputPtrs) - { - inputPtr->allocator()->allocate(); - - const float *inputData = *it_inputData; - const nnfw::rt::Shape &inputShape = *it_inputShape; - - TensorAccess(*inputPtr, inputData, inputShape); - - it_inputShape++; - it_inputData++; - } - output.allocator()->allocate(); - - // run - concat->run(); - arm_compute::CLScheduler::get().sync(); - - // get output - TensorAccess(output, outputData, outputShape); - - // cleanup - for (auto inputPtr : inputPtrs) - { - inputPtr->allocator()->free(); - delete inputPtr; - } - output.allocator()->free(); - - return true; -} - -} // namespace acl -} // namespace kernel -} // namespace nnfw diff --git a/libs/kernel/acl/src/cl/Concatenation.test.cpp b/libs/kernel/acl/src/cl/Concatenation.test.cpp deleted file mode 100644 index 40b22cf..0000000 --- a/libs/kernel/acl/src/cl/Concatenation.test.cpp +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include - -// TODO: fix include path in CMakeFiles -#include "../util.h" - -using namespace nnfw::kernel::acl; - -TEST(KernelACL_TC, concatFloat32_1) -{ - float inputData_1[6] = { - 1, 2, 3, 4, 5, 6 // [ [ [1],[2],[3] ], [ [4],[5],[6] ] ] - }; - float inputData_2[6] = { - 7, 8, 9, 10, 11, 12 // [ [ [7],[8],[9] ], [ [10],[11],[12] ] ] - }; - const nnfw::rt::Shape inputShape_1 = {OperandType::FLOAT32, {1, 2, 3, 1}, 1.0, 0}; - const nnfw::rt::Shape inputShape_2 = {OperandType::FLOAT32, {1, 2, 3, 1}, 1.0, 0}; - std::vector inputDataPtrs; - std::vector inputShapes; - float outputData[12]; - const nnfw::rt::Shape outputShape = {OperandType::FLOAT32, {1, 2, 3, 2}, 1.0, 0}; - bool bret; - - inputDataPtrs.push_back(inputData_1); - inputDataPtrs.push_back(inputData_2); - inputShapes.push_back(inputShape_1); - inputShapes.push_back(inputShape_2); - - util::initData(outputData, sizeof(outputData) / sizeof(outputData[0]), 0.0); - - bret = concatenationFloat32(inputDataPtrs, inputShapes, 3, outputData, outputShape); - EXPECT_EQ(bret, true); - - float expectNCHW[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; - float expectData[12]; // [ [ [1,7],[2,8],[3,9] ], [ [4,10],[5,11],[6,12] ] ] - util::NCHW2NHWC(expectNCHW, expectData, outputShape); - bret = util::compareData(outputData, expectData, outputShape); - EXPECT_EQ(bret, true); -} diff --git a/libs/kernel/acl/src/cl/Conv2D.cpp b/libs/kernel/acl/src/cl/Conv2D.cpp deleted file mode 100644 index c464c51..0000000 --- a/libs/kernel/acl/src/cl/Conv2D.cpp +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include - -#include -#include - -#include - -#include "../IO_accessor.h" -#include "../util.h" -#include "../shape.h" -#include "../UniqueTensor.h" -#include "../support.h" - -#include "util/feature/TextFormatter.h" - -#include "support/nnapi/feature/Reader.h" - -namespace nnfw -{ -namespace kernel -{ -namespace acl -{ - -static int verbose = 0; - -bool convFloat32(const float *inputData, const nnfw::rt::Shape &inputShape, const float *filterData, - const nnfw::rt::Shape &filterShape, const float *biasData, - const nnfw::rt::Shape &biasShape, int32_t padding_left, int32_t padding_right, - int32_t padding_top, int32_t padding_bottom, int32_t stride_width, - int32_t stride_height, int32_t activation, float *outputData, - const nnfw::rt::Shape &outputShape) -{ - arm_compute::TensorShape input_shape = util::fromNNShape(inputShape); - arm_compute::TensorShape filter_shape = util::fromNNShape(filterShape); - arm_compute::TensorShape bias_shape = util::fromVectorNNShape(biasShape); - arm_compute::TensorShape output_shape = util::fromNNShape(outputShape); - arm_compute::PadStrideInfo conv_info = arm_compute::PadStrideInfo( - stride_width, stride_height, padding_left, padding_right, padding_top, padding_bottom, - arm_compute::DimensionRoundingType::FLOOR); - - CLUniqueTensor input(arm_compute::TensorInfo(input_shape, arm_compute::Format::F32)); - CLUniqueTensor output(arm_compute::TensorInfo(output_shape, arm_compute::Format::F32)); - CLUniqueTensor bias(arm_compute::TensorInfo(bias_shape, arm_compute::Format::F32)); - CLUniqueTensor filter(arm_compute::TensorInfo(filter_shape, arm_compute::Format::F32)); - - std::vector> fns; - - auto conv_f = std::make_shared(); - - conv_f->configure(input.ptr(), filter.ptr(), bias.ptr(), output.ptr(), conv_info); - - fns.emplace_back(conv_f); - - util::insertFusedActivationLayer(output, - activation, fns); - - input.allocate(); - output.allocate(); - bias.allocate(); - filter.allocate(); - - TensorAccess(input.ref(), inputData, inputShape); - TensorAccess(bias.ref(), biasData, biasShape); - TensorAccess(filter.ref(), filterData, filterShape); - - nnfw::util::env::IntAccessor("CONV2D_VERBOSE").access(verbose); - if (verbose) - { - input.ref().map(); - auto ifm_shape = nnfw::support::nnapi::feature::asFeatureShape(inputShape); - nnfw::support::nnapi::feature::Reader nnapi_ifm_reader{ifm_shape, inputData}; - nnfw::support::acl::feature::Reader acl_ifm_reader{input.ptr()}; - - std::cout << "NNAPI IFM:" << std::endl; - std::cout << nnfw::util::feature::TextFormatter{ifm_shape, nnapi_ifm_reader} - << std::endl; - - std::cout << "ARM Compute IFM:" << std::endl; - std::cout << nnfw::util::feature::TextFormatter{ifm_shape, acl_ifm_reader} << std::endl; - input.ref().unmap(); - } - - for (const auto &fn : fns) - { - fn->run(); - } - - arm_compute::CLScheduler::get().sync(); - - TensorAccess(output.ref(), outputData, outputShape); - - return true; -} - -} // namespace acl -} // namespace kernel -} // namespace nnfw diff --git a/libs/kernel/acl/src/cl/Conv2D.test.cpp b/libs/kernel/acl/src/cl/Conv2D.test.cpp deleted file mode 100644 index 421e659..0000000 --- a/libs/kernel/acl/src/cl/Conv2D.test.cpp +++ /dev/null @@ -1,162 +0,0 @@ -/* - * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include - -// TODO: fix include path in CMakeFiles -#include "../util.h" - -using namespace nnfw::kernel::acl; - -TEST(KernelACL_TC, convFloat32_3x3to1x1) -{ - float inputData[9]; - const nnfw::rt::Shape inputShape = {OperandType::FLOAT32, {1, 3, 3, 1}, 1.0, 0}; - float filterData[9]; - const nnfw::rt::Shape filterShape = {OperandType::FLOAT32, {1, 3, 3, 1}, 1.0, 0}; - float biasData[1] = {1.0}; - const nnfw::rt::Shape biasShape = {OperandType::FLOAT32, {1}, 1.0, 0}; - int32_t padding_left = 0; - int32_t padding_right = 0; - int32_t padding_top = 0; - int32_t padding_bottom = 0; - int32_t stride_width = 1; - int32_t stride_height = 1; - int32_t activation = static_cast(FusedActivationFunc::RELU); - float outputData[1]; - const nnfw::rt::Shape outputShape = {OperandType::FLOAT32, {1, 1, 1, 1}, 1.0, 0}; - bool bret; - - util::initData(inputData, sizeof(inputData) / sizeof(inputData[0]), 1.0); - util::initData(filterData, sizeof(filterData) / sizeof(filterData[0]), 1.0); - util::initData(outputData, sizeof(outputData) / sizeof(outputData[0]), 0.0); - - bret = convFloat32(inputData, inputShape, filterData, filterShape, biasData, biasShape, - padding_left, padding_right, padding_top, padding_bottom, stride_width, - stride_height, activation, outputData, outputShape); - EXPECT_EQ(bret, true); - - float expectData[] = {10.0f}; - bret = util::compareData(outputData, expectData, outputShape); - EXPECT_EQ(bret, true); -} - -TEST(KernelACL_TC, convFloat32_3x3to3x3) -{ - float inputData[9]; - const nnfw::rt::Shape inputShape = {OperandType::FLOAT32, {1, 3, 3, 1}, 1.0, 0}; - float filterData[9]; - const nnfw::rt::Shape filterShape = {OperandType::FLOAT32, {1, 3, 3, 1}, 1.0, 0}; - float biasData[1] = {1.0}; - const nnfw::rt::Shape biasShape = {OperandType::FLOAT32, {1}, 1.0, 0}; - int32_t padding_left = 1; - int32_t padding_right = 1; - int32_t padding_top = 1; - int32_t padding_bottom = 1; - int32_t stride_width = 1; - int32_t stride_height = 1; - int32_t activation = static_cast(FusedActivationFunc::RELU); - float outputData[9]; - const nnfw::rt::Shape outputShape = {OperandType::FLOAT32, {1, 3, 3, 1}, 1.0, 0}; - bool bret; - - util::initData(inputData, sizeof(inputData) / sizeof(inputData[0]), 1.0); - util::initData(filterData, sizeof(filterData) / sizeof(filterData[0]), 1.0); - util::initData(outputData, sizeof(outputData) / sizeof(outputData[0]), 0.0); - - bret = convFloat32(inputData, inputShape, filterData, filterShape, biasData, biasShape, - padding_left, padding_right, padding_top, padding_bottom, stride_width, - stride_height, activation, outputData, outputShape); - EXPECT_EQ(bret, true); - - float expectData[] = {5.0f, 7.0f, 5.0f, 7.0f, 10.0f, 7.0f, 5.0f, 7.0f, 5.0f}; - bret = util::compareData(outputData, expectData, outputShape); - EXPECT_EQ(bret, true); -} - -TEST(KernelACL_TC, convFloat32_3x3to3x3_RELU) -{ - float inputData[9]; - const nnfw::rt::Shape inputShape = {OperandType::FLOAT32, {1, 3, 3, 1}, 1.0, 0}; - float filterData[9]; - const nnfw::rt::Shape filterShape = {OperandType::FLOAT32, {1, 3, 3, 1}, 1.0, 0}; - float biasData[1] = {-5.0f}; - const nnfw::rt::Shape biasShape = {OperandType::FLOAT32, {1}, 1.0, 0}; - int32_t padding_left = 1; - int32_t padding_right = 1; - int32_t padding_top = 1; - int32_t padding_bottom = 1; - int32_t stride_width = 1; - int32_t stride_height = 1; - int32_t activation = static_cast(FusedActivationFunc::RELU); - float outputData[9]; - const nnfw::rt::Shape outputShape = {OperandType::FLOAT32, {1, 3, 3, 1}, 1.0, 0}; - bool bret; - - util::initData(inputData, sizeof(inputData) / sizeof(inputData[0]), 1.0); - util::initData(filterData, sizeof(filterData) / sizeof(filterData[0]), 1.0); - util::initData(outputData, sizeof(outputData) / sizeof(outputData[0]), 0.0); - - bret = convFloat32(inputData, inputShape, filterData, filterShape, biasData, biasShape, - padding_left, padding_right, padding_top, padding_bottom, stride_width, - stride_height, activation, outputData, outputShape); - EXPECT_EQ(bret, true); - - float expectData[] = {0.0f, 1.0f, 0.0f, 1.0f, 4.0f, 1.0f, 0.0f, 1.0f, 0.0f}; - - bret = util::compareData(outputData, expectData, outputShape); - EXPECT_EQ(bret, true); -} - -TEST(KernelACL_TC, convFloat32_3x5to3x3) -{ - float inputData[15] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; - const nnfw::rt::Shape inputShape = {OperandType::FLOAT32, {1, 3, 5, 1}, 1.0, 0}; - float filterData[18] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2}; - const nnfw::rt::Shape filterShape = {OperandType::FLOAT32, {2, 3, 3, 1}, 1.0, 0}; - float biasData[2] = {1.0, 1.0}; - const nnfw::rt::Shape biasShape = {OperandType::FLOAT32, {2}, 1.0, 0}; - int32_t padding_left = 1; - int32_t padding_right = 1; - int32_t padding_top = 1; - int32_t padding_bottom = 1; - int32_t stride_width = 1; - int32_t stride_height = 1; - int32_t activation = static_cast(FusedActivationFunc::RELU); - float outputData[30]; - const nnfw::rt::Shape outputShape = {OperandType::FLOAT32, {1, 3, 5, 2}, 1.0, 0}; - bool bret; - - util::initData(outputData, sizeof(outputData) / sizeof(outputData[0]), 0.0); - - bret = convFloat32(inputData, inputShape, filterData, filterShape, biasData, biasShape, - padding_left, padding_right, padding_top, padding_bottom, stride_width, - stride_height, activation, outputData, outputShape); - EXPECT_EQ(bret, true); - - float expectNCHW[] = {17.0f, 28.0f, 34.0f, 40.0f, 29.0f, 40.0f, 64.0f, 73.0f, - 82.0f, 58.0f, 37.0f, 58.0f, 64.0f, 70.0f, 49.0f, - - 33.0f, 55.0f, 67.0f, 79.0f, 57.0f, 79.0f, 127.0f, 145.0f, - 163.0f, 115.0f, 73.0f, 115.0f, 127.0f, 139.0f, 97.0f}; - float expectData[30]; - util::NCHW2NHWC(expectNCHW, expectData, outputShape); - bret = util::compareData(outputData, expectData, outputShape); - EXPECT_EQ(bret, true); -} diff --git a/libs/kernel/acl/src/cl/DepthwiseConv2D.cpp b/libs/kernel/acl/src/cl/DepthwiseConv2D.cpp deleted file mode 100644 index bedfd97..0000000 --- a/libs/kernel/acl/src/cl/DepthwiseConv2D.cpp +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include - -#include - -// TODO: fix include path in CMakeFiles -#include "../IO_accessor.h" -#include "../shape.h" -#include "../UniqueTensor.h" -#include "../DepthwiseConv2D.h" - -namespace nnfw -{ -namespace kernel -{ -namespace acl -{ - -static void sync_scheduler() { arm_compute::CLScheduler::get().sync(); } - -bool depthwiseConvFloat32(const float *inputData, const nnfw::rt::Shape &inputShape, - const float *filterData, const nnfw::rt::Shape &filterShape, - const float *biasData, const nnfw::rt::Shape &biasShape, - int32_t padding_left, int32_t padding_right, int32_t padding_top, - int32_t padding_bottom, int32_t stride_width, int32_t stride_height, - int32_t depth_multiplier, int32_t activation, float *outputData, - const nnfw::rt::Shape &outputShape) -{ - return common::depthwiseConvFloat32( - inputData, inputShape, filterData, filterShape, biasData, biasShape, padding_left, - padding_right, padding_top, padding_bottom, stride_width, stride_height, depth_multiplier, - activation, outputData, outputShape, sync_scheduler); -} - -} // namespace acl -} // namespace kernel -} // namespace nnfw diff --git a/libs/kernel/acl/src/cl/DepthwiseConv2D.test.cpp b/libs/kernel/acl/src/cl/DepthwiseConv2D.test.cpp deleted file mode 100644 index 6955633..0000000 --- a/libs/kernel/acl/src/cl/DepthwiseConv2D.test.cpp +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#define ACL_CORE_FUNC_NAME depthwiseConvFloat32 -#define ACL_TEST(tc, t) TEST(tc, cl_##t) - -#include "../DepthwiseConv2D.test.h" diff --git a/libs/kernel/acl/src/cl/FullyConnected.cpp b/libs/kernel/acl/src/cl/FullyConnected.cpp deleted file mode 100644 index 318edda..0000000 --- a/libs/kernel/acl/src/cl/FullyConnected.cpp +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include - -#include - -// TODO: fix include path in CMakeFiles -#include "../IO_accessor.h" -#include "../shape.h" -#include "../UniqueTensor.h" -#include "../FullyConnected.h" - -namespace nnfw -{ -namespace kernel -{ -namespace acl -{ - -void sync_scheduler() { arm_compute::CLScheduler::get().sync(); } - -bool fullyConnectedFloat32(const float *inputData, const nnfw::rt::Shape &inputShape, - const float *weightsData, const nnfw::rt::Shape &weightsShape, - const float *biasData, const nnfw::rt::Shape &biasShape, - int32_t activation, float *outputData, - const nnfw::rt::Shape &outputShape) -{ - return common::fullyConnectedFloat32( - inputData, inputShape, weightsData, weightsShape, biasData, biasShape, activation, outputData, - outputShape, sync_scheduler); -} - -} // namespace acl -} // namespace kernel -} // namespace nnfw diff --git a/libs/kernel/acl/src/cl/FullyConnected.test.cpp b/libs/kernel/acl/src/cl/FullyConnected.test.cpp deleted file mode 100644 index b1f5a09..0000000 --- a/libs/kernel/acl/src/cl/FullyConnected.test.cpp +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#define ACL_CORE_FUNC_NAME fullyConnectedFloat32 -#define ACL_TEST(tc, t) TEST(tc, cl_##t) - -#include "../FullyConnected.test.h" diff --git a/libs/kernel/acl/src/cl/Mul.cpp b/libs/kernel/acl/src/cl/Mul.cpp deleted file mode 100644 index 6761519..0000000 --- a/libs/kernel/acl/src/cl/Mul.cpp +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "../Mul.h" - -namespace nnfw -{ -namespace kernel -{ -namespace acl -{ -static void sync_scheduler() { arm_compute::CLScheduler::get().sync(); } - -bool mulFloat32(const float *inputData1, const nnfw::rt::Shape &inputShape1, - const float *inputData2, const nnfw::rt::Shape &inputShape2, int32_t activation, - float *outputData, const nnfw::rt::Shape &outputShape) -{ - bool bret = common::mulFloat32( - inputData1, inputShape1, inputData2, inputShape2, activation, outputData, outputShape, - sync_scheduler); - return bret; -} - -} // namespace acl -} // namespace kernel -} // namespace nnfw diff --git a/libs/kernel/acl/src/cl/Mul.test.cpp b/libs/kernel/acl/src/cl/Mul.test.cpp deleted file mode 100644 index 95e9264..0000000 --- a/libs/kernel/acl/src/cl/Mul.test.cpp +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#define ACL_CORE_FUNC_NAME nnfw::kernel::acl::mulFloat32 -#define ACL_TEST(tc, t) TEST(tc, cl_##t) - -#include "../Mul.test.h" - -#undef ACL_CORE_FUNC_NAME -#undef ACL_TEST diff --git a/libs/kernel/acl/src/cl/Pooling.cpp b/libs/kernel/acl/src/cl/Pooling.cpp deleted file mode 100644 index 21e4925..0000000 --- a/libs/kernel/acl/src/cl/Pooling.cpp +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include "../IO_accessor.h" -#include "../shape.h" -#include "../UniqueTensor.h" - -#include - -namespace nnfw -{ -namespace kernel -{ -namespace acl -{ - -bool maxPoolFloat32(const float *inputData, const nnfw::rt::Shape &inputShape, int32_t padding_left, - int32_t padding_right, int32_t padding_top, int32_t padding_bottom, - int32_t stride_width, int32_t stride_height, int32_t filter_width, - int32_t filter_height, int32_t activation, float *outputData, - const nnfw::rt::Shape &outputShape) -{ - arm_compute::TensorShape input_shape = util::fromNNShape(inputShape); - arm_compute::TensorShape output_shape = util::fromNNShape(outputShape); - - std::vector> fns; - - arm_compute::PadStrideInfo pad_info = arm_compute::PadStrideInfo( - stride_width, stride_height, padding_left, padding_right, padding_top, padding_bottom, - arm_compute::DimensionRoundingType::FLOOR); - - arm_compute::PoolingLayerInfo maxpool_info = arm_compute::PoolingLayerInfo( - arm_compute::PoolingType::MAX, arm_compute::Size2D(filter_width, filter_height), pad_info, - false); - - CLUniqueTensor input(arm_compute::TensorInfo(input_shape, arm_compute::Format::F32)); - CLUniqueTensor output(arm_compute::TensorInfo(output_shape, arm_compute::Format::F32)); - - auto pool_f = std::make_shared(); - pool_f->configure(input.ptr(), output.ptr(), maxpool_info); - - fns.emplace_back(pool_f); - - input.allocate(); - output.allocate(); - - util::insertFusedActivationLayer(output, - activation, fns); - - TensorAccess(input.ref(), inputData, inputShape); - - for (const auto &fn : fns) - { - fn->run(); - } - - arm_compute::CLScheduler::get().sync(); - - TensorAccess(output.ref(), outputData, outputShape); - - return true; -} - -bool averagePoolFloat32(const float *inputData, const nnfw::rt::Shape &inputShape, - int32_t padding_left, int32_t padding_right, int32_t padding_top, - int32_t padding_bottom, int32_t stride_width, int32_t stride_height, - int32_t filter_width, int32_t filter_height, int32_t activation, - float *outputData, const nnfw::rt::Shape &outputShape) -{ - arm_compute::TensorShape input_shape = util::fromNNShape(inputShape); - arm_compute::TensorShape output_shape = util::fromNNShape(outputShape); - - std::vector> fns; - - arm_compute::PadStrideInfo pad_info = arm_compute::PadStrideInfo( - stride_width, stride_height, padding_left, padding_right, padding_top, padding_bottom, - arm_compute::DimensionRoundingType::FLOOR); - - arm_compute::PoolingLayerInfo pool_info = arm_compute::PoolingLayerInfo( - arm_compute::PoolingType::AVG, arm_compute::Size2D(filter_width, filter_height), pad_info, - true); - - CLUniqueTensor input(arm_compute::TensorInfo(input_shape, arm_compute::Format::F32)); - CLUniqueTensor output(arm_compute::TensorInfo(output_shape, arm_compute::Format::F32)); - - auto pool_f = std::make_shared(); - pool_f->configure(input.ptr(), output.ptr(), pool_info); - - fns.emplace_back(pool_f); - - input.allocate(); - output.allocate(); - - util::insertFusedActivationLayer(output, - activation, fns); - - TensorAccess(input.ref(), inputData, inputShape); - - for (const auto &fn : fns) - { - fn->run(); - } - - arm_compute::CLScheduler::get().sync(); - - TensorAccess(output.ref(), outputData, outputShape); - - return true; -} - -} // namespace acl -} // namespace kernel -} // namespace nnfw diff --git a/libs/kernel/acl/src/cl/Pooling.test.cpp b/libs/kernel/acl/src/cl/Pooling.test.cpp deleted file mode 100644 index 0971e21..0000000 --- a/libs/kernel/acl/src/cl/Pooling.test.cpp +++ /dev/null @@ -1,395 +0,0 @@ -/* - * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include - -#include "../util.h" - -using namespace nnfw::kernel::acl; - -TEST(KernelACL_TC, maxPoolFloat32_3x3to1x1) -{ - util::TensorWrapper input({1, 3, 3, 1}); - const nnfw::rt::Shape inputShape = {OperandType::FLOAT32, {1, 3, 3, 1}, 1.0, 0}; - int32_t padding_left = 0; - int32_t padding_right = 0; - int32_t padding_top = 0; - int32_t padding_bottom = 0; - int32_t stride_width = 1; - int32_t stride_height = 1; - int32_t filter_width = 3; - int32_t filter_height = 3; - - float outputData[1]; - const nnfw::rt::Shape outputShape = {OperandType::FLOAT32, {1, 1, 1, 1}, 1.0, 0}; - bool bret; - - float value = 1.0f; - input.initValue([&value](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { return value++; }); - - util::initData(outputData, sizeof(outputData) / sizeof(outputData[0]), 0.0); - - int32_t activation = ANEURALNETWORKS_FUSED_NONE; - - bret = maxPoolFloat32(input.ptr(), inputShape, padding_left, padding_right, padding_top, - padding_bottom, stride_width, stride_height, filter_width, filter_height, - activation, outputData, outputShape); - EXPECT_EQ(bret, true); - - float expectData[] = {9.0f}; - bret = util::compareData(outputData, expectData, outputShape); - EXPECT_EQ(bret, true); -} - -TEST(KernelACL_TC, maxPoolFloat32_3x3to1x1_RELU) -{ - util::TensorWrapper input({1, 3, 3, 1}); - const nnfw::rt::Shape inputShape = {OperandType::FLOAT32, {1, 3, 3, 1}, 1.0, 0}; - int32_t padding_left = 0; - int32_t padding_right = 0; - int32_t padding_top = 0; - int32_t padding_bottom = 0; - int32_t stride_width = 1; - int32_t stride_height = 1; - int32_t filter_width = 3; - int32_t filter_height = 3; - - float outputData[1]; - const nnfw::rt::Shape outputShape = {OperandType::FLOAT32, {1, 1, 1, 1}, 1.0, 0}; - bool bret; - - float value = -1.0f; - input.initValue([&value](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { return value--; }); - - util::initData(outputData, sizeof(outputData) / sizeof(outputData[0]), 0.0); - - int32_t activation = ANEURALNETWORKS_FUSED_RELU; - - bret = maxPoolFloat32(input.ptr(), inputShape, padding_left, padding_right, padding_top, - padding_bottom, stride_width, stride_height, filter_width, filter_height, - activation, outputData, outputShape); - EXPECT_EQ(bret, true); - - float expectData[] = {0.0f}; - bret = util::compareData(outputData, expectData, outputShape); - EXPECT_EQ(bret, true); -} - -TEST(KernelACL_TC, maxPoolFloat32_3x3to2x2) -{ - util::TensorWrapper input({1, 3, 3, 1}); - const nnfw::rt::Shape inputShape = {OperandType::FLOAT32, {1, 3, 3, 1}, 1.0, 0}; - int32_t padding_left = 0; - int32_t padding_right = 1; - int32_t padding_top = 0; - int32_t padding_bottom = 1; - int32_t stride_width = 2; - int32_t stride_height = 2; - int32_t filter_width = 2; - int32_t filter_height = 2; - - float outputData[4]; - const nnfw::rt::Shape outputShape = {OperandType::FLOAT32, {1, 2, 2, 1}, 1.0, 0}; - bool bret; - - float value = 1.0f; - input.initValue([&value](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { return value++; }); - - util::initData(outputData, sizeof(outputData) / sizeof(outputData[0]), 0.0); - - int32_t activation = ANEURALNETWORKS_FUSED_NONE; - - bret = maxPoolFloat32(input.ptr(), inputShape, padding_left, padding_right, padding_top, - padding_bottom, stride_width, stride_height, filter_width, filter_height, - activation, outputData, outputShape); - EXPECT_EQ(bret, true); - - float expectData[] = {5.0f, 6.0f, 8.0f, 9.0f}; - bret = util::compareData(outputData, expectData, outputShape); - EXPECT_EQ(bret, true); -} - -TEST(KernelACL_TC, maxPoolFloat32_147x147to73x73) -{ - util::TensorWrapper input({1, 147, 147, 64}); - util::TensorWrapper output({1, 73, 73, 64}); - - int32_t padding_left = 0; - int32_t padding_right = 0; - int32_t padding_top = 0; - int32_t padding_bottom = 0; - int32_t stride_width = 2; - int32_t stride_height = 2; - int32_t filter_width = 3; - int32_t filter_height = 3; - - input.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { return 1.0f; }); - - output.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { return 0.f; }); - - int32_t activation = ANEURALNETWORKS_FUSED_NONE; - - bool bret = maxPoolFloat32(input.ptr(), input.shape(), padding_left, padding_right, - padding_top, padding_bottom, stride_width, stride_height, filter_width, - filter_height, activation, output.ptr(), output.shape()); - EXPECT_EQ(bret, true); - - util::TensorWrapper expected({1, 73, 73, 64}); - expected.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { return 1.0f; }); - - EXPECT_EQ(output, expected); -} - -TEST(KernelACL_TC, maxPoolFloat32_71x71to35x35) -{ - util::TensorWrapper input({1, 71, 71, 192}); - util::TensorWrapper output({1, 35, 35, 192}); - - int32_t padding_left = 0; - int32_t padding_right = 0; - int32_t padding_top = 0; - int32_t padding_bottom = 0; - int32_t stride_width = 2; - int32_t stride_height = 2; - int32_t filter_width = 3; - int32_t filter_height = 3; - - input.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { return 1.0f; }); - - output.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { return 0.f; }); - - int32_t activation = ANEURALNETWORKS_FUSED_NONE; - - bool bret = maxPoolFloat32(input.ptr(), input.shape(), padding_left, padding_right, - padding_top, padding_bottom, stride_width, stride_height, filter_width, - filter_height, activation, output.ptr(), output.shape()); - EXPECT_EQ(bret, true); - - util::TensorWrapper expected({1, 35, 35, 192}); - expected.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { return 1.0f; }); - - EXPECT_EQ(output, expected); -} - -TEST(KernelACL_TC, averagePoolFloat32_3x3to1x1) -{ - util::TensorWrapper input({1, 3, 3, 1}); - const nnfw::rt::Shape inputShape = {OperandType::FLOAT32, {1, 3, 3, 1}, 1.0, 0}; - int32_t padding_left = 0; - int32_t padding_right = 0; - int32_t padding_top = 0; - int32_t padding_bottom = 0; - int32_t stride_width = 1; - int32_t stride_height = 1; - int32_t filter_width = 3; - int32_t filter_height = 3; - - float outputData[1]; - const nnfw::rt::Shape outputShape = {OperandType::FLOAT32, {1, 1, 1, 1}, 1.0, 0}; - bool bret; - - float value = 1.0f; - input.initValue([&value](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { return value++; }); - - util::initData(outputData, sizeof(outputData) / sizeof(outputData[0]), 0.0); - - int32_t activation = ANEURALNETWORKS_FUSED_NONE; - - bret = averagePoolFloat32(input.ptr(), inputShape, padding_left, padding_right, - padding_top, padding_bottom, stride_width, stride_height, filter_width, - filter_height, activation, outputData, outputShape); - EXPECT_EQ(bret, true); - - float expectData[] = {5.0f}; - bret = util::compareData(outputData, expectData, outputShape); - EXPECT_EQ(bret, true); -} - -TEST(KernelACL_TC, averagePoolFloat32_3x3to1x1_RELU) -{ - util::TensorWrapper input({1, 3, 3, 1}); - const nnfw::rt::Shape inputShape = {OperandType::FLOAT32, {1, 3, 3, 1}, 1.0, 0}; - int32_t padding_left = 0; - int32_t padding_right = 0; - int32_t padding_top = 0; - int32_t padding_bottom = 0; - int32_t stride_width = 1; - int32_t stride_height = 1; - int32_t filter_width = 3; - int32_t filter_height = 3; - - float outputData[1]; - const nnfw::rt::Shape outputShape = {OperandType::FLOAT32, {1, 1, 1, 1}, 1.0, 0}; - bool bret; - - float value = 3.0f; - input.initValue([&value](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { return value--; }); - - util::initData(outputData, sizeof(outputData) / sizeof(outputData[0]), 0.0); - - int32_t activation = ANEURALNETWORKS_FUSED_RELU; - - bret = averagePoolFloat32(input.ptr(), inputShape, padding_left, padding_right, - padding_top, padding_bottom, stride_width, stride_height, filter_width, - filter_height, activation, outputData, outputShape); - EXPECT_EQ(bret, true); - - float expectData[] = {0.0f}; - bret = util::compareData(outputData, expectData, outputShape); - EXPECT_EQ(bret, true); -} - -TEST(KernelACL_TC, averagePoolFloat32_3x3to2x2) -{ - util::TensorWrapper input({1, 3, 3, 1}); - const nnfw::rt::Shape inputShape = {OperandType::FLOAT32, {1, 3, 3, 1}, 1.0, 0}; - int32_t padding_left = 0; - int32_t padding_right = 0; - int32_t padding_top = 0; - int32_t padding_bottom = 0; - int32_t stride_width = 1; - int32_t stride_height = 1; - int32_t filter_width = 2; - int32_t filter_height = 2; - - float outputData[4]; - const nnfw::rt::Shape outputShape = {OperandType::FLOAT32, {1, 2, 2, 1}, 1.0, 0}; - bool bret; - - float value = 1.0f; - input.initValue([&value](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { return value++; }); - - util::initData(outputData, sizeof(outputData) / sizeof(outputData[0]), 0.0); - - int32_t activation = ANEURALNETWORKS_FUSED_NONE; - - bret = averagePoolFloat32(input.ptr(), inputShape, padding_left, padding_right, - padding_top, padding_bottom, stride_width, stride_height, filter_width, - filter_height, activation, outputData, outputShape); - EXPECT_EQ(bret, true); - - float expectData[] = {3.0f, 4.0f, 6.0f, 7.0f}; - bret = util::compareData(outputData, expectData, outputShape); - EXPECT_EQ(bret, true); -} - -TEST(KernelACL_TC, averagePoolFloat32_3x3to3x3) -{ - std::vector dims = {1, 3, 3, 1}; - util::TensorWrapper input(dims); - util::TensorWrapper output(dims); - - int32_t padding_left = 1; - int32_t padding_right = 1; - int32_t padding_top = 1; - int32_t padding_bottom = 1; - int32_t stride_width = 1; - int32_t stride_height = 1; - int32_t filter_width = 3; - int32_t filter_height = 3; - - int32_t value = 1.0f; - input.initValue([&value](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { return value++; }); - - output.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { return 0.f; }); - - int32_t activation = ANEURALNETWORKS_FUSED_NONE; - - bool bret = - averagePoolFloat32(input.ptr(), input.shape(), padding_left, padding_right, - padding_top, padding_bottom, stride_width, stride_height, filter_width, - filter_height, activation, output.ptr(), output.shape()); - EXPECT_EQ(bret, true); - - util::TensorWrapper expected(dims); - float v = 2.5f; - expected.initValue([&v](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { - v = v + 0.5f; - return v; - }); - - EXPECT_EQ(output, expected); -} - -TEST(KernelACL_TC, averagePoolFloat32_35x35to35x35) -{ - int32_t N = 35; - std::vector dims = {1, 35, 35, 768}; - util::TensorWrapper input(dims); - util::TensorWrapper output(dims); - - int32_t padding_left = 1; - int32_t padding_right = 1; - int32_t padding_top = 1; - int32_t padding_bottom = 1; - int32_t stride_width = 1; - int32_t stride_height = 1; - int32_t filter_width = 3; - int32_t filter_height = 3; - - input.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { return 1.0f; }); - - output.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { return 0.f; }); - - int32_t activation = ANEURALNETWORKS_FUSED_NONE; - - bool bret = - averagePoolFloat32(input.ptr(), input.shape(), padding_left, padding_right, - padding_top, padding_bottom, stride_width, stride_height, filter_width, - filter_height, activation, output.ptr(), output.shape()); - EXPECT_EQ(bret, true); - - util::TensorWrapper expected(dims); - expected.initValue([&N](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { return 1.0f; }); - - EXPECT_EQ(output, expected); -} - -TEST(KernelACL_TC, averagePoolFloat32_8x8to1x1) -{ - util::TensorWrapper input({1, 8, 8, 2048}); - util::TensorWrapper output({1, 1, 1, 2048}); - - int32_t padding_left = 0; - int32_t padding_right = 0; - int32_t padding_top = 0; - int32_t padding_bottom = 0; - int32_t stride_width = 2; - int32_t stride_height = 2; - int32_t filter_width = 8; - int32_t filter_height = 8; - - input.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { return 1.0f; }); - - output.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { return 0.f; }); - - int32_t activation = ANEURALNETWORKS_FUSED_NONE; - - bool bret = - averagePoolFloat32(input.ptr(), input.shape(), padding_left, padding_right, - padding_top, padding_bottom, stride_width, stride_height, filter_width, - filter_height, activation, output.ptr(), output.shape()); - EXPECT_EQ(bret, true); - - util::TensorWrapper expected({1, 1, 1, 2048}); - expected.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { return 1.0f; }); - - EXPECT_EQ(output, expected); -} diff --git a/libs/kernel/acl/src/cl/ReLU.cpp b/libs/kernel/acl/src/cl/ReLU.cpp deleted file mode 100644 index c2da5cf..0000000 --- a/libs/kernel/acl/src/cl/ReLU.cpp +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include - -#include -#include -#include "../IO_accessor.h" -#include "../shape.h" -#include "../UniqueTensor.h" -#include "../util.h" - -namespace nnfw -{ -namespace kernel -{ -namespace acl -{ - -bool reluFloat32(const float *inputData, const nnfw::rt::Shape &inputShape, float *outputData, - const nnfw::rt::Shape &outputShape) -{ - arm_compute::TensorShape input_shape = util::fromNNShape(inputShape); - arm_compute::TensorShape output_shape = util::fromNNShape(outputShape); - - CLUniqueTensor input(arm_compute::TensorInfo(input_shape, arm_compute::Format::F32)); - CLUniqueTensor output(arm_compute::TensorInfo(output_shape, arm_compute::Format::F32)); - - const ::arm_compute::ActivationLayerInfo act_info{ - ::arm_compute::ActivationLayerInfo::ActivationFunction::RELU}; - - auto relu_f = std::make_shared(); - relu_f->configure(input.ptr(), output.ptr(), act_info); - - input.allocate(); - output.allocate(); - - if (inputShape.dimensions.size() == 4) - { - TensorAccess(input.ref(), inputData, inputShape); - - relu_f->run(); - - arm_compute::CLScheduler::get().sync(); - - TensorAccess(output.ref(), outputData, outputShape); - } - else if (inputShape.dimensions.size() == 2) - { - TensorAccess(input.ref(), inputData, inputShape); - - relu_f->run(); - - arm_compute::CLScheduler::get().sync(); - - TensorAccess(output.ref(), outputData, outputShape); - } - else - { - assert("undefined dimension of input" && 0); - return false; - } - - return true; -} - -} // namespace acl -} // namespace kernel -} // namespace nnfw diff --git a/libs/kernel/acl/src/cl/ReLU.test.cpp b/libs/kernel/acl/src/cl/ReLU.test.cpp deleted file mode 100644 index ef2eecf..0000000 --- a/libs/kernel/acl/src/cl/ReLU.test.cpp +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include - -#include "../util.h" - -using namespace nnfw::kernel::acl; - -TEST(KernelACL_TC, reluFloat32_2d) -{ - uint32_t input_h = 3; - uint32_t input_w = 3; - uint32_t output_h = input_h; - uint32_t output_w = input_w; - - util::TensorWrapper input({input_h, input_w}); - util::TensorWrapper output({output_h, output_w}); - - float nv = -10.f; - float pv = 10.f; - - input.initValue([&](uint32_t h, uint32_t w) { - if (h < w) - return nv; - else - return pv; - }); - - output.initValue([](uint32_t h, uint32_t w) { return 0.f; }); - - bool bret = reluFloat32(input.ptr(), input.shape(), output.ptr(), output.shape()); - EXPECT_EQ(bret, true); - - util::TensorWrapper expected({output_h, output_w}); - expected.initValue([&](uint32_t h, uint32_t w) { - if (h < w) - return 0.f; - else - return pv; - }); - - bret = util::compareData(output.ptr(), expected.ptr(), output.shape()); - EXPECT_EQ(bret, true); -} - -TEST(KernelACL_TC, reluFloat32_4d) -{ - uint32_t input_n = 1; - uint32_t input_c = 3; - uint32_t input_h = 3; - uint32_t input_w = 3; - uint32_t output_n = input_n; - uint32_t output_c = input_c; - uint32_t output_h = input_h; - uint32_t output_w = input_w; - - util::TensorWrapper input({input_n, input_h, input_w, input_c}); - util::TensorWrapper output({output_n, output_h, output_w, output_c}); - - float nv = -10.f; - float pv = 10.f; - - input.initValue([&](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { - if (h < w) - return nv; - else - return pv; - }); - - output.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { return 0.f; }); - - bool bret = reluFloat32(input.ptr(), input.shape(), output.ptr(), output.shape()); - EXPECT_EQ(bret, true); - - util::TensorWrapper expected({output_n, output_h, output_w, output_c}); - expected.initValue([&](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { - if (h < w) - return 0.f; - else - return pv; - }); - - bret = util::compareData(output.ptr(), expected.ptr(), output.shape()); - EXPECT_EQ(bret, true); -} diff --git a/libs/kernel/acl/src/cl/ReLU6.cpp b/libs/kernel/acl/src/cl/ReLU6.cpp deleted file mode 100644 index 992cd85..0000000 --- a/libs/kernel/acl/src/cl/ReLU6.cpp +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include - -#include -#include -#include "../IO_accessor.h" -#include "../shape.h" -#include "../UniqueTensor.h" -#include "../util.h" - -namespace nnfw -{ -namespace kernel -{ -namespace acl -{ - -bool relu6Float32(const float *inputData, const nnfw::rt::Shape &inputShape, float *outputData, - const nnfw::rt::Shape &outputShape) -{ - arm_compute::TensorShape input_shape = util::fromNNShape(inputShape); - arm_compute::TensorShape output_shape = util::fromNNShape(outputShape); - - CLUniqueTensor input(arm_compute::TensorInfo(input_shape, arm_compute::Format::F32)); - CLUniqueTensor output(arm_compute::TensorInfo(output_shape, arm_compute::Format::F32)); - - const ::arm_compute::ActivationLayerInfo act_info{ - ::arm_compute::ActivationLayerInfo::ActivationFunction::BOUNDED_RELU, 6.0f}; - - auto relu_f = std::make_shared(); - relu_f->configure(input.ptr(), output.ptr(), act_info); - - input.allocate(); - output.allocate(); - - if (inputShape.dimensions.size() == 4) - { - TensorAccess(input.ref(), inputData, inputShape); - - relu_f->run(); - - arm_compute::CLScheduler::get().sync(); - - TensorAccess(output.ref(), outputData, outputShape); - } - else if (inputShape.dimensions.size() == 2) - { - TensorAccess(input.ref(), inputData, inputShape); - - relu_f->run(); - - arm_compute::CLScheduler::get().sync(); - - TensorAccess(output.ref(), outputData, outputShape); - } - else - { - assert("undefined dimension of input" && 0); - return false; - } - - return true; -} - -bool relu6LUFloat32(const float *inputData, const nnfw::rt::Shape &inputShape, float *outputData, - const nnfw::rt::Shape &outputShape) -{ - arm_compute::TensorShape input_shape = util::fromNNShape(inputShape); - arm_compute::TensorShape output_shape = util::fromNNShape(outputShape); - - CLUniqueTensor input(arm_compute::TensorInfo(input_shape, arm_compute::Format::F32)); - CLUniqueTensor output(arm_compute::TensorInfo(output_shape, arm_compute::Format::F32)); - - const ::arm_compute::ActivationLayerInfo act_info{ - ::arm_compute::ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU, 6.0f, 0.0f}; - - auto relu_f = std::make_shared(); - relu_f->configure(input.ptr(), output.ptr(), act_info); - - input.allocate(); - output.allocate(); - - if (inputShape.dimensions.size() == 4) - { - TensorAccess(input.ref(), inputData, inputShape); - - relu_f->run(); - - arm_compute::CLScheduler::get().sync(); - - TensorAccess(output.ref(), outputData, outputShape); - } - else if (inputShape.dimensions.size() == 2) - { - TensorAccess(input.ref(), inputData, inputShape); - - relu_f->run(); - - arm_compute::CLScheduler::get().sync(); - - TensorAccess(output.ref(), outputData, outputShape); - } - else - { - assert("undefined dimension of input" && 0); - return false; - } - - return true; -} - -} // namespace acl -} // namespace kernel -} // namespace nnfw diff --git a/libs/kernel/acl/src/cl/ReLU6.test.cpp b/libs/kernel/acl/src/cl/ReLU6.test.cpp deleted file mode 100644 index 3b6e257..0000000 --- a/libs/kernel/acl/src/cl/ReLU6.test.cpp +++ /dev/null @@ -1,203 +0,0 @@ -/* - * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include - -#include "../util.h" - -using namespace nnfw::kernel::acl; - -TEST(KernelACL_TC, relu6Float32_2d) -{ - uint32_t input_h = 3; - uint32_t input_w = 3; - uint32_t output_h = input_h; - uint32_t output_w = input_w; - - util::TensorWrapper input({input_h, input_w}); - util::TensorWrapper output({output_h, output_w}); - - float nv = -10.f; - float p1v = 3.f; - float p2v = 10.f; - - input.initValue([&](uint32_t h, uint32_t w) { - if (h < w) - return nv; - else if (h == w) - return p1v; - else - return p2v; - }); - - output.initValue([](uint32_t h, uint32_t w) { return 0.f; }); - - bool bret = relu6Float32(input.ptr(), input.shape(), output.ptr(), output.shape()); - EXPECT_EQ(bret, true); - - util::TensorWrapper expected({output_h, output_w}); - expected.initValue([&](uint32_t h, uint32_t w) { - if (h < w) - return 0.f; - else if (h == w) - return p1v; - else - return 6.f; - }); - - bret = util::compareData(output.ptr(), expected.ptr(), output.shape()); - EXPECT_EQ(bret, true); -} - -TEST(KernelACL_TC, relu6LUFloat32_2d) -{ - uint32_t input_h = 3; - uint32_t input_w = 3; - uint32_t output_h = input_h; - uint32_t output_w = input_w; - - util::TensorWrapper input({input_h, input_w}); - util::TensorWrapper output({output_h, output_w}); - - float nv = -10.f; - float p1v = 3.f; - float p2v = 10.f; - - input.initValue([&](uint32_t h, uint32_t w) { - if (h < w) - return nv; - else if (h == w) - return p1v; - else - return p2v; - }); - - output.initValue([](uint32_t h, uint32_t w) { return 0.f; }); - - bool bret = - relu6LUFloat32(input.ptr(), input.shape(), output.ptr(), output.shape()); - EXPECT_EQ(bret, true); - - util::TensorWrapper expected({output_h, output_w}); - expected.initValue([&](uint32_t h, uint32_t w) { - if (h < w) - return 0.f; - else if (h == w) - return p1v; - else - return 6.f; - }); - - bret = util::compareData(output.ptr(), expected.ptr(), output.shape()); - EXPECT_EQ(bret, true); -} - -TEST(KernelACL_TC, relu6Float32_4d) -{ - uint32_t input_n = 1; - uint32_t input_c = 3; - uint32_t input_h = 3; - uint32_t input_w = 3; - uint32_t output_n = input_n; - uint32_t output_c = input_c; - uint32_t output_h = input_h; - uint32_t output_w = input_w; - - util::TensorWrapper input({input_n, input_h, input_w, input_c}); - util::TensorWrapper output({output_n, output_h, output_w, output_c}); - - float nv = -10.f; - float p1v = 3.f; - float p2v = 10.f; - - input.initValue([&](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { - if (h < w) - return nv; - else if (h == w) - return p1v; - else - return p2v; - }); - - output.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { return 0.f; }); - - bool bret = relu6Float32(input.ptr(), input.shape(), output.ptr(), output.shape()); - EXPECT_EQ(bret, true); - - util::TensorWrapper expected({output_n, output_h, output_w, output_c}); - expected.initValue([&](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { - if (h < w) - return 0.f; - else if (h == w) - return p1v; - else - return 6.f; - }); - - bret = util::compareData(output.ptr(), expected.ptr(), output.shape()); - EXPECT_EQ(bret, true); -} - -TEST(KernelACL_TC, relu6LUFloat32_4d) -{ - uint32_t input_n = 1; - uint32_t input_c = 3; - uint32_t input_h = 3; - uint32_t input_w = 3; - uint32_t output_n = input_n; - uint32_t output_c = input_c; - uint32_t output_h = input_h; - uint32_t output_w = input_w; - - util::TensorWrapper input({input_n, input_h, input_w, input_c}); - util::TensorWrapper output({output_n, output_h, output_w, output_c}); - - float nv = -10.f; - float p1v = 3.f; - float p2v = 10.f; - - input.initValue([&](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { - if (h < w) - return nv; - else if (h == w) - return p1v; - else - return p2v; - }); - - output.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { return 0.f; }); - - bool bret = - relu6LUFloat32(input.ptr(), input.shape(), output.ptr(), output.shape()); - EXPECT_EQ(bret, true); - - util::TensorWrapper expected({output_n, output_h, output_w, output_c}); - expected.initValue([&](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { - if (h < w) - return 0.f; - else if (h == w) - return p1v; - else - return 6.f; - }); - - bret = util::compareData(output.ptr(), expected.ptr(), output.shape()); - EXPECT_EQ(bret, true); -} diff --git a/libs/kernel/acl/src/cl/Reshape.cpp b/libs/kernel/acl/src/cl/Reshape.cpp deleted file mode 100644 index 707333e..0000000 --- a/libs/kernel/acl/src/cl/Reshape.cpp +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include - -// TODO: fix include path in CMakeFiles -#include "../IO_accessor.h" -#include "../shape.h" -#include "../UniqueTensor.h" -#include "../Reshape.h" - -namespace nnfw -{ -namespace kernel -{ -namespace acl -{ - -static void sync_scheduler() { arm_compute::CLScheduler::get().sync(); } - -bool reshapeGeneric(const void *inputData, const nnfw::rt::Shape &inputShape, void *outputData, - const nnfw::rt::Shape &outputShape) -{ - return common::reshapeGeneric( - inputData, inputShape, outputData, outputShape, sync_scheduler); -} - -} // namespace acl -} // namespace kernel -} // namespace nnfw diff --git a/libs/kernel/acl/src/cl/Reshape.test.cpp b/libs/kernel/acl/src/cl/Reshape.test.cpp deleted file mode 100644 index db23a6d..0000000 --- a/libs/kernel/acl/src/cl/Reshape.test.cpp +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#define ACL_CORE_FUNC_NAME reshapeGeneric -#define ACL_TEST(tc, t) TEST(tc, cl_##t) - -#include "../Reshape.test.h" diff --git a/libs/kernel/acl/src/cl/Softmax.cpp b/libs/kernel/acl/src/cl/Softmax.cpp deleted file mode 100644 index 09a430a..0000000 --- a/libs/kernel/acl/src/cl/Softmax.cpp +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include - -#include -#include -#include "../IO_accessor.h" -#include "../shape.h" -#include "../UniqueTensor.h" -#include "../util.h" - -namespace nnfw -{ -namespace kernel -{ -namespace acl -{ - -bool softmaxFloat32(const float *inputData, const nnfw::rt::Shape &inputShape, const float beta, - float *outputData, const nnfw::rt::Shape &outputShape) -{ - arm_compute::TensorShape input_shape = util::fromNNShape(inputShape); - arm_compute::TensorShape output_shape = util::fromNNShape(outputShape); - - CLUniqueTensor input(arm_compute::TensorInfo(input_shape, arm_compute::Format::F32)); - CLUniqueTensor output(arm_compute::TensorInfo(output_shape, arm_compute::Format::F32)); - - auto softmax_f = std::make_shared(); - softmax_f->configure(input.ptr(), output.ptr(), beta); - - input.allocate(); - output.allocate(); - - if (inputShape.dimensions.size() == 4) - { - TensorAccess(input.ref(), inputData, inputShape); - - softmax_f->run(); - - arm_compute::CLScheduler::get().sync(); - - TensorAccess(output.ref(), outputData, outputShape); - } - else if (inputShape.dimensions.size() == 2) - { - TensorAccess(input.ref(), inputData, inputShape); - - softmax_f->run(); - - arm_compute::CLScheduler::get().sync(); - - TensorAccess(output.ref(), outputData, outputShape); - } - else - { - assert("undefined dimension of input" && 0); - return false; - } - - return true; -} - -} // namespace acl -} // namespace kernel -} // namespace nnfw diff --git a/libs/kernel/acl/src/cl/Softmax.test.cpp b/libs/kernel/acl/src/cl/Softmax.test.cpp deleted file mode 100644 index d121314..0000000 --- a/libs/kernel/acl/src/cl/Softmax.test.cpp +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include - -#include "../util.h" - -using namespace nnfw::kernel::acl; - -TEST(KernelACL_TC, softmaxFloat32_1xn) -{ - float inputData[4]; - const nnfw::rt::Shape inputShape = {OperandType::FLOAT32, {1, 4}, 1.0, 0}; - float outputData[4]; - const nnfw::rt::Shape outputShape = {OperandType::FLOAT32, {1, 4}, 1.0, 0}; - const float beta = 1.0f; - bool bret; - - util::initData(inputData, sizeof(inputData) / sizeof(inputData[0]), 1.0); - util::initData(outputData, sizeof(outputData) / sizeof(outputData[0]), 0.0); - - bret = softmaxFloat32(inputData, inputShape, beta, outputData, outputShape); - EXPECT_EQ(bret, true); - - float expectData[] = {0.25f, 0.25f, 0.25f, 0.25f}; - bret = util::compareData(outputData, expectData, outputShape); - EXPECT_EQ(bret, true); -} - -TEST(KernelACL_TC, softmaxFloat32_4d) -{ - float inputData[4]; - const nnfw::rt::Shape inputShape = {OperandType::FLOAT32, {1, 1, 4, 1}, 1.0, 0}; - float outputData[4]; - const nnfw::rt::Shape outputShape = {OperandType::FLOAT32, {1, 1, 4, 1}, 1.0, 0}; - const float beta = 1.0f; - bool bret; - - util::initData(inputData, sizeof(inputData) / sizeof(inputData[0]), 1.0); - util::initData(outputData, sizeof(outputData) / sizeof(outputData[0]), 0.0); - - bret = softmaxFloat32(inputData, inputShape, beta, outputData, outputShape); - EXPECT_EQ(bret, true); - - float expectData[] = {0.25f, 0.25f, 0.25f, 0.25f}; - bret = util::compareData(outputData, expectData, outputShape); - EXPECT_EQ(bret, true); -} - -TEST(KernelACL_TC, softmaxFloat32_1xn_seq) -{ - float inputData[4]; - const nnfw::rt::Shape inputShape = {OperandType::FLOAT32, {1, 4}, 1.0, 0}; - float outputData[4]; - const nnfw::rt::Shape outputShape = {OperandType::FLOAT32, {1, 4}, 1.0, 0}; - const float beta = 1.0f; - bool bret; - - util::initData_Increasing(inputData, sizeof(inputData) / sizeof(inputData[0]), 1.0); - util::initData(outputData, sizeof(outputData) / sizeof(outputData[0]), 0.0); - - bret = softmaxFloat32(inputData, inputShape, beta, outputData, outputShape); - EXPECT_EQ(bret, true); - - float expectData[] = {0.032058603280085, 0.0871443187420326, 0.23688281808991, 0.643914259887972}; - bret = util::compareData(outputData, expectData, outputShape); - EXPECT_EQ(bret, true); -} - -TEST(KernelACL_TC, softmaxFloat32_4d_seq) -{ - float inputData[4]; - const nnfw::rt::Shape inputShape = {OperandType::FLOAT32, {1, 1, 4, 1}, 1.0, 0}; - float outputData[4]; - const nnfw::rt::Shape outputShape = {OperandType::FLOAT32, {1, 1, 4, 1}, 1.0, 0}; - const float beta = 1.0f; - bool bret; - - util::initData_Increasing(inputData, sizeof(inputData) / sizeof(inputData[0]), 1.0); - util::initData(outputData, sizeof(outputData) / sizeof(outputData[0]), 0.0); - - bret = softmaxFloat32(inputData, inputShape, beta, outputData, outputShape); - EXPECT_EQ(bret, true); - - float expectData[] = {0.032058603280085, 0.0871443187420326, 0.23688281808991, 0.643914259887972}; - bret = util::compareData(outputData, expectData, outputShape); - EXPECT_EQ(bret, true); -} diff --git a/libs/kernel/acl/src/gtest_env.cpp b/libs/kernel/acl/src/gtest_env.cpp deleted file mode 100644 index d17fcbe..0000000 --- a/libs/kernel/acl/src/gtest_env.cpp +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include - -class TestEnvironment : public ::testing::Environment -{ -public: - virtual ~TestEnvironment() = default; - - virtual void SetUp() { nnfw::kernel::acl::Initialize(); } - - virtual void TearDown() - { - // DO NOTHING - } -}; - -static ::testing::Environment *const testingenv = - ::testing::AddGlobalTestEnvironment(new TestEnvironment); diff --git a/libs/kernel/acl/src/neon/Add.cpp b/libs/kernel/acl/src/neon/Add.cpp deleted file mode 100644 index a95f3c8..0000000 --- a/libs/kernel/acl/src/neon/Add.cpp +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include - -// TODO: fix include path in CMakeFiles -#include "../IO_accessor.h" -#include "../shape.h" -#include "../UniqueTensor.h" -#include "../util.h" - -namespace nnfw -{ -namespace kernel -{ -namespace acl -{ -namespace neon -{ -// TODO : Currently, handles addition of vector+vector, matrix(upto 4D)+matrix(upto 4D) -// TODO : broadcasting is not supported -bool addFloat32(const float *inputData1, const nnfw::rt::Shape &inputShape1, - const float *inputData2, const nnfw::rt::Shape &inputShape2, int32_t activation, - float *outputData, const nnfw::rt::Shape &outputShape) -{ - // TODO: scalar addition is not implemented currently - assert((inputShape1.dimensions.size() >= 1) && (inputShape2.dimensions.size() >= 1)); - - // TODO: broadcasting is not implemented currently - assert(inputShape1.dimensions.size() == inputShape2.dimensions.size()); - - auto input_shape1 = util::fromNNShape(inputShape1); - auto input_shape2 = util::fromNNShape(inputShape2); - auto output_shape = util::fromNNShape(outputShape); - - NEUniqueTensor input1(arm_compute::TensorInfo(input_shape1, arm_compute::Format::F32)); - NEUniqueTensor input2(arm_compute::TensorInfo(input_shape2, arm_compute::Format::F32)); - NEUniqueTensor output(arm_compute::TensorInfo(output_shape, arm_compute::Format::F32)); - - std::vector> fns; - - auto add_f = std::make_shared(); - - // Regarding ConvertPolocy, refer to - // https://www.mathworks.com/help/fixedpoint/ug/saturation-and-wrapping.html - // TODO: check if using arm_compute::ConvertPolicy::SATURATE is correct - add_f->configure(input1.ptr(), input2.ptr(), output.ptr(), arm_compute::ConvertPolicy::SATURATE); - - fns.emplace_back(add_f); - - util::insertFusedActivationLayer(output, - activation, fns); - input1.allocate(); - input2.allocate(); - output.allocate(); - - if (inputShape1.dimensions.size() == 1) - TensorAccess(input1.ref(), (float *)inputData1, inputShape1); - else if (inputShape1.dimensions.size() >= 2) - TensorAccess(input1.ref(), (float *)inputData1, inputShape1); - else - assert("scalar addition is not implemented"); - - if (inputShape2.dimensions.size() == 1) - TensorAccess(input2.ref(), (float *)inputData2, inputShape2); - else if (inputShape2.dimensions.size() >= 2) - TensorAccess(input2.ref(), (float *)inputData2, inputShape2); - else - assert("scalar addition is not implemented"); - - for (const auto &fn : fns) - { - fn->run(); - } - - if (outputShape.dimensions.size() == 1) - TensorAccess(output.ref(), (float *)outputData, outputShape); - else // outputShape.dimensions.size() >= 2 - TensorAccess(output.ref(), (float *)outputData, outputShape); - - return true; -} - -} // namespace neon -} // namespace acl -} // namespace kernel -} // namespace nnfw diff --git a/libs/kernel/acl/src/neon/Add.test.cpp b/libs/kernel/acl/src/neon/Add.test.cpp deleted file mode 100644 index e141917..0000000 --- a/libs/kernel/acl/src/neon/Add.test.cpp +++ /dev/null @@ -1,189 +0,0 @@ -/* - * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include - -// TODO: fix include path in CMakeFiles -#include "../util.h" -#include "../Add.test.h" // test data - -using namespace nnfw::kernel::acl; -// using nnfw::add_vector_test; - -TEST(KernelACL_TC, neon_addFloat32_vector_1) -{ - const int DIM = 1; - - const nnfw::rt::Shape inputShape1 = {OperandType::FLOAT32, {DIM}, 1.0, 0}; - const nnfw::rt::Shape inputShape2 = {OperandType::FLOAT32, {DIM}, 1.0, 0}; - - std::vector inputDataPtrs; - std::vector inputShapes; - float outputData[DIM]; - const nnfw::rt::Shape outputShape = {OperandType::FLOAT32, {DIM}, 1.0, 0}; - bool bret; - int32_t activation = static_cast(FusedActivationFunc::NONE); - - util::initData(outputData, sizeof(outputData) / sizeof(outputData[0]), 0.0); - - bret = neon::addFloat32(nnfw::add_vector_test::x1, inputShape1, nnfw::add_vector_test::y1, - inputShape2, activation, outputData, outputShape); - - EXPECT_EQ(bret, true); - - bret = util::compareData(outputData, nnfw::add_vector_test::expected1, outputShape); - EXPECT_EQ(bret, true); -} - -TEST(KernelACL_TC, neon_addFloat32_vector_100) -{ - const int DIM = 100; - - const nnfw::rt::Shape inputShape1 = {OperandType::FLOAT32, {DIM}, 1.0, 0}; - const nnfw::rt::Shape inputShape2 = {OperandType::FLOAT32, {DIM}, 1.0, 0}; - - std::vector inputDataPtrs; - std::vector inputShapes; - float outputData[DIM]; - const nnfw::rt::Shape outputShape = {OperandType::FLOAT32, {DIM}, 1.0, 0}; - bool bret; - int32_t activation = static_cast(FusedActivationFunc::NONE); - - util::initData(outputData, sizeof(outputData) / sizeof(outputData[0]), 0.0); - - bret = neon::addFloat32(nnfw::add_vector_test::x2, inputShape1, nnfw::add_vector_test::y2, - inputShape2, activation, outputData, outputShape); - - EXPECT_EQ(bret, true); - - bret = util::compareData(outputData, nnfw::add_vector_test::expected2, outputShape); - EXPECT_EQ(bret, true); -} - -TEST(KernelACL_TC, neon_addFloat32_relu_vector_100) -{ - const int DIM = 10; - - const nnfw::rt::Shape inputShape1 = {OperandType::FLOAT32, {DIM}, 1.0, 0}; - const nnfw::rt::Shape inputShape2 = {OperandType::FLOAT32, {DIM}, 1.0, 0}; - - std::vector inputDataPtrs; - std::vector inputShapes; - float outputData[DIM]; - const nnfw::rt::Shape outputShape = {OperandType::FLOAT32, {DIM}, 1.0, 0}; - bool bret; - int32_t activation = static_cast(FusedActivationFunc::RELU); - - util::initData(outputData, sizeof(outputData) / sizeof(outputData[0]), 0.0); - - bret = neon::addFloat32(nnfw::add_vector_test::x3, inputShape1, nnfw::add_vector_test::y3, - inputShape2, activation, outputData, outputShape); - - EXPECT_EQ(bret, true); - - bret = util::compareData(outputData, nnfw::add_vector_test::expected3, outputShape); - EXPECT_EQ(bret, true); -} - -// 2D + 2D -#define GTEST_TC_DIM 2, 6 -#define GTEST_TC_OUTPUT_SIZE 12 - -TEST(KernelACL_TC, neon_addFloat_2Dx2D) -{ - const nnfw::rt::Shape inputShape1 = {OperandType::FLOAT32, {GTEST_TC_DIM}, 1.0, 0}; - const nnfw::rt::Shape inputShape2 = {OperandType::FLOAT32, {GTEST_TC_DIM}, 1.0, 0}; - - std::vector inputDataPtrs; - std::vector inputShapes; - float outputData[GTEST_TC_OUTPUT_SIZE]; - const nnfw::rt::Shape outputShape = {OperandType::FLOAT32, {GTEST_TC_DIM}, 1.0, 0}; - bool bret; - - util::initData(outputData, sizeof(outputData) / sizeof(outputData[0]), 0.0); - - bret = neon::addFloat32((float *)nnfw::add_matrix_test::x_2d_1, inputShape1, - (float *)nnfw::add_matrix_test::y_2d_1, inputShape2, - static_cast(FusedActivationFunc::NONE), outputData, outputShape); - - EXPECT_EQ(bret, true); - - bret = util::compareData(outputData, (float *)nnfw::add_matrix_test::expected_2d_1, outputShape); - EXPECT_EQ(bret, true); -} -#undef GTEST_TC_DIM -#undef GTEST_TC_OUTPUT_SIZE - -//-------- 3D + 3D -#define GTEST_TC_DIM 2, 2, 6 -#define GTEST_TC_OUTPUT_SIZE 2 * 2 * 6 - -TEST(KernelACL_TC, neon_addFloat_3Dx3D) -{ - const nnfw::rt::Shape inputShape1 = {OperandType::FLOAT32, {GTEST_TC_DIM}, 1.0, 0}; - const nnfw::rt::Shape inputShape2 = {OperandType::FLOAT32, {GTEST_TC_DIM}, 1.0, 0}; - - std::vector inputDataPtrs; - std::vector inputShapes; - float outputData[GTEST_TC_OUTPUT_SIZE]; - const nnfw::rt::Shape outputShape = {OperandType::FLOAT32, {GTEST_TC_DIM}, 1.0, 0}; - bool bret; - - util::initData(outputData, sizeof(outputData) / sizeof(outputData[0]), 0.0); - - bret = neon::addFloat32((float *)nnfw::add_matrix_test::x_3d_1, inputShape1, - (float *)nnfw::add_matrix_test::y_3d_1, inputShape2, - static_cast(FusedActivationFunc::NONE), outputData, outputShape); - - EXPECT_EQ(bret, true); - - bret = util::compareData(outputData, (float *)nnfw::add_matrix_test::expected_3d_1, outputShape); - EXPECT_EQ(bret, true); -} -#undef GTEST_TC_DIM -#undef GTEST_TC_OUTPUT_SIZE - -//----- 4D + 4D -#define GTEST_TC_DIM 2, 2, 2, 6 -#define GTEST_TC_OUTPUT_SIZE 2 * 2 * 2 * 6 - -TEST(KernelACL_TC, neon_addFloat_4Dx4D_1) -{ - const nnfw::rt::Shape inputShape1 = {OperandType::FLOAT32, {GTEST_TC_DIM}, 1.0, 0}; - const nnfw::rt::Shape inputShape2 = {OperandType::FLOAT32, {GTEST_TC_DIM}, 1.0, 0}; - - std::vector inputDataPtrs; - std::vector inputShapes; - float outputData[GTEST_TC_OUTPUT_SIZE]; - const nnfw::rt::Shape outputShape = {OperandType::FLOAT32, {GTEST_TC_DIM}, 1.0, 0}; - bool bret; - - util::initData(outputData, sizeof(outputData) / sizeof(outputData[0]), 0.0); - - bret = neon::addFloat32((float *)nnfw::add_matrix_test::x_4d_1, inputShape1, - (float *)nnfw::add_matrix_test::y_4d_1, inputShape2, - static_cast(FusedActivationFunc::NONE), outputData, outputShape); - - EXPECT_EQ(bret, true); - - bret = util::compareData(outputData, (float *)nnfw::add_matrix_test::expected_4d_1, outputShape); - EXPECT_EQ(bret, true); -} -#undef GTEST_TC_DIM -#undef GTEST_TC_OUTPUT_SIZE diff --git a/libs/kernel/acl/src/neon/Concatenation.cpp b/libs/kernel/acl/src/neon/Concatenation.cpp deleted file mode 100644 index 2b494eb..0000000 --- a/libs/kernel/acl/src/neon/Concatenation.cpp +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include - -#include - -// TODO: fix include path in CMakeFiles -#include "../IO_accessor.h" -#include "../shape.h" - -namespace nnfw -{ -namespace kernel -{ -namespace acl -{ -namespace neon -{ - -bool concatenationFloat32(const std::vector &inputDataPtrs, - const std::vector &inputShapes, int32_t axis, - float *outputData, const nnfw::rt::Shape &outputShape) -{ - if (axis != 3) - { - assert("Only support axis=3 for ACL" && 0); - return false; - } - assert(inputDataPtrs.size() == inputShapes.size()); - - std::vector inputPtrs; - std::vector inputIptrs; - arm_compute::Tensor output; - - // init Tensors - std::vector::const_iterator it_inputShape = inputShapes.begin(); - for (auto inputData : inputDataPtrs) - { - const nnfw::rt::Shape &inputShape = *it_inputShape; - arm_compute::TensorShape input_shape = util::fromNNShape(inputShape); - arm_compute::Tensor *inputPtr = new arm_compute::Tensor(); - - inputPtr->allocator()->init(arm_compute::TensorInfo(input_shape, arm_compute::Format::F32)); - inputPtrs.push_back(inputPtr); - inputIptrs.push_back(inputPtr); - - it_inputShape++; - } - arm_compute::TensorShape output_shape = util::fromNNShape(outputShape); - output.allocator()->init(arm_compute::TensorInfo(output_shape, arm_compute::Format::F32)); - - // prepare ACL Concatenate and configure tensors - auto concat = std::make_shared(); - concat->configure(inputIptrs, &output); - - // allocate Tensors - it_inputShape = inputShapes.begin(); - std::vector::const_iterator it_inputData = inputDataPtrs.begin(); - for (auto inputPtr : inputPtrs) - { - inputPtr->allocator()->allocate(); - - const float *inputData = *it_inputData; - const nnfw::rt::Shape &inputShape = *it_inputShape; - - TensorAccess(*inputPtr, inputData, inputShape); - - it_inputShape++; - it_inputData++; - } - output.allocator()->allocate(); - - // run - concat->run(); - - // get output - TensorAccess(output, outputData, outputShape); - - // cleanup - for (auto inputPtr : inputPtrs) - { - inputPtr->allocator()->free(); - delete inputPtr; - } - output.allocator()->free(); - - return true; -} - -} // namespace neon -} // namespace acl -} // namespace kernel -} // namespace nnfw diff --git a/libs/kernel/acl/src/neon/Concatenation.test.cpp b/libs/kernel/acl/src/neon/Concatenation.test.cpp deleted file mode 100644 index 4fe2451..0000000 --- a/libs/kernel/acl/src/neon/Concatenation.test.cpp +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include - -// TODO: fix include path in CMakeFiles -#include "../util.h" - -using namespace nnfw::kernel::acl; - -TEST(KernelACL_TC, neon_concatFloat32_1) -{ - float inputData_1[6] = { - 1, 2, 3, 4, 5, 6 // [ [ [1],[2],[3] ], [ [4],[5],[6] ] ] - }; - float inputData_2[6] = { - 7, 8, 9, 10, 11, 12 // [ [ [7],[8],[9] ], [ [10],[11],[12] ] ] - }; - const nnfw::rt::Shape inputShape_1 = {OperandType::FLOAT32, {1, 2, 3, 1}, 1.0, 0}; - const nnfw::rt::Shape inputShape_2 = {OperandType::FLOAT32, {1, 2, 3, 1}, 1.0, 0}; - std::vector inputDataPtrs; - std::vector inputShapes; - float outputData[12]; - const nnfw::rt::Shape outputShape = {OperandType::FLOAT32, {1, 2, 3, 2}, 1.0, 0}; - bool bret; - - inputDataPtrs.push_back(inputData_1); - inputDataPtrs.push_back(inputData_2); - inputShapes.push_back(inputShape_1); - inputShapes.push_back(inputShape_2); - - util::initData(outputData, sizeof(outputData) / sizeof(outputData[0]), 0.0); - - bret = neon::concatenationFloat32(inputDataPtrs, inputShapes, 3, outputData, outputShape); - EXPECT_EQ(bret, true); - - float expectNCHW[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; - float expectData[12]; // [ [ [1,7],[2,8],[3,9] ], [ [4,10],[5,11],[6,12] ] ] - util::NCHW2NHWC(expectNCHW, expectData, outputShape); - bret = util::compareData(outputData, expectData, outputShape); - EXPECT_EQ(bret, true); -} diff --git a/libs/kernel/acl/src/neon/Conv2D.cpp b/libs/kernel/acl/src/neon/Conv2D.cpp deleted file mode 100644 index 87372d7..0000000 --- a/libs/kernel/acl/src/neon/Conv2D.cpp +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include - -#include -#include - -#include - -#include "../IO_accessor.h" -#include "../util.h" -#include "../shape.h" -#include "../UniqueTensor.h" -#include "../support.h" - -#include "util/feature/TextFormatter.h" - -#include "support/nnapi/feature/Reader.h" - -namespace nnfw -{ -namespace kernel -{ -namespace acl -{ -namespace neon -{ - -static int verbose = 0; - -bool convFloat32(const float *inputData, const nnfw::rt::Shape &inputShape, const float *filterData, - const nnfw::rt::Shape &filterShape, const float *biasData, - const nnfw::rt::Shape &biasShape, int32_t padding_left, int32_t padding_right, - int32_t padding_top, int32_t padding_bottom, int32_t stride_width, - int32_t stride_height, int32_t activation, float *outputData, - const nnfw::rt::Shape &outputShape) -{ - arm_compute::TensorShape input_shape = util::fromNNShape(inputShape); - arm_compute::TensorShape filter_shape = util::fromNNShape(filterShape); - arm_compute::TensorShape bias_shape = util::fromVectorNNShape(biasShape); - arm_compute::TensorShape output_shape = util::fromNNShape(outputShape); - arm_compute::PadStrideInfo conv_info = arm_compute::PadStrideInfo( - stride_width, stride_height, padding_left, padding_right, padding_top, padding_bottom, - arm_compute::DimensionRoundingType::FLOOR); - - NEUniqueTensor input(arm_compute::TensorInfo(input_shape, arm_compute::Format::F32)); - NEUniqueTensor output(arm_compute::TensorInfo(output_shape, arm_compute::Format::F32)); - NEUniqueTensor bias(arm_compute::TensorInfo(bias_shape, arm_compute::Format::F32)); - NEUniqueTensor filter(arm_compute::TensorInfo(filter_shape, arm_compute::Format::F32)); - - std::vector> fns; - - auto conv_f = std::make_shared(); - - conv_f->configure(input.ptr(), filter.ptr(), bias.ptr(), output.ptr(), conv_info); - - fns.emplace_back(conv_f); - - util::insertFusedActivationLayer(output, - activation, fns); - - input.allocate(); - output.allocate(); - bias.allocate(); - filter.allocate(); - - TensorAccess(input.ref(), inputData, inputShape); - TensorAccess(bias.ref(), biasData, biasShape); - TensorAccess(filter.ref(), filterData, filterShape); - - nnfw::util::env::IntAccessor("CONV2D_VERBOSE").access(verbose); - if (verbose) - { - auto ifm_shape = nnfw::support::nnapi::feature::asFeatureShape(inputShape); - nnfw::support::nnapi::feature::Reader nnapi_ifm_reader{ifm_shape, inputData}; - nnfw::support::acl::feature::Reader acl_ifm_reader{input.ptr()}; - - std::cout << "NNAPI IFM:" << std::endl; - std::cout << nnfw::util::feature::TextFormatter{ifm_shape, nnapi_ifm_reader} - << std::endl; - - std::cout << "ARM Compute IFM:" << std::endl; - std::cout << nnfw::util::feature::TextFormatter{ifm_shape, acl_ifm_reader} << std::endl; - } - - for (const auto &fn : fns) - { - fn->run(); - } - - TensorAccess(output.ref(), outputData, outputShape); - - return true; -} - -} // namespace neon -} // namespace acl -} // namespace kernel -} // namespace nnfw diff --git a/libs/kernel/acl/src/neon/Conv2D.test.cpp b/libs/kernel/acl/src/neon/Conv2D.test.cpp deleted file mode 100644 index 3adb938..0000000 --- a/libs/kernel/acl/src/neon/Conv2D.test.cpp +++ /dev/null @@ -1,162 +0,0 @@ -/* - * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include - -// TODO: fix include path in CMakeFiles -#include "../util.h" - -using namespace nnfw::kernel::acl; - -TEST(KernelACL_TC, neon_convFloat32_3x3to1x1) -{ - float inputData[9]; - const nnfw::rt::Shape inputShape = {OperandType::FLOAT32, {1, 3, 3, 1}, 1.0, 0}; - float filterData[9]; - const nnfw::rt::Shape filterShape = {OperandType::FLOAT32, {1, 3, 3, 1}, 1.0, 0}; - float biasData[1] = {1.0}; - const nnfw::rt::Shape biasShape = {OperandType::FLOAT32, {1}, 1.0, 0}; - int32_t padding_left = 0; - int32_t padding_right = 0; - int32_t padding_top = 0; - int32_t padding_bottom = 0; - int32_t stride_width = 1; - int32_t stride_height = 1; - int32_t activation = static_cast(FusedActivationFunc::RELU); - float outputData[1]; - const nnfw::rt::Shape outputShape = {OperandType::FLOAT32, {1, 1, 1, 1}, 1.0, 0}; - bool bret; - - util::initData(inputData, sizeof(inputData) / sizeof(inputData[0]), 1.0); - util::initData(filterData, sizeof(filterData) / sizeof(filterData[0]), 1.0); - util::initData(outputData, sizeof(outputData) / sizeof(outputData[0]), 0.0); - - bret = neon::convFloat32(inputData, inputShape, filterData, filterShape, biasData, biasShape, - padding_left, padding_right, padding_top, padding_bottom, stride_width, - stride_height, activation, outputData, outputShape); - EXPECT_EQ(bret, true); - - float expectData[] = {10.0f}; - bret = util::compareData(outputData, expectData, outputShape); - EXPECT_EQ(bret, true); -} - -TEST(KernelACL_TC, neon_convFloat32_3x3to3x3) -{ - float inputData[9]; - const nnfw::rt::Shape inputShape = {OperandType::FLOAT32, {1, 3, 3, 1}, 1.0, 0}; - float filterData[9]; - const nnfw::rt::Shape filterShape = {OperandType::FLOAT32, {1, 3, 3, 1}, 1.0, 0}; - float biasData[1] = {1.0}; - const nnfw::rt::Shape biasShape = {OperandType::FLOAT32, {1}, 1.0, 0}; - int32_t padding_left = 1; - int32_t padding_right = 1; - int32_t padding_top = 1; - int32_t padding_bottom = 1; - int32_t stride_width = 1; - int32_t stride_height = 1; - int32_t activation = static_cast(FusedActivationFunc::RELU); - float outputData[9]; - const nnfw::rt::Shape outputShape = {OperandType::FLOAT32, {1, 3, 3, 1}, 1.0, 0}; - bool bret; - - util::initData(inputData, sizeof(inputData) / sizeof(inputData[0]), 1.0); - util::initData(filterData, sizeof(filterData) / sizeof(filterData[0]), 1.0); - util::initData(outputData, sizeof(outputData) / sizeof(outputData[0]), 0.0); - - bret = neon::convFloat32(inputData, inputShape, filterData, filterShape, biasData, biasShape, - padding_left, padding_right, padding_top, padding_bottom, stride_width, - stride_height, activation, outputData, outputShape); - EXPECT_EQ(bret, true); - - float expectData[] = {5.0f, 7.0f, 5.0f, 7.0f, 10.0f, 7.0f, 5.0f, 7.0f, 5.0f}; - bret = util::compareData(outputData, expectData, outputShape); - EXPECT_EQ(bret, true); -} - -TEST(KernelACL_TC, neon_convFloat32_3x3to3x3_RELU) -{ - float inputData[9]; - const nnfw::rt::Shape inputShape = {OperandType::FLOAT32, {1, 3, 3, 1}, 1.0, 0}; - float filterData[9]; - const nnfw::rt::Shape filterShape = {OperandType::FLOAT32, {1, 3, 3, 1}, 1.0, 0}; - float biasData[1] = {-5.0f}; - const nnfw::rt::Shape biasShape = {OperandType::FLOAT32, {1}, 1.0, 0}; - int32_t padding_left = 1; - int32_t padding_right = 1; - int32_t padding_top = 1; - int32_t padding_bottom = 1; - int32_t stride_width = 1; - int32_t stride_height = 1; - int32_t activation = static_cast(FusedActivationFunc::RELU); - float outputData[9]; - const nnfw::rt::Shape outputShape = {OperandType::FLOAT32, {1, 3, 3, 1}, 1.0, 0}; - bool bret; - - util::initData(inputData, sizeof(inputData) / sizeof(inputData[0]), 1.0); - util::initData(filterData, sizeof(filterData) / sizeof(filterData[0]), 1.0); - util::initData(outputData, sizeof(outputData) / sizeof(outputData[0]), 0.0); - - bret = neon::convFloat32(inputData, inputShape, filterData, filterShape, biasData, biasShape, - padding_left, padding_right, padding_top, padding_bottom, stride_width, - stride_height, activation, outputData, outputShape); - EXPECT_EQ(bret, true); - - float expectData[] = {0.0f, 1.0f, 0.0f, 1.0f, 4.0f, 1.0f, 0.0f, 1.0f, 0.0f}; - - bret = util::compareData(outputData, expectData, outputShape); - EXPECT_EQ(bret, true); -} - -TEST(KernelACL_TC, neon_convFloat32_3x5to3x3) -{ - float inputData[15] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; - const nnfw::rt::Shape inputShape = {OperandType::FLOAT32, {1, 3, 5, 1}, 1.0, 0}; - float filterData[18] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2}; - const nnfw::rt::Shape filterShape = {OperandType::FLOAT32, {2, 3, 3, 1}, 1.0, 0}; - float biasData[2] = {1.0, 1.0}; - const nnfw::rt::Shape biasShape = {OperandType::FLOAT32, {2}, 1.0, 0}; - int32_t padding_left = 1; - int32_t padding_right = 1; - int32_t padding_top = 1; - int32_t padding_bottom = 1; - int32_t stride_width = 1; - int32_t stride_height = 1; - int32_t activation = static_cast(FusedActivationFunc::RELU); - float outputData[30]; - const nnfw::rt::Shape outputShape = {OperandType::FLOAT32, {1, 3, 5, 2}, 1.0, 0}; - bool bret; - - util::initData(outputData, sizeof(outputData) / sizeof(outputData[0]), 0.0); - - bret = neon::convFloat32(inputData, inputShape, filterData, filterShape, biasData, biasShape, - padding_left, padding_right, padding_top, padding_bottom, stride_width, - stride_height, activation, outputData, outputShape); - EXPECT_EQ(bret, true); - - float expectNCHW[] = {17.0f, 28.0f, 34.0f, 40.0f, 29.0f, 40.0f, 64.0f, 73.0f, - 82.0f, 58.0f, 37.0f, 58.0f, 64.0f, 70.0f, 49.0f, - - 33.0f, 55.0f, 67.0f, 79.0f, 57.0f, 79.0f, 127.0f, 145.0f, - 163.0f, 115.0f, 73.0f, 115.0f, 127.0f, 139.0f, 97.0f}; - float expectData[30]; - util::NCHW2NHWC(expectNCHW, expectData, outputShape); - bret = util::compareData(outputData, expectData, outputShape); - EXPECT_EQ(bret, true); -} diff --git a/libs/kernel/acl/src/neon/DepthwiseConv2D.cpp b/libs/kernel/acl/src/neon/DepthwiseConv2D.cpp deleted file mode 100644 index b40a65c..0000000 --- a/libs/kernel/acl/src/neon/DepthwiseConv2D.cpp +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include - -#include - -// TODO: fix include path in CMakeFiles -#include "../IO_accessor.h" -#include "../shape.h" -#include "../UniqueTensor.h" -#include "../DepthwiseConv2D.h" - -namespace nnfw -{ -namespace kernel -{ -namespace acl -{ - -namespace neon -{ -static void sync_scheduler() {} - -bool depthwiseConvFloat32(const float *inputData, const nnfw::rt::Shape &inputShape, - const float *filterData, const nnfw::rt::Shape &filterShape, - const float *biasData, const nnfw::rt::Shape &biasShape, - int32_t padding_left, int32_t padding_right, int32_t padding_top, - int32_t padding_bottom, int32_t stride_width, int32_t stride_height, - int32_t depth_multiplier, int32_t activation, float *outputData, - const nnfw::rt::Shape &outputShape) -{ - return common::depthwiseConvFloat32( - inputData, inputShape, filterData, filterShape, biasData, biasShape, padding_left, - padding_right, padding_top, padding_bottom, stride_width, stride_height, depth_multiplier, - activation, outputData, outputShape, sync_scheduler); -} - -} // namespace neon -} // namespace acl -} // namespace kernel -} // namespace nnfw diff --git a/libs/kernel/acl/src/neon/DepthwiseConv2D.test.cpp b/libs/kernel/acl/src/neon/DepthwiseConv2D.test.cpp deleted file mode 100644 index d729d53..0000000 --- a/libs/kernel/acl/src/neon/DepthwiseConv2D.test.cpp +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#define ACL_CORE_FUNC_NAME neon::depthwiseConvFloat32 -#define ACL_TEST(tc, t) TEST(tc, neon_##t) - -#include "../DepthwiseConv2D.test.h" diff --git a/libs/kernel/acl/src/neon/FullyConnected.cpp b/libs/kernel/acl/src/neon/FullyConnected.cpp deleted file mode 100644 index c245925..0000000 --- a/libs/kernel/acl/src/neon/FullyConnected.cpp +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include - -#include - -// TODO: fix include path in CMakeFiles -#include "../IO_accessor.h" -#include "../shape.h" -#include "../UniqueTensor.h" -#include "../FullyConnected.h" - -namespace nnfw -{ -namespace kernel -{ -namespace acl -{ - -namespace neon -{ - -void sync_scheduler() {} - -bool fullyConnectedFloat32(const float *inputData, const nnfw::rt::Shape &inputShape, - const float *weightsData, const nnfw::rt::Shape &weightsShape, - const float *biasData, const nnfw::rt::Shape &biasShape, - int32_t activation, float *outputData, - const nnfw::rt::Shape &outputShape) -{ - - return common::fullyConnectedFloat32( - inputData, inputShape, weightsData, weightsShape, biasData, biasShape, activation, outputData, - outputShape, sync_scheduler); -} - -} // namespace neon -} // namespace acl -} // namespace kernel -} // namespace nnfw diff --git a/libs/kernel/acl/src/neon/FullyConnected.test.cpp b/libs/kernel/acl/src/neon/FullyConnected.test.cpp deleted file mode 100644 index baf0681..0000000 --- a/libs/kernel/acl/src/neon/FullyConnected.test.cpp +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#define ACL_CORE_FUNC_NAME neon::fullyConnectedFloat32 -#define ACL_TEST(tc, t) TEST(tc, neon_##t) - -#include "../FullyConnected.test.h" diff --git a/libs/kernel/acl/src/neon/Mul.cpp b/libs/kernel/acl/src/neon/Mul.cpp deleted file mode 100644 index f110ca6..0000000 --- a/libs/kernel/acl/src/neon/Mul.cpp +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "../Mul.h" -/* -#include -#include -#include - -// TODO: fix include path in CMakeFiles -#include "../IO_accessor.h" -#include "../shape.h" -#include "../UniqueTensor.h" -#include "../util.h" -*/ -namespace nnfw -{ -namespace kernel -{ -namespace acl -{ -namespace neon -{ - -void neon_sync_scheduler() {} - -bool mulFloat32(const float *inputData1, const nnfw::rt::Shape &inputShape1, - const float *inputData2, const nnfw::rt::Shape &inputShape2, int32_t activation, - float *outputData, const nnfw::rt::Shape &outputShape) -{ - bool bret = common::mulFloat32( - inputData1, inputShape1, inputData2, inputShape2, activation, outputData, outputShape, - neon_sync_scheduler); - return bret; -} - -} // namespace neon -} // namespace acl -} // namespace kernel -} // namespace nnfw diff --git a/libs/kernel/acl/src/neon/Mul.test.cpp b/libs/kernel/acl/src/neon/Mul.test.cpp deleted file mode 100644 index b009b42..0000000 --- a/libs/kernel/acl/src/neon/Mul.test.cpp +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#define ACL_CORE_FUNC_NAME nnfw::kernel::acl::neon::mulFloat32 -#define ACL_TEST(tc, t) TEST(tc, neon_##t) - -// exclude some tests in "../Mul.test.h" -#define GTEST_EXCLUDE_TEST - -#include "../Mul.test.h" - -#undef GTEST_EXCLUDE_TEST - -#undef ACL_CORE_FUNC_NAME -#undef ACL_TEST diff --git a/libs/kernel/acl/src/neon/Pooling.cpp b/libs/kernel/acl/src/neon/Pooling.cpp deleted file mode 100644 index d1665e5..0000000 --- a/libs/kernel/acl/src/neon/Pooling.cpp +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include "../IO_accessor.h" -#include "../shape.h" -#include "../UniqueTensor.h" - -#include - -namespace nnfw -{ -namespace kernel -{ -namespace acl -{ -namespace neon -{ - -bool maxPoolFloat32(const float *inputData, const nnfw::rt::Shape &inputShape, int32_t padding_left, - int32_t padding_right, int32_t padding_top, int32_t padding_bottom, - int32_t stride_width, int32_t stride_height, int32_t filter_width, - int32_t filter_height, int32_t activation, float *outputData, - const nnfw::rt::Shape &outputShape) -{ - arm_compute::TensorShape input_shape = util::fromNNShape(inputShape); - arm_compute::TensorShape output_shape = util::fromNNShape(outputShape); - - std::vector> fns; - - arm_compute::PadStrideInfo pad_info = arm_compute::PadStrideInfo( - stride_width, stride_height, padding_left, padding_right, padding_top, padding_bottom, - arm_compute::DimensionRoundingType::FLOOR); - - arm_compute::PoolingLayerInfo maxpool_info = arm_compute::PoolingLayerInfo( - arm_compute::PoolingType::MAX, arm_compute::Size2D(filter_width, filter_height), pad_info, - false); - - NEUniqueTensor input(arm_compute::TensorInfo(input_shape, arm_compute::Format::F32)); - NEUniqueTensor output(arm_compute::TensorInfo(output_shape, arm_compute::Format::F32)); - - auto pool_f = std::make_shared(); - pool_f->configure(input.ptr(), output.ptr(), maxpool_info); - - fns.emplace_back(pool_f); - - util::insertFusedActivationLayer(output, - activation, fns); - - input.allocate(); - output.allocate(); - - TensorAccess(input.ref(), inputData, inputShape); - - for (const auto &fn : fns) - { - fn->run(); - } - - TensorAccess(output.ref(), outputData, outputShape); - - return true; -} - -bool averagePoolFloat32(const float *inputData, const nnfw::rt::Shape &inputShape, - int32_t padding_left, int32_t padding_right, int32_t padding_top, - int32_t padding_bottom, int32_t stride_width, int32_t stride_height, - int32_t filter_width, int32_t filter_height, int32_t activation, - float *outputData, const nnfw::rt::Shape &outputShape) -{ - arm_compute::TensorShape input_shape = util::fromNNShape(inputShape); - arm_compute::TensorShape output_shape = util::fromNNShape(outputShape); - - std::vector> fns; - - arm_compute::PadStrideInfo pad_info = arm_compute::PadStrideInfo( - stride_width, stride_height, padding_left, padding_right, padding_top, padding_bottom, - arm_compute::DimensionRoundingType::FLOOR); - - arm_compute::PoolingLayerInfo pool_info = arm_compute::PoolingLayerInfo( - arm_compute::PoolingType::AVG, arm_compute::Size2D(filter_width, filter_height), pad_info, - true); - - NEUniqueTensor input(arm_compute::TensorInfo(input_shape, arm_compute::Format::F32)); - NEUniqueTensor output(arm_compute::TensorInfo(output_shape, arm_compute::Format::F32)); - - auto pool_f = std::make_shared(); - pool_f->configure(input.ptr(), output.ptr(), pool_info); - - fns.emplace_back(pool_f); - - util::insertFusedActivationLayer(output, - activation, fns); - - input.allocate(); - output.allocate(); - - TensorAccess(input.ref(), inputData, inputShape); - - for (const auto &fn : fns) - { - fn->run(); - } - - TensorAccess(output.ref(), outputData, outputShape); - - return true; -} - -} // namespace neon -} // namespace acl -} // namespace kernel -} // namespace nnfw diff --git a/libs/kernel/acl/src/neon/Pooling.test.cpp b/libs/kernel/acl/src/neon/Pooling.test.cpp deleted file mode 100644 index 07159a6..0000000 --- a/libs/kernel/acl/src/neon/Pooling.test.cpp +++ /dev/null @@ -1,358 +0,0 @@ -/* - * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include - -#include "../util.h" - -using namespace nnfw::kernel::acl; - -TEST(KernelACL_TC, neon_maxPoolFloat32_3x3to1x1) -{ - util::TensorWrapper input({1, 3, 3, 1}); - const nnfw::rt::Shape inputShape = {OperandType::FLOAT32, {1, 3, 3, 1}, 1.0, 0}; - int32_t padding_left = 0; - int32_t padding_right = 0; - int32_t padding_top = 0; - int32_t padding_bottom = 0; - int32_t stride_width = 1; - int32_t stride_height = 1; - int32_t filter_width = 3; - int32_t filter_height = 3; - - float outputData[1]; - const nnfw::rt::Shape outputShape = {OperandType::FLOAT32, {1, 1, 1, 1}, 1.0, 0}; - bool bret; - - float value = 1.0f; - input.initValue([&value](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { return value++; }); - - util::initData(outputData, sizeof(outputData) / sizeof(outputData[0]), 0.0); - - int32_t activation = ANEURALNETWORKS_FUSED_NONE; - - bret = neon::maxPoolFloat32(input.ptr(), inputShape, padding_left, padding_right, - padding_top, padding_bottom, stride_width, stride_height, - filter_width, filter_height, activation, outputData, outputShape); - EXPECT_EQ(bret, true); - - float expectData[] = {9.0f}; - bret = util::compareData(outputData, expectData, outputShape); - EXPECT_EQ(bret, true); -} - -TEST(KernelACL_TC, neon_maxPoolFloat32_3x3to1x1_RELU) -{ - util::TensorWrapper input({1, 3, 3, 1}); - const nnfw::rt::Shape inputShape = {OperandType::FLOAT32, {1, 3, 3, 1}, 1.0, 0}; - int32_t padding_left = 0; - int32_t padding_right = 0; - int32_t padding_top = 0; - int32_t padding_bottom = 0; - int32_t stride_width = 1; - int32_t stride_height = 1; - int32_t filter_width = 3; - int32_t filter_height = 3; - - float outputData[1]; - const nnfw::rt::Shape outputShape = {OperandType::FLOAT32, {1, 1, 1, 1}, 1.0, 0}; - bool bret; - - float value = -1.0f; - input.initValue([&value](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { return value--; }); - - util::initData(outputData, sizeof(outputData) / sizeof(outputData[0]), 0.0); - - int32_t activation = ANEURALNETWORKS_FUSED_RELU; - - bret = neon::maxPoolFloat32(input.ptr(), inputShape, padding_left, padding_right, - padding_top, padding_bottom, stride_width, stride_height, - filter_width, filter_height, activation, outputData, outputShape); - EXPECT_EQ(bret, true); - - float expectData[] = {0.0f}; - bret = util::compareData(outputData, expectData, outputShape); - EXPECT_EQ(bret, true); -} - -TEST(KernelACL_TC, neon_maxPoolFloat32_3x3to2x2) -{ - util::TensorWrapper input({1, 3, 3, 1}); - const nnfw::rt::Shape inputShape = {OperandType::FLOAT32, {1, 3, 3, 1}, 1.0, 0}; - int32_t padding_left = 0; - int32_t padding_right = 1; - int32_t padding_top = 0; - int32_t padding_bottom = 1; - int32_t stride_width = 2; - int32_t stride_height = 2; - int32_t filter_width = 2; - int32_t filter_height = 2; - - float outputData[4]; - const nnfw::rt::Shape outputShape = {OperandType::FLOAT32, {1, 2, 2, 1}, 1.0, 0}; - bool bret; - - float value = 1.0f; - input.initValue([&value](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { return value++; }); - - util::initData(outputData, sizeof(outputData) / sizeof(outputData[0]), 0.0); - - int32_t activation = ANEURALNETWORKS_FUSED_NONE; - - bret = neon::maxPoolFloat32(input.ptr(), inputShape, padding_left, padding_right, - padding_top, padding_bottom, stride_width, stride_height, - filter_width, filter_height, activation, outputData, outputShape); - EXPECT_EQ(bret, true); - - float expectData[] = {5.0f, 6.0f, 8.0f, 9.0f}; - bret = util::compareData(outputData, expectData, outputShape); - EXPECT_EQ(bret, true); -} - -TEST(KernelACL_TC, neon_maxPoolFloat32_147x147to73x73) -{ - util::TensorWrapper input({1, 147, 147, 64}); - util::TensorWrapper output({1, 73, 73, 64}); - - int32_t padding_left = 0; - int32_t padding_right = 0; - int32_t padding_top = 0; - int32_t padding_bottom = 0; - int32_t stride_width = 2; - int32_t stride_height = 2; - int32_t filter_width = 3; - int32_t filter_height = 3; - - input.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { return 1.0f; }); - - output.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { return 0.f; }); - - int32_t activation = ANEURALNETWORKS_FUSED_NONE; - - bool bret = - neon::maxPoolFloat32(input.ptr(), input.shape(), padding_left, padding_right, - padding_top, padding_bottom, stride_width, stride_height, filter_width, - filter_height, activation, output.ptr(), output.shape()); - EXPECT_EQ(bret, true); - - util::TensorWrapper expected({1, 73, 73, 64}); - expected.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { return 1.0f; }); - - EXPECT_EQ(output, expected); -} - -TEST(KernelACL_TC, neon_maxPoolFloat32_71x71to35x35) -{ - util::TensorWrapper input({1, 71, 71, 192}); - util::TensorWrapper output({1, 35, 35, 192}); - - int32_t padding_left = 0; - int32_t padding_right = 0; - int32_t padding_top = 0; - int32_t padding_bottom = 0; - int32_t stride_width = 2; - int32_t stride_height = 2; - int32_t filter_width = 3; - int32_t filter_height = 3; - - input.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { return 1.0f; }); - - output.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { return 0.f; }); - - int32_t activation = ANEURALNETWORKS_FUSED_NONE; - - bool bret = - neon::maxPoolFloat32(input.ptr(), input.shape(), padding_left, padding_right, - padding_top, padding_bottom, stride_width, stride_height, filter_width, - filter_height, activation, output.ptr(), output.shape()); - EXPECT_EQ(bret, true); - - util::TensorWrapper expected({1, 35, 35, 192}); - expected.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { return 1.0f; }); - - EXPECT_EQ(output, expected); -} - -TEST(KernelACL_TC, neon_averagePoolFloat32_3x3to1x1) -{ - util::TensorWrapper input({1, 3, 3, 1}); - const nnfw::rt::Shape inputShape = {OperandType::FLOAT32, {1, 3, 3, 1}, 1.0, 0}; - int32_t padding_left = 0; - int32_t padding_right = 0; - int32_t padding_top = 0; - int32_t padding_bottom = 0; - int32_t stride_width = 1; - int32_t stride_height = 1; - int32_t filter_width = 3; - int32_t filter_height = 3; - - float outputData[1]; - const nnfw::rt::Shape outputShape = {OperandType::FLOAT32, {1, 1, 1, 1}, 1.0, 0}; - bool bret; - - float value = 1.0f; - input.initValue([&value](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { return value++; }); - - util::initData(outputData, sizeof(outputData) / sizeof(outputData[0]), 0.0); - - int32_t activation = ANEURALNETWORKS_FUSED_NONE; - - bret = neon::averagePoolFloat32(input.ptr(), inputShape, padding_left, padding_right, - padding_top, padding_bottom, stride_width, stride_height, - filter_width, filter_height, activation, outputData, outputShape); - EXPECT_EQ(bret, true); - - float expectData[] = {5.0f}; - bret = util::compareData(outputData, expectData, outputShape); - EXPECT_EQ(bret, true); -} - -TEST(KernelACL_TC, neon_averagePoolFloat32_3x3to1x1_RELU) -{ - util::TensorWrapper input({1, 3, 3, 1}); - const nnfw::rt::Shape inputShape = {OperandType::FLOAT32, {1, 3, 3, 1}, 1.0, 0}; - int32_t padding_left = 0; - int32_t padding_right = 0; - int32_t padding_top = 0; - int32_t padding_bottom = 0; - int32_t stride_width = 1; - int32_t stride_height = 1; - int32_t filter_width = 3; - int32_t filter_height = 3; - - float outputData[1]; - const nnfw::rt::Shape outputShape = {OperandType::FLOAT32, {1, 1, 1, 1}, 1.0, 0}; - bool bret; - - float value = 3.0f; - input.initValue([&value](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { return value--; }); - - util::initData(outputData, sizeof(outputData) / sizeof(outputData[0]), 0.0); - - int32_t activation = ANEURALNETWORKS_FUSED_RELU; - - bret = neon::averagePoolFloat32(input.ptr(), inputShape, padding_left, padding_right, - padding_top, padding_bottom, stride_width, stride_height, - filter_width, filter_height, activation, outputData, outputShape); - EXPECT_EQ(bret, true); - - float expectData[] = {0.0f}; - bret = util::compareData(outputData, expectData, outputShape); - EXPECT_EQ(bret, true); -} - -TEST(KernelACL_TC, neon_averagePoolFloat32_3x3to2x2) -{ - util::TensorWrapper input({1, 3, 3, 1}); - const nnfw::rt::Shape inputShape = {OperandType::FLOAT32, {1, 3, 3, 1}, 1.0, 0}; - int32_t padding_left = 0; - int32_t padding_right = 0; - int32_t padding_top = 0; - int32_t padding_bottom = 0; - int32_t stride_width = 1; - int32_t stride_height = 1; - int32_t filter_width = 2; - int32_t filter_height = 2; - - float outputData[4]; - const nnfw::rt::Shape outputShape = {OperandType::FLOAT32, {1, 2, 2, 1}, 1.0, 0}; - bool bret; - - float value = 1.0f; - input.initValue([&value](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { return value++; }); - - util::initData(outputData, sizeof(outputData) / sizeof(outputData[0]), 0.0); - - int32_t activation = ANEURALNETWORKS_FUSED_NONE; - - bret = neon::averagePoolFloat32(input.ptr(), inputShape, padding_left, padding_right, - padding_top, padding_bottom, stride_width, stride_height, - filter_width, filter_height, activation, outputData, outputShape); - EXPECT_EQ(bret, true); - - float expectData[] = {3.0f, 4.0f, 6.0f, 7.0f}; - bret = util::compareData(outputData, expectData, outputShape); - EXPECT_EQ(bret, true); -} - -TEST(KernelACL_TC, neon_averagePoolFloat32_35x35to35x35) -{ - std::vector dims = {1, 35, 35, 192}; - util::TensorWrapper input(dims); - util::TensorWrapper output(dims); - - int32_t padding_left = 1; - int32_t padding_right = 1; - int32_t padding_top = 1; - int32_t padding_bottom = 1; - int32_t stride_width = 1; - int32_t stride_height = 1; - int32_t filter_width = 3; - int32_t filter_height = 3; - - input.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { return 1.0f; }); - - output.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { return 0.f; }); - - int32_t activation = ANEURALNETWORKS_FUSED_NONE; - - bool bret = neon::averagePoolFloat32(input.ptr(), input.shape(), padding_left, - padding_right, padding_top, padding_bottom, stride_width, - stride_height, filter_width, filter_height, activation, - output.ptr(), output.shape()); - EXPECT_EQ(bret, true); - - util::TensorWrapper expected(dims); - expected.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { return 1.0f; }); - - EXPECT_EQ(output, expected); -} - -TEST(KernelACL_TC, neon_averagePoolFloat32_8x8to1x1) -{ - util::TensorWrapper input({1, 8, 8, 2048}); - util::TensorWrapper output({1, 1, 1, 2048}); - - int32_t padding_left = 0; - int32_t padding_right = 0; - int32_t padding_top = 0; - int32_t padding_bottom = 0; - int32_t stride_width = 2; - int32_t stride_height = 2; - int32_t filter_width = 8; - int32_t filter_height = 8; - - input.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { return 1.0f; }); - - output.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { return 0.f; }); - - int32_t activation = ANEURALNETWORKS_FUSED_NONE; - - bool bret = neon::averagePoolFloat32(input.ptr(), input.shape(), padding_left, - padding_right, padding_top, padding_bottom, stride_width, - stride_height, filter_width, filter_height, activation, - output.ptr(), output.shape()); - EXPECT_EQ(bret, true); - - util::TensorWrapper expected({1, 1, 1, 2048}); - expected.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { return 1.0f; }); - - EXPECT_EQ(output, expected); -} diff --git a/libs/kernel/acl/src/neon/ReLU.cpp b/libs/kernel/acl/src/neon/ReLU.cpp deleted file mode 100644 index b5a2769..0000000 --- a/libs/kernel/acl/src/neon/ReLU.cpp +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include - -#include -#include -#include "../IO_accessor.h" -#include "../shape.h" -#include "../UniqueTensor.h" -#include "../util.h" - -namespace nnfw -{ -namespace kernel -{ -namespace acl -{ -namespace neon -{ - -bool reluFloat32(const float *inputData, const nnfw::rt::Shape &inputShape, float *outputData, - const nnfw::rt::Shape &outputShape) -{ - arm_compute::TensorShape input_shape = util::fromNNShape(inputShape); - arm_compute::TensorShape output_shape = util::fromNNShape(outputShape); - - NEUniqueTensor input(arm_compute::TensorInfo(input_shape, arm_compute::Format::F32)); - NEUniqueTensor output(arm_compute::TensorInfo(output_shape, arm_compute::Format::F32)); - - const ::arm_compute::ActivationLayerInfo act_info{ - ::arm_compute::ActivationLayerInfo::ActivationFunction::RELU}; - - auto relu_f = std::make_shared(); - relu_f->configure(input.ptr(), output.ptr(), act_info); - - input.allocate(); - output.allocate(); - - if (inputShape.dimensions.size() == 4) - { - TensorAccess(input.ref(), inputData, inputShape); - - relu_f->run(); - - arm_compute::CLScheduler::get().sync(); - - TensorAccess(output.ref(), outputData, outputShape); - } - else if (inputShape.dimensions.size() == 2) - { - TensorAccess(input.ref(), inputData, inputShape); - - relu_f->run(); - - TensorAccess(output.ref(), outputData, outputShape); - } - else - { - assert("undefined dimension of input" && 0); - return false; - } - - return true; -} - -} // namespace neon -} // namespace acl -} // namespace kernel -} // namespace nnfw diff --git a/libs/kernel/acl/src/neon/ReLU.test.cpp b/libs/kernel/acl/src/neon/ReLU.test.cpp deleted file mode 100644 index 2083c08..0000000 --- a/libs/kernel/acl/src/neon/ReLU.test.cpp +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include - -#include "../util.h" - -using namespace nnfw::kernel::acl; - -TEST(KernelACL_TC, neon_reluFloat32_2d) -{ - uint32_t input_h = 3; - uint32_t input_w = 3; - uint32_t output_h = input_h; - uint32_t output_w = input_w; - - util::TensorWrapper input({input_h, input_w}); - util::TensorWrapper output({output_h, output_w}); - - float nv = -10.f; - float pv = 10.f; - - input.initValue([&](uint32_t h, uint32_t w) { - if (h < w) - return nv; - else - return pv; - }); - - output.initValue([](uint32_t h, uint32_t w) { return 0.f; }); - - bool bret = - neon::reluFloat32(input.ptr(), input.shape(), output.ptr(), output.shape()); - EXPECT_EQ(bret, true); - - util::TensorWrapper expected({output_h, output_w}); - expected.initValue([&](uint32_t h, uint32_t w) { - if (h < w) - return 0.f; - else - return pv; - }); - - bret = util::compareData(output.ptr(), expected.ptr(), output.shape()); - EXPECT_EQ(bret, true); -} - -TEST(KernelACL_TC, neon_reluFloat32_4d) -{ - uint32_t input_n = 1; - uint32_t input_c = 3; - uint32_t input_h = 3; - uint32_t input_w = 3; - uint32_t output_n = input_n; - uint32_t output_c = input_c; - uint32_t output_h = input_h; - uint32_t output_w = input_w; - - util::TensorWrapper input({input_n, input_h, input_w, input_c}); - util::TensorWrapper output({output_n, output_h, output_w, output_c}); - - float nv = -10.f; - float pv = 10.f; - - input.initValue([&](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { - if (h < w) - return nv; - else - return pv; - }); - - output.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { return 0.f; }); - - bool bret = - neon::reluFloat32(input.ptr(), input.shape(), output.ptr(), output.shape()); - EXPECT_EQ(bret, true); - - util::TensorWrapper expected({output_n, output_h, output_w, output_c}); - expected.initValue([&](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { - if (h < w) - return 0.f; - else - return pv; - }); - - bret = util::compareData(output.ptr(), expected.ptr(), output.shape()); - EXPECT_EQ(bret, true); -} diff --git a/libs/kernel/acl/src/neon/ReLU6.cpp b/libs/kernel/acl/src/neon/ReLU6.cpp deleted file mode 100644 index 79f46a1..0000000 --- a/libs/kernel/acl/src/neon/ReLU6.cpp +++ /dev/null @@ -1,133 +0,0 @@ -/* - * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include - -#include -#include -#include "../IO_accessor.h" -#include "../shape.h" -#include "../UniqueTensor.h" -#include "../util.h" - -namespace nnfw -{ -namespace kernel -{ -namespace acl -{ -namespace neon -{ - -bool relu6Float32(const float *inputData, const nnfw::rt::Shape &inputShape, float *outputData, - const nnfw::rt::Shape &outputShape) -{ - arm_compute::TensorShape input_shape = util::fromNNShape(inputShape); - arm_compute::TensorShape output_shape = util::fromNNShape(outputShape); - - CLUniqueTensor input(arm_compute::TensorInfo(input_shape, arm_compute::Format::F32)); - CLUniqueTensor output(arm_compute::TensorInfo(output_shape, arm_compute::Format::F32)); - - const ::arm_compute::ActivationLayerInfo act_info{ - ::arm_compute::ActivationLayerInfo::ActivationFunction::BOUNDED_RELU, 6.0f}; - - auto relu_f = std::make_shared(); - relu_f->configure(input.ptr(), output.ptr(), act_info); - - input.allocate(); - output.allocate(); - - if (inputShape.dimensions.size() == 4) - { - TensorAccess(input.ref(), inputData, inputShape); - - relu_f->run(); - - arm_compute::CLScheduler::get().sync(); - - TensorAccess(output.ref(), outputData, outputShape); - } - else if (inputShape.dimensions.size() == 2) - { - TensorAccess(input.ref(), inputData, inputShape); - - relu_f->run(); - - arm_compute::CLScheduler::get().sync(); - - TensorAccess(output.ref(), outputData, outputShape); - } - else - { - assert("undefined dimension of input" && 0); - return false; - } - - return true; -} - -bool relu6LUFloat32(const float *inputData, const nnfw::rt::Shape &inputShape, float *outputData, - const nnfw::rt::Shape &outputShape) -{ - arm_compute::TensorShape input_shape = util::fromNNShape(inputShape); - arm_compute::TensorShape output_shape = util::fromNNShape(outputShape); - - CLUniqueTensor input(arm_compute::TensorInfo(input_shape, arm_compute::Format::F32)); - CLUniqueTensor output(arm_compute::TensorInfo(output_shape, arm_compute::Format::F32)); - - const ::arm_compute::ActivationLayerInfo act_info{ - ::arm_compute::ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU, 6.0f, 0.0f}; - - auto relu_f = std::make_shared(); - relu_f->configure(input.ptr(), output.ptr(), act_info); - - input.allocate(); - output.allocate(); - - if (inputShape.dimensions.size() == 4) - { - TensorAccess(input.ref(), inputData, inputShape); - - relu_f->run(); - - arm_compute::CLScheduler::get().sync(); - - TensorAccess(output.ref(), outputData, outputShape); - } - else if (inputShape.dimensions.size() == 2) - { - TensorAccess(input.ref(), inputData, inputShape); - - relu_f->run(); - - arm_compute::CLScheduler::get().sync(); - - TensorAccess(output.ref(), outputData, outputShape); - } - else - { - assert("undefined dimension of input" && 0); - return false; - } - - return true; -} - -} // namespace neon -} // namespace acl -} // namespace kernel -} // namespace nnfw diff --git a/libs/kernel/acl/src/neon/ReLU6.test.cpp b/libs/kernel/acl/src/neon/ReLU6.test.cpp deleted file mode 100644 index 620e528..0000000 --- a/libs/kernel/acl/src/neon/ReLU6.test.cpp +++ /dev/null @@ -1,205 +0,0 @@ -/* - * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include - -#include "../util.h" - -using namespace nnfw::kernel::acl; - -TEST(KernelACL_TC, neon_relu6Float32_2d) -{ - uint32_t input_h = 3; - uint32_t input_w = 3; - uint32_t output_h = input_h; - uint32_t output_w = input_w; - - util::TensorWrapper input({input_h, input_w}); - util::TensorWrapper output({output_h, output_w}); - - float nv = -10.f; - float p1v = 3.f; - float p2v = 10.f; - - input.initValue([&](uint32_t h, uint32_t w) { - if (h < w) - return nv; - else if (h == w) - return p1v; - else - return p2v; - }); - - output.initValue([](uint32_t h, uint32_t w) { return 0.f; }); - - bool bret = - neon::relu6Float32(input.ptr(), input.shape(), output.ptr(), output.shape()); - EXPECT_EQ(bret, true); - - util::TensorWrapper expected({output_h, output_w}); - expected.initValue([&](uint32_t h, uint32_t w) { - if (h < w) - return 0.f; - else if (h == w) - return p1v; - else - return 6.f; - }); - - bret = util::compareData(output.ptr(), expected.ptr(), output.shape()); - EXPECT_EQ(bret, true); -} - -TEST(KernelACL_TC, neon_relu6LUFloat32_2d) -{ - uint32_t input_h = 3; - uint32_t input_w = 3; - uint32_t output_h = input_h; - uint32_t output_w = input_w; - - util::TensorWrapper input({input_h, input_w}); - util::TensorWrapper output({output_h, output_w}); - - float nv = -10.f; - float p1v = 3.f; - float p2v = 10.f; - - input.initValue([&](uint32_t h, uint32_t w) { - if (h < w) - return nv; - else if (h == w) - return p1v; - else - return p2v; - }); - - output.initValue([](uint32_t h, uint32_t w) { return 0.f; }); - - bool bret = - neon::relu6LUFloat32(input.ptr(), input.shape(), output.ptr(), output.shape()); - EXPECT_EQ(bret, true); - - util::TensorWrapper expected({output_h, output_w}); - expected.initValue([&](uint32_t h, uint32_t w) { - if (h < w) - return 0.f; - else if (h == w) - return p1v; - else - return 6.f; - }); - - bret = util::compareData(output.ptr(), expected.ptr(), output.shape()); - EXPECT_EQ(bret, true); -} - -TEST(KernelACL_TC, neon_relu6Float32_4d) -{ - uint32_t input_n = 1; - uint32_t input_c = 3; - uint32_t input_h = 3; - uint32_t input_w = 3; - uint32_t output_n = input_n; - uint32_t output_c = input_c; - uint32_t output_h = input_h; - uint32_t output_w = input_w; - - util::TensorWrapper input({input_n, input_h, input_w, input_c}); - util::TensorWrapper output({output_n, output_h, output_w, output_c}); - - float nv = -10.f; - float p1v = 3.f; - float p2v = 10.f; - - input.initValue([&](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { - if (h < w) - return nv; - else if (h == w) - return p1v; - else - return p2v; - }); - - output.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { return 0.f; }); - - bool bret = - neon::relu6Float32(input.ptr(), input.shape(), output.ptr(), output.shape()); - EXPECT_EQ(bret, true); - - util::TensorWrapper expected({output_n, output_h, output_w, output_c}); - expected.initValue([&](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { - if (h < w) - return 0.f; - else if (h == w) - return p1v; - else - return 6.f; - }); - - bret = util::compareData(output.ptr(), expected.ptr(), output.shape()); - EXPECT_EQ(bret, true); -} - -TEST(KernelACL_TC, neon_relu6LUFloat32_4d) -{ - uint32_t input_n = 1; - uint32_t input_c = 3; - uint32_t input_h = 3; - uint32_t input_w = 3; - uint32_t output_n = input_n; - uint32_t output_c = input_c; - uint32_t output_h = input_h; - uint32_t output_w = input_w; - - util::TensorWrapper input({input_n, input_h, input_w, input_c}); - util::TensorWrapper output({output_n, output_h, output_w, output_c}); - - float nv = -10.f; - float p1v = 3.f; - float p2v = 10.f; - - input.initValue([&](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { - if (h < w) - return nv; - else if (h == w) - return p1v; - else - return p2v; - }); - - output.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { return 0.f; }); - - bool bret = - neon::relu6LUFloat32(input.ptr(), input.shape(), output.ptr(), output.shape()); - EXPECT_EQ(bret, true); - - util::TensorWrapper expected({output_n, output_h, output_w, output_c}); - expected.initValue([&](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { - if (h < w) - return 0.f; - else if (h == w) - return p1v; - else - return 6.f; - }); - - bret = util::compareData(output.ptr(), expected.ptr(), output.shape()); - EXPECT_EQ(bret, true); -} diff --git a/libs/kernel/acl/src/neon/Reshape.cpp b/libs/kernel/acl/src/neon/Reshape.cpp deleted file mode 100644 index 4774dab..0000000 --- a/libs/kernel/acl/src/neon/Reshape.cpp +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include - -// TODO: fix include path in CMakeFiles -#include "../IO_accessor.h" -#include "../shape.h" -#include "../UniqueTensor.h" -#include "../Reshape.h" - -namespace nnfw -{ -namespace kernel -{ -namespace acl -{ - -namespace neon -{ - -static void sync_scheduler() { arm_compute::CLScheduler::get().sync(); } - -bool reshapeGeneric(const void *inputData, const nnfw::rt::Shape &inputShape, void *outputData, - const nnfw::rt::Shape &outputShape) -{ - return common::reshapeGeneric( - inputData, inputShape, outputData, outputShape, sync_scheduler); -} - -} // namespace neon - -} // namespace acl -} // namespace kernel -} // namespace nnfw diff --git a/libs/kernel/acl/src/neon/Reshape.test.cpp b/libs/kernel/acl/src/neon/Reshape.test.cpp deleted file mode 100644 index 9aca45e..0000000 --- a/libs/kernel/acl/src/neon/Reshape.test.cpp +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#define ACL_CORE_FUNC_NAME neon::reshapeGeneric -#define ACL_TEST(tc, t) TEST(tc, neon_##t) - -#include "../Reshape.test.h" diff --git a/libs/kernel/acl/src/neon/Softmax.cpp b/libs/kernel/acl/src/neon/Softmax.cpp deleted file mode 100644 index 49ad32e..0000000 --- a/libs/kernel/acl/src/neon/Softmax.cpp +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include - -#include -#include -#include "../IO_accessor.h" -#include "../shape.h" -#include "../util.h" -#include "../UniqueTensor.h" - -namespace nnfw -{ -namespace kernel -{ -namespace acl -{ -namespace neon -{ - -bool softmaxFloat32(const float *inputData, const nnfw::rt::Shape &inputShape, const float beta, - float *outputData, const nnfw::rt::Shape &outputShape) -{ - arm_compute::TensorShape input_shape = util::fromNNShape(inputShape); - arm_compute::TensorShape output_shape = util::fromNNShape(outputShape); - - NEUniqueTensor input(arm_compute::TensorInfo(input_shape, arm_compute::Format::F32)); - NEUniqueTensor output(arm_compute::TensorInfo(output_shape, arm_compute::Format::F32)); - - auto softmax_f = std::make_shared(); - softmax_f->configure(input.ptr(), output.ptr(), beta); - - input.allocate(); - output.allocate(); - - if (inputShape.dimensions.size() == 4) - { - TensorAccess(input.ref(), inputData, inputShape); - - softmax_f->run(); - - TensorAccess(output.ref(), outputData, outputShape); - } - else if (inputShape.dimensions.size() == 2) - { - // Softmax comes with 1xN matrix and this is translated to N vector in arm_compute::TensorShape - TensorAccess(input.ref(), inputData, inputShape); - - softmax_f->run(); - - TensorAccess(output.ref(), outputData, outputShape); - } - else - { - assert("undefined dimension of input" && 0); - return false; - } - - return true; -} - -} // namespace neon -} // namespace acl -} // namespace kernel -} // namespace nnfw diff --git a/libs/kernel/acl/src/neon/Softmax.test.cpp b/libs/kernel/acl/src/neon/Softmax.test.cpp deleted file mode 100644 index d33e476..0000000 --- a/libs/kernel/acl/src/neon/Softmax.test.cpp +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include - -#include "../util.h" - -using namespace nnfw::kernel::acl; - -TEST(KernelACL_TC, neon_softmaxFloat32_1xn) -{ - float inputData[4]; - const nnfw::rt::Shape inputShape = {OperandType::FLOAT32, {1, 4}, 1.0, 0}; - float outputData[4]; - const nnfw::rt::Shape outputShape = {OperandType::FLOAT32, {1, 4}, 1.0, 0}; - const float beta = 1.0f; - bool bret; - - util::initData(inputData, sizeof(inputData) / sizeof(inputData[0]), 1.0); - util::initData(outputData, sizeof(outputData) / sizeof(outputData[0]), 0.0); - - bret = neon::softmaxFloat32(inputData, inputShape, beta, outputData, outputShape); - EXPECT_EQ(bret, true); - - float expectData[] = {0.25f, 0.25f, 0.25f, 0.25f}; - bret = util::compareData(outputData, expectData, outputShape); - EXPECT_EQ(bret, true); -} - -TEST(KernelACL_TC, neon_softmaxFloat32_4d) -{ - float inputData[4]; - const nnfw::rt::Shape inputShape = {OperandType::FLOAT32, {1, 1, 4, 1}, 1.0, 0}; - float outputData[4]; - const nnfw::rt::Shape outputShape = {OperandType::FLOAT32, {1, 1, 4, 1}, 1.0, 0}; - const float beta = 1.0f; - bool bret; - - util::initData(inputData, sizeof(inputData) / sizeof(inputData[0]), 1.0); - util::initData(outputData, sizeof(outputData) / sizeof(outputData[0]), 0.0); - - bret = neon::softmaxFloat32(inputData, inputShape, beta, outputData, outputShape); - EXPECT_EQ(bret, true); - - float expectData[] = {0.25f, 0.25f, 0.25f, 0.25f}; - bret = util::compareData(outputData, expectData, outputShape); - EXPECT_EQ(bret, true); -} - -TEST(KernelACL_TC, neon_softmaxFloat32_1xn_seq) -{ - float inputData[4]; - const nnfw::rt::Shape inputShape = {OperandType::FLOAT32, {1, 1, 4, 1}, 1.0, 0}; - float outputData[4]; - const nnfw::rt::Shape outputShape = {OperandType::FLOAT32, {1, 1, 4, 1}, 1.0, 0}; - const float beta = 1.0f; - bool bret; - - util::initData_Increasing(inputData, sizeof(inputData) / sizeof(inputData[0]), 1.0); - util::initData(outputData, sizeof(outputData) / sizeof(outputData[0]), 0.0); - - bret = neon::softmaxFloat32(inputData, inputShape, beta, outputData, outputShape); - EXPECT_EQ(bret, true); - - float expectData[] = {0.032058603280085, 0.0871443187420326, 0.23688281808991, 0.643914259887972}; - bret = util::compareData(outputData, expectData, outputShape); - EXPECT_EQ(bret, true); -} - -TEST(KernelACL_TC, neon_softmaxFloat32_4d_seq) -{ - float inputData[4]; - const nnfw::rt::Shape inputShape = {OperandType::FLOAT32, {1, 1, 4, 1}, 1.0, 0}; - float outputData[4]; - const nnfw::rt::Shape outputShape = {OperandType::FLOAT32, {1, 1, 4, 1}, 1.0, 0}; - const float beta = 1.0f; - bool bret; - - util::initData_Increasing(inputData, sizeof(inputData) / sizeof(inputData[0]), 1.0); - util::initData(outputData, sizeof(outputData) / sizeof(outputData[0]), 0.0); - - bret = neon::softmaxFloat32(inputData, inputShape, beta, outputData, outputShape); - EXPECT_EQ(bret, true); - - float expectData[] = {0.032058603280085, 0.0871443187420326, 0.23688281808991, 0.643914259887972}; - bret = util::compareData(outputData, expectData, outputShape); - EXPECT_EQ(bret, true); -} diff --git a/libs/kernel/acl/src/shape.cpp b/libs/kernel/acl/src/shape.cpp deleted file mode 100644 index 1b45c3a..0000000 --- a/libs/kernel/acl/src/shape.cpp +++ /dev/null @@ -1,135 +0,0 @@ -/* - * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include - -#include "shape.h" - -namespace nnfw -{ -namespace rt -{ - -// TODO remove from this source and use it from runtime -uint32_t getSizeOfDimension(const Shape &shape, uint32_t dimensionIdx) -{ - if (dimensionIdx >= shape.dimensions.size()) - { - // TODO, log the error - return 0; - } - return shape.dimensions[dimensionIdx]; -} - -} // namespace rt -} // namespace nnfw - -namespace nnfw -{ -namespace kernel -{ -namespace acl -{ -namespace util -{ - -arm_compute::TensorShape fromVectorNNShape(const nnfw::rt::Shape &shape) -{ - assert(shape.dimensions.size() == 1); - - const uint32_t len = nnfw::rt::getSizeOfDimension(shape, 0); - - return arm_compute::TensorShape(len); -} - -// TODO: check if merging fromVectorNNShape and fromMatrixNNShape is possible -arm_compute::TensorShape fromMatrixNNShape(const nnfw::rt::Shape &shape) -{ - assert(shape.dimensions.size() <= 4); - - // in https://arm-software.github.io/ComputeLibrary/latest/architecture.xhtml - // sample code was written like "const TensorShape shape(width, height, batch);" - // also the above site mensions, - // "Tensors are defined by a DataType plus a number of channels (Always expected to be 1 for now) - // and their dimensions are expressed as [width, height, feature_maps, batch]. - // In other words, the lower three dimensions of a tensor specify a single input in - // [width, height, feature_maps], while any other specified dimension represents a batch - // in the appropriate dimension space. For example, a tensor with dimensions [128, 128, 64, 16] - // represents a 1D batch space with 16 batches of 128 elements in width and height - // and 64 feature maps each. - - if (shape.dimensions.size() == 2) - { - const uint32_t h = nnfw::rt::getSizeOfDimension(shape, 0); - const uint32_t w = nnfw::rt::getSizeOfDimension(shape, 1); - - return arm_compute::TensorShape(w, h); - } - else if (shape.dimensions.size() == 3) - { - const uint32_t w = nnfw::rt::getSizeOfDimension(shape, 2); - const uint32_t h = nnfw::rt::getSizeOfDimension(shape, 1); - const uint32_t feature_maps = nnfw::rt::getSizeOfDimension(shape, 0); - return arm_compute::TensorShape(w, h, feature_maps); - } - else if (shape.dimensions.size() == 4) - { - const uint32_t batch = nnfw::rt::getSizeOfDimension(shape, 0); - const uint32_t feature_maps = nnfw::rt::getSizeOfDimension(shape, 1); - const uint32_t h = nnfw::rt::getSizeOfDimension(shape, 2); - const uint32_t w = nnfw::rt::getSizeOfDimension(shape, 3); - return arm_compute::TensorShape(w, h, feature_maps, batch); - } -} - -// argument isImageSetMatrix is true by default (see the header file) -// only when the rank of shape is 4 and it contains image set info -// of which shape shoud be changed from NHWC to WHCN (arm_compute shape), -arm_compute::TensorShape fromNNShape(const nnfw::rt::Shape &shape, bool isImageSetMatrix) -{ - if (shape.dimensions.size() == 1) - return fromVectorNNShape(shape); - // TODO: check if merging this condition and the next condition is possible - else if ((shape.dimensions.size() == 2) || (shape.dimensions.size() == 3)) - return fromMatrixNNShape(shape); - else if (shape.dimensions.size() == 4) - { - if (isImageSetMatrix == false) - return fromMatrixNNShape(shape); - else - { - // NNAPI assumes the following ordering: - // - // dim(0) -> N - // dim(1) -> H - // dim(2) -> W - // dim(3) -> C - // - uint32_t c = nnfw::rt::getSizeOfDimension(shape, 3); - uint32_t h = nnfw::rt::getSizeOfDimension(shape, 1); - uint32_t w = nnfw::rt::getSizeOfDimension(shape, 2); - uint32_t n = nnfw::rt::getSizeOfDimension(shape, 0); - - return arm_compute::TensorShape(w, h, c, n); - } - } -} - -} // namespace util -} // namespace acl -} // namespace kernel -} // namespace nnfw diff --git a/libs/kernel/acl/src/shape.h b/libs/kernel/acl/src/shape.h deleted file mode 100644 index 70c4fb2..0000000 --- a/libs/kernel/acl/src/shape.h +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef __NNFW_KERNEL_ACL_SHAPE_H__ -#define __NNFW_KERNEL_ACL_SHAPE_H__ - -#include -#include -#include -#include -#include - -namespace nnfw -{ -namespace rt -{ - -// TODO remove from this source and use it from runtime -uint32_t getSizeOfDimension(const Shape &shape, uint32_t dimensionIdx); - -} // namespace rt -} // namespace nnfw - -namespace nnfw -{ -namespace kernel -{ -namespace acl -{ -namespace util -{ - -arm_compute::TensorShape fromVectorNNShape(const nnfw::rt::Shape &shape); - -// For 4D image set matrix whose shape shoud be changed from NHWC to WHCN (arm_compute shape), -// pass isImageMatrix = true ; -// For other matrix, pass isImageMatrix = false -arm_compute::TensorShape fromNNShape(const nnfw::rt::Shape &shape, bool isImageSetMatrix = true); - -template -void insertFusedActivationLayer(TensorT &out, int activation, - std::vector> &fns) -{ - auto relu_f = std::make_shared(); - - switch (activation) - { - case ANEURALNETWORKS_FUSED_NONE: - // DO NOTHING - return; - - case ANEURALNETWORKS_FUSED_RELU: - { - const arm_compute::ActivationLayerInfo relu_info( - arm_compute::ActivationLayerInfo::ActivationFunction::RELU); - - // Do in-place update - relu_f->configure(out.ptr(), nullptr, relu_info); - } - break; - - case ANEURALNETWORKS_FUSED_RELU1: - { - const arm_compute::ActivationLayerInfo relu_info( - arm_compute::ActivationLayerInfo::ActivationFunction::BOUNDED_RELU, 1.f); - - // Do in-place update - relu_f->configure(out.ptr(), nullptr, relu_info); - } - break; - - case ANEURALNETWORKS_FUSED_RELU6: - { - const arm_compute::ActivationLayerInfo relu_info( - arm_compute::ActivationLayerInfo::ActivationFunction::BOUNDED_RELU, 6.f); - - // Do in-place update - relu_f->configure(out.ptr(), nullptr, relu_info); - } - break; - - default: - assert("Undefined activation type." && 0); - break; - } - - fns.emplace_back(relu_f); -} - -} // namespace util -} // namespace acl -} // namespace kernel -} // namespace nnfw - -#endif // __NNFW_KERNEL_ACL_SHAPE_H__ diff --git a/libs/kernel/acl/src/support.cpp b/libs/kernel/acl/src/support.cpp deleted file mode 100644 index 2befdfe..0000000 --- a/libs/kernel/acl/src/support.cpp +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -#include "support.h" - -namespace nnfw -{ -namespace support -{ -namespace nnapi -{ -namespace feature -{ - -// TODO Extract this function as utility function -// NOTE It is not a good design to access nnfw::rt::Shape nnfw_support_nnapi lib -nnfw::util::feature::Shape asFeatureShape(const nnfw::rt::Shape &shape) -{ - // NNAPI assumes the following ordering: - // - // dim(0) -> N - // dim(1) -> H - // dim(2) -> W - // dim(3) -> C - // - int32_t c = nnfw::rt::getSizeOfDimension(shape, 3); - int32_t h = nnfw::rt::getSizeOfDimension(shape, 1); - int32_t w = nnfw::rt::getSizeOfDimension(shape, 2); - - assert(nnfw::rt::getSizeOfDimension(shape, 0) == 1); - - return nnfw::util::feature::Shape{c, h, w}; -} - -} // namespace feature -} // namespace nnapi -} // namespace support -} // namespace nnfw diff --git a/libs/kernel/acl/src/support.h b/libs/kernel/acl/src/support.h deleted file mode 100644 index 0372907..0000000 --- a/libs/kernel/acl/src/support.h +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef __NNFW_KERNEL_SUPPORT_H_TEMPORARY__ -#define __NNFW_KERNEL_SUPPORT_H_TEMPORARY__ - -// NOTE these are not decided yet but need to be moved out from Conv2D -// to separate NEON implementation to it's folder -// TODO move to some folder where it should be - -#include "util/feature/Shape.h" - -#include - -namespace nnfw -{ -namespace support -{ -namespace nnapi -{ -namespace feature -{ - -// TODO Extract this function as utility function -// NOTE It is not a good design to access nnfw::rt::Shape nnfw_support_nnapi lib -nnfw::util::feature::Shape asFeatureShape(const nnfw::rt::Shape &shape); - -} // namespace feature -} // namespace nnapi -} // namespace support -} // namespace nnfw - -#include - -#include "util/feature/Reader.h" - -namespace nnfw -{ -namespace support -{ -namespace acl -{ -namespace feature -{ - -template class Reader final : public nnfw::util::feature::Reader -{ -public: - Reader(arm_compute::ITensor *tensor) : _tensor{tensor} - { - // DO NOTHING - } - -public: - T at(uint32_t ch, uint32_t row, uint32_t col) const override - { - return *ptr_to_element(ch, row, col); - } - -private: - T *ptr_to_element(uint32_t ch, uint32_t row, uint32_t col) const - { - // ARM Compute uses CHW ordering - return reinterpret_cast(_tensor->ptr_to_element(arm_compute::Coordinates{col, row, ch})); - } - -private: - arm_compute::ITensor *_tensor; -}; - -} // namespace feature -} // namespace acl -} // namespace support -} // namespace nnfw - -#endif // __NNFW_KERNEL_SUPPORT_H_TEMPORARY__ diff --git a/libs/kernel/acl/src/util.cpp b/libs/kernel/acl/src/util.cpp deleted file mode 100644 index 3fbdf5d..0000000 --- a/libs/kernel/acl/src/util.cpp +++ /dev/null @@ -1,139 +0,0 @@ -/* - * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -#include "util.h" - -namespace nnfw -{ -namespace kernel -{ -namespace acl -{ -namespace util -{ - -void initData(float *data, int num, float value) -{ - for (int i = 0; i < num; i++) - { - *(data + i) = value; - } -} - -void initData_Increasing(float *data, int num, float value) -{ - for (int i = 0; i < num; i++) - { - *(data + i) = value; - value++; - } -} - -// compareData -// return true if result == expected with the shape info, -// otherwise false -bool compareData(const float *result, const float *expected, const nnfw::rt::Shape &shape) -{ - if (shape.dimensions.size() == 4) - { - // TODO fix indentation - uint32_t height = nnfw::rt::getSizeOfDimension(shape, 1); - uint32_t width = nnfw::rt::getSizeOfDimension(shape, 2); - uint32_t numitems = height * width; - for (int item = 0; item < numitems; item++) - { - if (!::nnfw::util::fp32::epsilon_equal(*(result + item), *(expected + item), 1)) - { - LOG(ERROR) << "compareData failed: result " << *(result + item) << ", expected " - << *(expected + item) << ", diff " - << ::nnfw::util::fp32::relative_diff(*(result + item), *(expected + item)) - << std::endl; - return false; - } - } - } - else if ((shape.dimensions.size() == 2) || (shape.dimensions.size() == 3)) - { - uint32_t numitems = 1; - - for (int i = 0; i < shape.dimensions.size(); i++) - numitems *= nnfw::rt::getSizeOfDimension(shape, i); - - for (int item = 0; item < numitems; item++) - { - if (!::nnfw::util::fp32::epsilon_equal(*(result + item), *(expected + item), 1)) - { - LOG(ERROR) << "compareData failed: result " << *(result + item) << ", expected " - << *(expected + item) << ", diff " - << ::nnfw::util::fp32::relative_diff(*(result + item), *(expected + item)) - << std::endl; - return false; - } - } - } - else if (shape.dimensions.size() == 1) - { - uint32_t numitems = nnfw::rt::getSizeOfDimension(shape, 0); - for (int item = 0; item < numitems; item++) - { - if (!::nnfw::util::fp32::epsilon_equal(*(result + item), *(expected + item), 1)) - { - LOG(ERROR) << "compareData failed: result " << *(result + item) << ", expected " - << *(expected + item) << ", diff " - << ::nnfw::util::fp32::relative_diff(*(result + item), *(expected + item)) - << std::endl; - return false; - } - } - } - else - { - // TODO: add a handler for 5, 6, ... - LOG(ERROR) << "Unhandled shape: " << shape.dimensions.size() << std::endl; - } - return true; -} - -void NCHW2NHWC(const float *nchw, float *nhwc, const nnfw::rt::Shape &shape) -{ - uint32_t N = nnfw::rt::getSizeOfDimension(shape, 0); - uint32_t H = nnfw::rt::getSizeOfDimension(shape, 1); - uint32_t W = nnfw::rt::getSizeOfDimension(shape, 2); - uint32_t C = nnfw::rt::getSizeOfDimension(shape, 3); - - for (uint32_t n = 0; n < N; n++) - { - for (uint32_t c = 0; c < C; c++) - { - for (uint32_t h = 0; h < H; h++) - { - for (uint32_t w = 0; w < W; w++) - { - uint32_t soffset = w + (h * W) + (c * W * H) + (n * W * H * C); - uint32_t doffset = c + (w * C) + (h * C * W) + (n * C * W * H); - *(nhwc + doffset) = *(nchw + soffset); - } - } - } - } -} - -} // namespace util -} // namespace acl -} // namespace kernel -} // namespace nnfw diff --git a/libs/kernel/acl/src/util.h b/libs/kernel/acl/src/util.h deleted file mode 100644 index 976c6eb..0000000 --- a/libs/kernel/acl/src/util.h +++ /dev/null @@ -1,208 +0,0 @@ -/* - * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef __NNFW_KERNEL_ACL_UTIL_H__ -#define __NNFW_KERNEL_ACL_UTIL_H__ -#include - -#include -#include -#include - -namespace nnfw -{ -namespace kernel -{ -namespace acl -{ -namespace util -{ - -// TODO: make a separate module. -class TensorWrapper -{ -public: - TensorWrapper(std::vector dims, OperandType type = OperandType::FLOAT32, - float scale = 1.0, int32_t offset = 0) - : _shape{type, dims, scale, offset} - { - - // currently, we support only FLOAT32 for now. - assert(type == OperandType::FLOAT32); - - uint32_t size_bytes = sizeof(float); - - _num_elems = 1; - for (auto &d : dims) - { - _num_elems *= d; - } - - _data = new uint8_t[_num_elems * size_bytes]; - } - - ~TensorWrapper() { delete[] _data; } - - const nnfw::rt::Shape shape() const { return _shape; } - - uint32_t num_elems() const { return _num_elems; } - - template T at(const uint32_t &idx) const { return reinterpret_cast(_data)[idx]; } - - template T &at(const uint32_t &idx) { return reinterpret_cast(_data)[idx]; } - - template T *ptr() { return reinterpret_cast(_data); } - - void initValue(float f) - { - for (uint32_t i = 0; i < _num_elems; ++i) - { - at(i) = f; - } - } - - typedef std::function funcInit4; - void initValue(funcInit4 f) - { - assert(_shape.dimensions.size() == 4); - - int N = _shape.dimensions[0]; - int H = _shape.dimensions[1]; - int W = _shape.dimensions[2]; - int C = _shape.dimensions[3]; - - for (int n = 0; n < N; ++n) - { - for (int h = 0; h < H; ++h) - { - for (int w = 0; w < W; ++w) - { - for (int c = 0; c < C; ++c) - { - uint32_t offset = n * H * W * C + h * W * C + w * C + c; - at(offset) = f(n, c, h, w); - } - } - } - } - } - - typedef std::function funcInit3; - void initValue(funcInit3 f) - { - assert(_shape.dimensions.size() == 3); - - int C = _shape.dimensions[0]; - int H = _shape.dimensions[1]; - int W = _shape.dimensions[2]; - - for (int h = 0; h < H; ++h) - { - for (int w = 0; w < W; ++w) - { - for (int c = 0; c < C; ++c) - { - uint32_t offset = h * W * C + w * C + c; - at(offset) = f(c, h, w); - } - } - } - } - - typedef std::function funcInit2; - void initValue(funcInit2 f) - { - assert(_shape.dimensions.size() == 2); - - int H = _shape.dimensions[0]; - int W = _shape.dimensions[1]; - - for (int h = 0; h < H; ++h) - { - for (int w = 0; w < W; ++w) - { - uint32_t offset = h * W + w; - at(offset) = f(h, w); - } - } - } - - typedef std::function funcInit1; - void initValue(funcInit1 f) - { - assert(_shape.dimensions.size() == 1); - - int W = _shape.dimensions[0]; - - for (int w = 0; w < W; ++w) - { - uint32_t offset = w; - at(offset) = f(w); - } - } - - void initValue(std::vector v) - { - assert(v.size() == _num_elems); - for (uint32_t i = 0; i < _num_elems; ++i) - { - at(i) = v[i]; - } - } - - bool operator==(const TensorWrapper &t) const - { - // compare the shape - assert(num_elems() == t.num_elems()); - assert(_shape.type == t.shape().type); - assert(_shape.scale == t.shape().scale); - assert(_shape.offset == t.shape().offset); - assert(_shape.dimensions == t.shape().dimensions); - - // currently, we support only FLOAT32. - assert(_shape.type == OperandType::FLOAT32); - - for (uint32_t i = 0; i < _num_elems; ++i) - { - if (std::fabs(static_cast(at(i) - t.at(i))) > 0.001f) - { - std::cout << "Comparing [" << i << "] " << at(i) << "," << t.at(i) - << std::endl; - return false; - } - } - - return true; - } - -private: - nnfw::rt::Shape _shape; - uint32_t _num_elems; - uint8_t *_data; -}; - -void initData(float *data, int num, float value); -bool compareData(const float *result, const float *expected, const nnfw::rt::Shape &shape); -void initData_Increasing(float *data, int num, float value); - -void NCHW2NHWC(const float *nchw, float *nhwc, const nnfw::rt::Shape &shape); - -} // namespace util -} // namespace acl -} // namespace kernel -} // namespace nnfw - -#endif // __NNFW_KERNEL_ACL_UTIL_H__ -- 2.7.4