IVGCVSW-7273 Integrate TOSA Reference Model into Arm NN

Signed-off-by: Matthew Sloyan <matthew.sloyan@arm.com>
Change-Id: Ie9aa1aa20a5bc837e005a7a36d4d07b4cd8d021b
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 96f94be..ff05fb3 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -541,6 +541,17 @@
 
         target_link_libraries(armnn PUBLIC -Wl,--whole-archive ${TOSA_SERIALIZATION_LIB} -Wl,--no-whole-archive)
     endif()
+
+    if (TOSA_REFERENCE_MODEL_LIB)
+        target_link_libraries(armnn PUBLIC -Wl,--whole-archive ${TOSA_REFERENCE_MODEL_LIB} -Wl,--no-whole-archive)
+    else()
+        find_library(TOSA_REFERENCE_MODEL_LIB
+            NAMES libtosa_reference_model_lib.a tosa_reference_model_lib
+            HINTS ${TOSA_REFERENCE_MODEL_ROOT}/lib /usr/local/lib /usr/lib)
+        message(STATUS "TOSA Reference Model set to ${TOSA_REFERENCE_MODEL_LIB}")
+
+        target_link_libraries(armnn PUBLIC -Wl,--whole-archive ${TOSA_REFERENCE_MODEL_LIB} -Wl,--no-whole-archive)
+    endif()
 endif()
 
 if(PROFILING_BACKEND_STREAMLINE AND (NOT ("${CMAKE_SYSTEM_NAME}" STREQUAL Android)))
diff --git a/cmake/GlobalConfig.cmake b/cmake/GlobalConfig.cmake
index 9137fa3..fb70d1a 100644
--- a/cmake/GlobalConfig.cmake
+++ b/cmake/GlobalConfig.cmake
@@ -11,7 +11,7 @@
 option(ARMCOMPUTENEON "Build with ARM Compute NEON support" OFF)
 option(ARMCOMPUTECL "Build with ARM Compute OpenCL support" OFF)
 option(ARMNNREF "Build with ArmNN reference support" ON)
-option(ARMNNTOSAREF "Build with Tosa reference support" OFF)
+option(ARMNNTOSAREF "Build with TOSA reference support" OFF)
 option(PROFILING_BACKEND_STREAMLINE "Forward the armNN profiling events to DS-5/Streamline as annotations" OFF)
 # options used for heap profiling and leak checking
 option(HEAP_PROFILING "Build with heap profiling enabled" OFF)
@@ -24,7 +24,8 @@
 option(FLATC_DIR "Path to Flatbuffers compiler" OFF)
 option(TF_LITE_GENERATED_PATH "Tensorflow lite generated C++ schema location" OFF)
 option(FLATBUFFERS_ROOT "Location where the flatbuffers 'include' and 'lib' folders to be found" Off)
-option(TOSA_SERIALIZATION_LIB_ROOT "Location where the TOSA serialization library 'include' and 'lib' folders can be found" OFF)
+option(TOSA_SERIALIZATION_LIB_ROOT "Location where the TOSA Serialization Library 'include' and 'lib' folders can be found" OFF)
+option(TOSA_REFERENCE_MODEL_ROOT "Location where the TOSA Reference Model 'include' and 'lib' folders can be found" OFF)
 option(DYNAMIC_BACKEND_PATHS "Colon seperated list of paths where to load the dynamic backends from" "")
 option(SAMPLE_DYNAMIC_BACKEND "Include the sample dynamic backend and its tests in the build" OFF)
 option(BUILD_GATORD_MOCK "Build the Gatord simulator for external profiling testing." ON)
@@ -341,14 +342,26 @@
     # Locate the includes for the TOSA serialization library.
     message(STATUS "TOSA serialization library root set to ${TOSA_SERIALIZATION_LIB_ROOT}")
 
-    find_path(TOSA_SERIALIZATION_LIB_INCLUDE tosa_serialization_handler.h HINTS
-            ${TOSA_SERIALIZATION_LIB_ROOT}/include)
+    find_path(TOSA_SERIALIZATION_LIB_INCLUDE tosa_serialization_handler.h
+              HINTS ${TOSA_SERIALIZATION_LIB_ROOT}/include)
     message(STATUS "TOSA serialization library include directory located at: ${TOSA_SERIALIZATION_LIB_INCLUDE}")
 
     find_library(TOSA_SERIALIZATION_LIB
-            NAMES tosa_serialization_lib.a tosa_serialization_lib
-            HINTS ${TOSA_SERIALIZATION_LIB_ROOT}/lib /usr/local/lib /usr/lib)
+                 NAMES tosa_serialization_lib.a tosa_serialization_lib
+                 HINTS ${TOSA_SERIALIZATION_LIB_ROOT}/lib /usr/local/lib /usr/lib)
     message(STATUS "TOSA serialization library set to ${TOSA_SERIALIZATION_LIB}")
+
+    # Next, locate the includes for the TOSA Reference Model.
+    message(STATUS "TOSA Reference Model root set to ${TOSA_REFERENCE_MODEL_ROOT}")
+
+    find_path(TOSA_REFERENCE_MODEL_INCLUDE model_runner.h
+              HINTS ${TOSA_REFERENCE_MODEL_ROOT}/include)
+    message(STATUS "TOSA Reference Model include directory located at: ${TOSA_REFERENCE_MODEL_INCLUDE}")
+
+    find_library(TOSA_REFERENCE_MODEL_LIB
+                 NAMES tosa_reference_model_lib.a tosa_reference_model_lib
+                 HINTS ${TOSA_REFERENCE_MODEL_ROOT}/lib /usr/local/lib /usr/lib)
+    message(STATUS "TOSA Reference Model set to ${TOSA_REFERENCE_MODEL_LIB}")
 endif()
 
 # This is the root for the dynamic backend tests to search for dynamic
diff --git a/src/backends/tosaReference/CMakeLists.txt b/src/backends/tosaReference/CMakeLists.txt
index d1f9040..fdec6d1 100644
--- a/src/backends/tosaReference/CMakeLists.txt
+++ b/src/backends/tosaReference/CMakeLists.txt
@@ -5,6 +5,7 @@
 
 include_directories(SYSTEM ${FLATBUFFERS_INCLUDE_PATH})
 include_directories(SYSTEM ${TOSA_SERIALIZATION_LIB_INCLUDE})
+include_directories(SYSTEM ${TOSA_REFERENCE_MODEL_INCLUDE})
 
 if(ARMNNTOSAREF)
     list(APPEND armnnTosaRefBackend_sources