[hi-perf-cpu] High performance cpu backend (#5064)
authorАндрей Шедько/AI Tools Lab /SRR/Engineer/삼성전자 <a.shedko@samsung.com>
Wed, 15 May 2019 07:52:09 +0000 (10:52 +0300)
committer오형석/On-Device Lab(SR)/Staff Engineer/삼성전자 <hseok82.oh@samsung.com>
Wed, 15 May 2019 07:52:09 +0000 (16:52 +0900)
* [hi-perf] High performance cpu backend

initial support for nnpack library

Signed-off-by: Andrei Shedko <a.shedko@samsung.com>
* [hi-perf] NNPACK actually builds correctly.

NNPACK builds, but cpuinfo does not detect CPU yet.

Signed-off-by: Andrei Shedko <a.shedko@samsung.com>
* [hi-perf] Cleanup cmake and test inference

Split nnpack deps download into separate configs.
Added float16 format options to arm builds.
Added nnpack relu test to be run when it is possible

Signed-off-by: Andrei Shedko <a.shedko@samsung.com>
* [hi-perf] Try to fix cmake crossbuild

Try to fix cmake crossbuild

Signed-off-by: Andrei Shedko <a.shedko@samsung.com>
* [hi-perf] Fix x86_64 build

PeachPy on x86_64 needs to generate some files for successful
compilation
Added explicit dependency on Opcodes.py

Signed-off-by: Andrei Shedko <a.shedko@samsung.com>
* [hi-perf] Fix archive type in cmake

Fix archive type in cmake
Fix avx instruction generation for nnpack

Signed-off-by: Andrei Shedko <a.shedko@samsung.com>
* [hi-perf] Review Fixes

file-terminating newlines added, codestyle fixed.

Signed-off-by: Andrei Shedko <a.shedko@samsung.com>
* [hi-perf] More fixes for cmake files

Status reporting improved.
Removed superfluous linkages and includes.

Signed-off-by: Andrei Shedko <a.shedko@samsung.com>
* [hi-perf] More review Fixes

Fixed comment, Removed conflicting change

Signed-off-by: Andrei Shedko <a.shedko@samsung.com>
23 files changed:
.gitignore
cmake/CfgOptionFlags.cmake
cmake/buildtool/config/config_armv7l-linux.cmake
cmake/options/options_armv7l-tizen.cmake
cmake/packages/CpuinfoSourceConfig.cmake [new file with mode: 0644]
cmake/packages/Enum34SourceConfig.cmake [new file with mode: 0644]
cmake/packages/FP16SourceConfig.cmake [new file with mode: 0644]
cmake/packages/FXdivSourceConfig.cmake [new file with mode: 0644]
cmake/packages/NNPACKConfig.cmake [new file with mode: 0644]
cmake/packages/NNPACKSourceConfig.cmake [new file with mode: 0644]
cmake/packages/OpcodesSourceConfig.cmake [new file with mode: 0644]
cmake/packages/PSIMDSourceConfig.cmake [new file with mode: 0644]
cmake/packages/PeachpySourceConfig.cmake [new file with mode: 0644]
cmake/packages/PthreadpoolSourceConfig.cmake [new file with mode: 0644]
cmake/packages/SixSourceConfig.cmake [new file with mode: 0644]
runtimes/neurun/backend/CMakeLists.txt
runtimes/neurun/backend/hi_perf_cpu/CMakeLists.txt [new file with mode: 0644]
runtimes/neurun/backend/hi_perf_cpu/HighPerformanceBackend.test.cc [new file with mode: 0644]
runtimes/neurun/backend/hi_perf_cpu/StageGenerator.cc [new file with mode: 0644]
runtimes/neurun/backend/hi_perf_cpu/StageGenerator.h [new file with mode: 0644]
runtimes/neurun/backend/hi_perf_cpu/TensorBuilder.cc [new file with mode: 0644]
runtimes/neurun/backend/hi_perf_cpu/TensorBuilder.h [new file with mode: 0644]
runtimes/neurun/backend/hi_perf_cpu/kernel/CMakeLists.txt [new file with mode: 0644]

index f5af17b..178769d 100644 (file)
@@ -89,6 +89,13 @@ GRTAGS
 /externals/absl
 /externals/nonius
 /externals/boost
+/externals/NNPACK
+/externals/python*
+/externals/FXdiv
+/externals/cpuinfo
+/externals/PSIMD
+/externals/pthreadpool
+/externals/FP16
 
 # tflkit info files
 /tools/tflkit/*.info
index 3ad969e..7d7fe89 100644 (file)
@@ -44,6 +44,7 @@ option(DOWNLOAD_EIGEN "Download Eigen source" ON)
 option(DOWNLOAD_FARMHASH "Download farmhash source" ON)
 option(DOWNLOAD_GEMMLOWP "Download GEMM low precesion library source" ON)
 option(DOWNLOAD_NEON2SSE "Download NEON2SSE library source" ON)
+option(DOWNLOAD_NNPACK "Download NNPACK source" ON)
 option(DOWNLOAD_FLATBUFFERS "Download FlatBuffers source" ON)
 option(BUILD_TENSORFLOW_LITE "Build TensorFlow Lite from the downloaded source" ON)
 option(DOWNLOAD_ARMCOMPUTE "Download ARM Compute source" ON)
index ef6dd41..6d6459f 100644 (file)
@@ -14,4 +14,5 @@ set(FLAGS_COMMON ${FLAGS_COMMON}
     "-mfpu=neon-vfpv4"
     "-funsafe-math-optimizations"
     "-ftree-vectorize"
+    "-mfp16-format=ieee"
     )
index 687c523..6942baf 100644 (file)
@@ -5,3 +5,4 @@ option(BUILD_ARMCOMPUTE "Build ARM Compute from the downloaded source" ON)
 option(BUILD_ANDROID_TFLITE "Enable android support for TensorFlow Lite" OFF)
 option(DOWNLOAD_ARMCOMPUTE "Download ARM Compute source" ON)
 option(DOWNLOAD_NEON2SSE "Download NEON2SSE library source" OFF)
+option(DOWNLOAD_NNPACK "Download NNPACK library source" OFF)
diff --git a/cmake/packages/CpuinfoSourceConfig.cmake b/cmake/packages/CpuinfoSourceConfig.cmake
new file mode 100644 (file)
index 0000000..0939ba3
--- /dev/null
@@ -0,0 +1,14 @@
+function(_cpuinfoSource_import)
+    nnfw_include(ExternalSourceTools)
+    nnfw_include(OptionTools)
+
+    envoption(EXTERNAL_DOWNLOAD_SERVER "https://github.com")
+    set(CPUINFO_URL ${EXTERNAL_DOWNLOAD_SERVER}/pytorch/cpuinfo/archive/d5e37adf1406cf899d7d9ec1d317c47506ccb970.tar.gz)
+
+    ExternalSource_Get("cpuinfo" ${DOWNLOAD_NNPACK} ${CPUINFO_URL})
+
+    set(CPUINFO_SOURCE_DIR ${cpuinfo_SOURCE_DIR} PARENT_SCOPE)
+    set(CPUINFO_SOURCE_FOUND ${cpuinfo_SOURCE_GET} PARENT_SCOPE)
+endfunction(_cpuinfoSource_import)
+
+_cpuinfoSource_import()
diff --git a/cmake/packages/Enum34SourceConfig.cmake b/cmake/packages/Enum34SourceConfig.cmake
new file mode 100644 (file)
index 0000000..96b6ca8
--- /dev/null
@@ -0,0 +1,14 @@
+function(_enum34Source_import)
+    nnfw_include(ExternalSourceTools)
+    nnfw_include(OptionTools)
+
+    envoption(EXTERNAL_DOWNLOAD_SERVER "https://bitbucket.org")
+    set(ENUM34_URL ${EXTERNAL_DOWNLOAD_SERVER}/stoneleaf/enum34/get/1.1.6.tar.gz)
+
+    ExternalSource_Get("python_enum" ${DOWNLOAD_NNPACK} ${ENUM34_URL})
+
+    set(PYTHON_ENUM_SOURCE_DIR ${python_enum_SOURCE_DIR} PARENT_SCOPE)
+    set(PYTHON_ENUM_SOURCE_FOUND ${python_enum_SOURCE_GET} PARENT_SCOPE)
+endfunction(_enum34Source_import)
+
+_enum34Source_import()
diff --git a/cmake/packages/FP16SourceConfig.cmake b/cmake/packages/FP16SourceConfig.cmake
new file mode 100644 (file)
index 0000000..7df5294
--- /dev/null
@@ -0,0 +1,14 @@
+function(_FP16Source_import)
+    nnfw_include(ExternalSourceTools)
+    nnfw_include(OptionTools)
+
+    envoption(EXTERNAL_DOWNLOAD_SERVER "https://github.com")
+    set(FP16_URL ${EXTERNAL_DOWNLOAD_SERVER}/Maratyszcza/FP16/archive/febbb1c163726b5db24bed55cc9dc42529068997.tar.gz)
+
+    ExternalSource_Get("FP16" ${DOWNLOAD_NNPACK} ${FP16_URL})
+
+    set(FP16_SOURCE_DIR ${FP16_SOURCE_DIR} PARENT_SCOPE)
+    set(FP16_SOURCE_FOUND ${FP16_SOURCE_GET} PARENT_SCOPE)
+endfunction(_FP16Source_import)
+
+_FP16Source_import()
diff --git a/cmake/packages/FXdivSourceConfig.cmake b/cmake/packages/FXdivSourceConfig.cmake
new file mode 100644 (file)
index 0000000..2ea574a
--- /dev/null
@@ -0,0 +1,14 @@
+function(_FXdivSource_import)
+    nnfw_include(ExternalSourceTools)
+    nnfw_include(OptionTools)
+
+    envoption(EXTERNAL_DOWNLOAD_SERVER "https://github.com")
+    set(FXDIV_URL ${EXTERNAL_DOWNLOAD_SERVER}/Maratyszcza/FXdiv/archive/f8c5354679ec2597792bc70a9e06eff50c508b9a.tar.gz)
+
+    ExternalSource_Get("FXdiv" ${DOWNLOAD_NNPACK} ${FXDIV_URL})
+
+    set(FXDIV_SOURCE_DIR ${FXdiv_SOURCE_DIR} PARENT_SCOPE)
+    set(FXDIV_SOURCE_FOUND ${FXdiv_SOURCE_GET} PARENT_SCOPE)
+endfunction(_FXdivSource_import)
+
+_FXdivSource_import()
diff --git a/cmake/packages/NNPACKConfig.cmake b/cmake/packages/NNPACKConfig.cmake
new file mode 100644 (file)
index 0000000..918425b
--- /dev/null
@@ -0,0 +1,45 @@
+function(_NNPACK_Import)
+    nnfw_find_package(NNPACKSource QUIET)
+
+    if(NOT NNPACK_SOURCE_FOUND)
+        set(NNPACK_FOUND FALSE PARENT_SCOPE)
+        message(STATUS "NNPACK not found")
+        return()
+    endif(NOT NNPACK_SOURCE_FOUND)
+
+    nnfw_find_package(CpuinfoSource REQUIRED)
+    nnfw_find_package(FP16Source REQUIRED)
+    nnfw_find_package(FXdivSource REQUIRED)
+    nnfw_find_package(PSIMDSource REQUIRED)
+    nnfw_find_package(PthreadpoolSource REQUIRED)
+    nnfw_find_package(SixSource REQUIRED)
+    nnfw_find_package(Enum34Source REQUIRED)
+    nnfw_find_package(OpcodesSource REQUIRED)
+    nnfw_find_package(PeachpySource REQUIRED)
+
+    # workaround for CI
+    set(THREADS_PTHREAD_ARG "2" CACHE STRING "Forcibly set by CMakeLists.txt." FORCE)
+    if(NOT TARGET nnpack)
+        # Allows us to build nnpack at build time
+        set(NNPACK_BUILD_TESTS OFF CACHE BOOL "")
+        set(NNPACK_BUILD_BENCHMARKS OFF CACHE BOOL "")
+        set(NNPACK_LIBRARY_TYPE "static" CACHE STRING "")
+        set(PTHREADPOOL_LIBRARY_TYPE "static" CACHE STRING "")
+        set(CPUINFO_LIBRARY_TYPE "static" CACHE STRING "")
+        add_extdirectory("${NNPACK_SOURCE_DIR}" nnpack)
+        # We build static versions of nnpack and pthreadpool but link
+        # them into a shared library (high-perf-backend), so they need PIC.
+        set_property(TARGET nnpack PROPERTY POSITION_INDEPENDENT_CODE ON)
+        set_property(TARGET pthreadpool PROPERTY POSITION_INDEPENDENT_CODE ON)
+        set_property(TARGET cpuinfo PROPERTY POSITION_INDEPENDENT_CODE ON)
+    endif()
+
+    set(NNPACK_FOUND TRUE PARENT_SCOPE)
+    set(NNPACK_INCLUDE_DIRS
+            $<TARGET_PROPERTY:nnpack,INCLUDE_DIRECTORIES>
+            $<TARGET_PROPERTY:pthreadpool,INCLUDE_DIRECTORIES> PARENT_SCOPE)
+    set(NNPACK_LIBRARIES $<TARGET_FILE:nnpack> $<TARGET_FILE:cpuinfo> PARENT_SCOPE)
+
+endfunction(_NNPACK_Import)
+
+_NNPACK_Import()
diff --git a/cmake/packages/NNPACKSourceConfig.cmake b/cmake/packages/NNPACKSourceConfig.cmake
new file mode 100644 (file)
index 0000000..b6b5b01
--- /dev/null
@@ -0,0 +1,20 @@
+function(_NNPACKSource_import)
+    if(NOT DOWNLOAD_NNPACK)
+        set(NNPACKSource_FOUND FALSE PARENT_SCOPE)
+        message(WARN "NNPACK not downloaded")
+        return()
+    endif(NOT DOWNLOAD_NNPACK)
+
+    nnfw_include(ExternalSourceTools)
+    nnfw_include(OptionTools)
+
+    envoption(EXTERNAL_DOWNLOAD_SERVER "https://github.com")
+    set(NNPACK_URL ${EXTERNAL_DOWNLOAD_SERVER}/Maratyszcza/NNPACK/archive/c039579abe21f5756e0f0e45e8e767adccc11852.tar.gz)
+    ExternalSource_Get("NNPACK" ${DOWNLOAD_NNPACK} ${NNPACK_URL})
+
+    set(NNPACK_SOURCE_DIR ${NNPACK_SOURCE_DIR} PARENT_SCOPE)
+    set(NNPACK_INCLUDE_DIR ${NNPACK_SOURCE_DIR}/include PARENT_SCOPE)
+    set(NNPACK_SOURCE_FOUND ${NNPACK_SOURCE_GET} PARENT_SCOPE)
+endfunction(_NNPACKSource_import)
+
+_NNPACKSource_import()
diff --git a/cmake/packages/OpcodesSourceConfig.cmake b/cmake/packages/OpcodesSourceConfig.cmake
new file mode 100644 (file)
index 0000000..635249f
--- /dev/null
@@ -0,0 +1,13 @@
+function(_PeachpySource_import)
+    nnfw_include(ExternalSourceTools)
+    nnfw_include(OptionTools)
+
+    envoption(EXTERNAL_DOWNLOAD_SERVER "https://github.com")
+    set(PEACHPY_URL ${EXTERNAL_DOWNLOAD_SERVER}/Maratyszcza/Opcodes/archive/6e2b0cd9f1403ecaf164dea7019dd54db5aea252.tar.gz)
+    ExternalSource_Get("python_opcodes" ${DOWNLOAD_NNPACK} ${PEACHPY_URL})
+        
+    set(PYTHON_OPCODES_SOURCE_DIR ${python_opcodes_SOURCE_DIR} PARENT_SCOPE)
+    set(PYTHON_OPCODES_SOURCE_FOUND ${python_opcodes_SOURCE_GET} PARENT_SCOPE)
+endfunction(_PeachpySource_import)
+
+_PeachpySource_import()
diff --git a/cmake/packages/PSIMDSourceConfig.cmake b/cmake/packages/PSIMDSourceConfig.cmake
new file mode 100644 (file)
index 0000000..0f208cd
--- /dev/null
@@ -0,0 +1,14 @@
+function(_PSIMDSource_import)
+    nnfw_include(ExternalSourceTools)
+    nnfw_include(OptionTools)
+
+    envoption(EXTERNAL_DOWNLOAD_SERVER "https://github.com")
+    set(PSIMD_URL ${EXTERNAL_DOWNLOAD_SERVER}/Maratyszcza/psimd/archive/90a938f30ba414ada2f4b00674ee9631d7d85e19.tar.gz)
+
+    ExternalSource_Get("PSIMD" ${DOWNLOAD_NNPACK} ${PSIMD_URL})
+
+    set(PSIMD_SOURCE_DIR ${PSIMD_SOURCE_DIR} PARENT_SCOPE)
+    set(PSIMD_SOURCE_FOUND ${PSIMD_SOURCE_GET} PARENT_SCOPE)
+endfunction(_PSIMDSource_import)
+
+_PSIMDSource_import()
diff --git a/cmake/packages/PeachpySourceConfig.cmake b/cmake/packages/PeachpySourceConfig.cmake
new file mode 100644 (file)
index 0000000..4745909
--- /dev/null
@@ -0,0 +1,20 @@
+function(_PeachpySource_import)
+    nnfw_include(ExternalSourceTools)
+    nnfw_include(OptionTools)
+
+    envoption(EXTERNAL_DOWNLOAD_SERVER "https://github.com")
+    set(PEACHPY_URL ${EXTERNAL_DOWNLOAD_SERVER}/Maratyszcza/PeachPy/archive/01d15157a973a4ae16b8046313ddab371ea582db.tar.gz)
+
+    ExternalSource_Get("python_peachpy" ${DOWNLOAD_NNPACK} ${PEACHPY_URL})
+    FIND_PACKAGE(PythonInterp)
+
+    # Generate opcodes:
+    SET(ENV{PYTHONPATH} ${PYTHON_SIX_SOURCE_DIR}:${PYTHON_ENUM_SOURCE_DIR}:${PYTHON_OPCODES_SOURCE_DIR})
+    EXECUTE_PROCESS(COMMAND ${PYTHON_EXECUTABLE} ./setup.py generate
+            WORKING_DIRECTORY ${python_peachpy_SOURCE_DIR}
+            RESULT_VARIABLE BUILT_PP)
+    set(PYTHON_PEACHPY_SOURCE_DIR ${python_peachpy_SOURCE_DIR} PARENT_SCOPE)
+    set(PYTHON_PEACHPY_SOURCE_FOUND ${python_peachpy_SOURCE_GET} PARENT_SCOPE)
+endfunction(_PeachpySource_import)
+
+_PeachpySource_import()
diff --git a/cmake/packages/PthreadpoolSourceConfig.cmake b/cmake/packages/PthreadpoolSourceConfig.cmake
new file mode 100644 (file)
index 0000000..0c3b61a
--- /dev/null
@@ -0,0 +1,14 @@
+function(_pthreadpoolSource_import)
+    nnfw_include(ExternalSourceTools)
+    nnfw_include(OptionTools)
+
+    envoption(EXTERNAL_DOWNLOAD_SERVER "https://github.com")
+    set(PTHREADPOOL_URL ${EXTERNAL_DOWNLOAD_SERVER}/Maratyszcza/pthreadpool/archive/6673a4c71fe35e077c6843a74017d9c25610c537.tar.gz)
+
+    ExternalSource_Get("pthreadpool" ${DOWNLOAD_NNPACK} ${PTHREADPOOL_URL})
+
+    set(PTHREADPOOL_SOURCE_DIR ${pthreadpool_SOURCE_DIR} PARENT_SCOPE)
+    set(PTHREADPOOL_SOURCE_FOUND ${pthreadpool_SOURCE_GET} PARENT_SCOPE)
+endfunction(_pthreadpoolSource_import)
+
+_pthreadpoolSource_import()
diff --git a/cmake/packages/SixSourceConfig.cmake b/cmake/packages/SixSourceConfig.cmake
new file mode 100644 (file)
index 0000000..309ead3
--- /dev/null
@@ -0,0 +1,14 @@
+function(_SIXSource_import)
+    nnfw_include(ExternalSourceTools)
+    nnfw_include(OptionTools)
+
+    envoption(EXTERNAL_DOWNLOAD_SERVER "https://github.com")
+    set(six_URL ${EXTERNAL_DOWNLOAD_SERVER}/benjaminp/six/archive/1.11.0.tar.gz)
+
+    ExternalSource_Get("python_six" ${DOWNLOAD_NNPACK} ${six_URL})
+
+    set(PYTHON_SIX_SOURCE_DIR ${python_six_SOURCE_DIR} PARENT_SCOPE)
+    set(PYTHON_SIX_SOURCE_FOUND ${python_six_SOURCE_GET} PARENT_SCOPE)
+endfunction(_SIXSource_import)
+
+_SIXSource_import()
index 648f410..41eb872 100644 (file)
@@ -4,3 +4,4 @@ add_subdirectory(cpu)
 add_subdirectory(acl_cl)
 add_subdirectory(acl_neon)
 add_subdirectory(acl_common)
+add_subdirectory(hi_perf_cpu)
diff --git a/runtimes/neurun/backend/hi_perf_cpu/CMakeLists.txt b/runtimes/neurun/backend/hi_perf_cpu/CMakeLists.txt
new file mode 100644 (file)
index 0000000..876193a
--- /dev/null
@@ -0,0 +1,40 @@
+set(LIB_NEURUN_BACKEND_HI_PERF_CPU neurun_backend_hi_perf)
+
+nnfw_find_package(NNPACK QUIET)
+IF(NOT ${NNPACK_FOUND})
+    message(STATUS "NNPACK not found => not building high performance cpu backend")
+    return()
+ENDIF(NOT ${NNPACK_FOUND})
+add_subdirectory(kernel)
+
+file(GLOB_RECURSE SOURCES "*.cc")
+file(GLOB_RECURSE REMOVE_KERNEL_SOURCES "kernel/*.cc")
+file(GLOB_RECURSE TESTS "*.test.cc")
+#list(REMOVE_ITEM SOURCES ${REMOVE_KERNEL_SOURCES})
+list(REMOVE_ITEM SOURCES ${TESTS})
+
+add_library(${LIB_NEURUN_BACKEND_HI_PERF_CPU} SHARED ${SOURCES})
+
+target_link_libraries(${LIB_NEURUN_BACKEND_HI_PERF_CPU} nnfw_lib_misc)
+target_link_libraries(${LIB_NEURUN_BACKEND_HI_PERF_CPU} nnfw_lib_cpp14)
+target_link_libraries(${LIB_NEURUN_BACKEND_HI_PERF_CPU} ${LIB_NEURUN_KERNEL_NNPACK})
+target_link_libraries(${LIB_NEURUN_BACKEND_HI_PERF_CPU} neurun-core)
+
+target_compile_options(${LIB_NEURUN_BACKEND_HI_PERF_CPU} PRIVATE -Wall -Wextra -Werror)
+
+set_target_properties(${LIB_NEURUN_BACKEND_HI_PERF_CPU} PROPERTIES OUTPUT_NAME backend_NNPACK)
+install(TARGETS ${LIB_NEURUN_BACKEND_HI_PERF_CPU} DESTINATION lib)
+
+target_link_libraries(${LIB_NEURUN_BACKEND_HI_PERF_CPU} nnpack pthreadpool cpuinfo)
+target_include_directories(${LIB_NEURUN_BACKEND_HI_PERF_CPU} PRIVATE ${NNPACK_INCLUDE_DIRS})
+
+# Unit Tests
+set(TEST_NEURUN_BACKEND_HI_PERF_CPU test_neurun_backend_hi_perf)
+
+add_executable(${TEST_NEURUN_BACKEND_HI_PERF_CPU} ${TESTS})
+target_link_libraries(${TEST_NEURUN_BACKEND_HI_PERF_CPU} ${LIB_NEURUN_BACKEND_HI_PERF_CPU})
+target_link_libraries(${TEST_NEURUN_BACKEND_HI_PERF_CPU} gtest gtest_main ${LIB_PTHREAD})
+add_test(${TEST_NEURUN_BACKEND_HI_PERF_CPU} ${TEST_NEURUN_BACKEND_HI_PERF_CPU})
+target_include_directories(${TEST_NEURUN_BACKEND_HI_PERF_CPU} PRIVATE ${NNPACK_INCLUDE_DIR})
+
+install(TARGETS ${TEST_NEURUN_BACKEND_HI_PERF_CPU} DESTINATION unittest)
diff --git a/runtimes/neurun/backend/hi_perf_cpu/HighPerformanceBackend.test.cc b/runtimes/neurun/backend/hi_perf_cpu/HighPerformanceBackend.test.cc
new file mode 100644 (file)
index 0000000..625fe1c
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2019 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 <gtest/gtest.h>
+
+#include "nnpack.h"
+
+TEST(High_performance_backend, NNPACK_Test)
+{
+  // Check that it is possible to import
+  const enum nnp_status init_status = nnp_initialize();
+
+  // One of the allowed nnp status codes
+  ASSERT_GE(init_status, 0);
+  ASSERT_LE(init_status, 54);
+
+  // If it is possible to test, test relu
+  if (init_status == nnp_status_success)
+  {
+    float in[] = {-1, 1, -1, 1};
+    float out[4];
+    nnp_relu_output(1, 4, in, out, 0, nullptr);
+    for (int i = 0; i < 4; i++)
+    {
+      ASSERT_EQ(out[i], in[i] >= 0 ? in[i] : 0);
+    }
+  }
+  nnp_deinitialize();
+}
diff --git a/runtimes/neurun/backend/hi_perf_cpu/StageGenerator.cc b/runtimes/neurun/backend/hi_perf_cpu/StageGenerator.cc
new file mode 100644 (file)
index 0000000..943c43b
--- /dev/null
@@ -0,0 +1,18 @@
+/*
+ * Copyright (c) 2019 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 "StageGenerator.h"
+// to force compilation
diff --git a/runtimes/neurun/backend/hi_perf_cpu/StageGenerator.h b/runtimes/neurun/backend/hi_perf_cpu/StageGenerator.h
new file mode 100644 (file)
index 0000000..62476dc
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2019 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_STAGEGENERATOR_H
+#define NNFW_STAGEGENERATOR_H
+
+#include <backend/IStageGenerator.h>
+
+#include "model/Operands.h"
+#include "TensorBuilder.h"
+
+namespace neurun
+{
+namespace backend
+{
+namespace hi_perf_cpu
+{
+
+class StageGenerator : public IStageGenerator
+{
+public:
+  StageGenerator(const neurun::model::Operands &ctx,
+                 const std::shared_ptr<TensorBuilder> &tensor_builder);
+  std::shared_ptr<ITensorBuilder> tensor_builder() override;
+  // TODO add more ops
+
+private:
+  const neurun::model::Operands &_ctx;
+  std::shared_ptr<TensorBuilder> _tensor_builder;
+};
+
+} // namespace hi_perf_cpu
+} // namespace backend
+} // namespace neurun
+
+#endif // NNFW_STAGEGENERATOR_H
diff --git a/runtimes/neurun/backend/hi_perf_cpu/TensorBuilder.cc b/runtimes/neurun/backend/hi_perf_cpu/TensorBuilder.cc
new file mode 100644 (file)
index 0000000..e6ebf5f
--- /dev/null
@@ -0,0 +1,18 @@
+/*
+ * Copyright (c) 2019 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 "TensorBuilder.h"
+// to force compilation
diff --git a/runtimes/neurun/backend/hi_perf_cpu/TensorBuilder.h b/runtimes/neurun/backend/hi_perf_cpu/TensorBuilder.h
new file mode 100644 (file)
index 0000000..344d804
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2019 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_TENSORBUILDER_H
+#define NNFW_TENSORBUILDER_H
+
+#include <unordered_map>
+
+#include <backend/ITensorBuilder.h>
+#include <backend/operand/Object.h>
+#include "model/OperandIndexMap.h"
+
+namespace neurun
+{
+namespace backend
+{
+namespace hi_perf_cpu
+{
+
+class TensorBuilder : public ITensorBuilder
+{
+public:
+  TensorBuilder();
+
+private:
+};
+
+} // namespace hi_perf_cpu
+} // namespace backend
+} // namespace neurun
+
+#endif // NNFW_TENSORBUILDER_H
diff --git a/runtimes/neurun/backend/hi_perf_cpu/kernel/CMakeLists.txt b/runtimes/neurun/backend/hi_perf_cpu/kernel/CMakeLists.txt
new file mode 100644 (file)
index 0000000..c643e26
--- /dev/null
@@ -0,0 +1 @@
+return()