Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 1 | cmake_minimum_required (VERSION 3.4) |
| 2 | |
Tai Ly | a4d748b | 2023-03-28 22:06:56 +0000 | [diff] [blame] | 3 | # Copyright (c) 2020-2023, ARM Limited. |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 17 | project(tosa_reference_model LANGUAGES CXX) |
| 18 | |
| 19 | set(CMAKE_CXX_STANDARD 17) |
| 20 | set(CMAKE_CXX_STANDARD_REQUIRED ON) |
| 21 | |
| 22 | if(CMAKE_CXX_COMPILER_ID STREQUAL GNU) |
| 23 | set(CMAKE_CXX_FLAGS "-Wall -Wno-ignored-attributes -Wno-format-truncation") |
| 24 | else() |
| 25 | set(CMAKE_CXX_FLAGS "-Wall -Wno-ignored-attributes") |
| 26 | endif() |
| 27 | |
Matthew Sloyan | ba5fad3 | 2022-09-26 13:31:43 +0100 | [diff] [blame] | 28 | # If Serialization Library path is specified, look for library so it doesn't have to be built again. |
| 29 | # Otherwise, set the Serialization Library related paths to thirdparty directory. |
| 30 | if(SERIALIZATION_DIR) |
| 31 | find_library(SERIALIZATION_LIB |
| 32 | NAMES libtosa_serialization_lib.a tosa_serialization_lib |
| 33 | NO_DEFAULT_PATH |
| 34 | HINTS ${SERIALIZATION_DIR} |
| 35 | PATH_SUFFIXES lib) |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 36 | |
Matthew Sloyan | ba5fad3 | 2022-09-26 13:31:43 +0100 | [diff] [blame] | 37 | if(NOT SERIALIZATION_LIB) |
| 38 | message(FATAL_ERROR "TOSA Serialization Library location was specified but not found at: ${SERIALIZATION_LIB_DIR}") |
| 39 | endif() |
| 40 | else() |
| 41 | # Build from third party directory if not found. |
| 42 | set(SERIALIZATION_LIB tosa_serialization_lib) |
| 43 | set(SERIALIZATION_DIR "../thirdparty/serialization_lib/") |
| 44 | endif() |
| 45 | |
James Ward | 8b39043 | 2022-08-12 20:48:56 +0100 | [diff] [blame] | 46 | # If Flatbuffers, Eigen, Half path isn't specified, set to thirdparty directory. |
Matthew Sloyan | ba5fad3 | 2022-09-26 13:31:43 +0100 | [diff] [blame] | 47 | if(NOT FLATBUFFERS_DIR) |
| 48 | set(FLATBUFFERS_DIR "../thirdparty/serialization_lib/third_party/flatbuffers/") |
| 49 | endif() |
| 50 | |
| 51 | if(NOT EIGEN_DIR) |
| 52 | set(EIGEN_DIR "../thirdparty/eigen/") |
| 53 | endif() |
| 54 | |
James Ward | 8b39043 | 2022-08-12 20:48:56 +0100 | [diff] [blame] | 55 | if(NOT HALF_DIR) |
| 56 | set(HALF_DIR "../thirdparty/serialization_lib/third_party/half") |
| 57 | endif() |
| 58 | |
Matthew Sloyan | ba5fad3 | 2022-09-26 13:31:43 +0100 | [diff] [blame] | 59 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include) |
| 60 | |
| 61 | # Common sources required for TOSA Reference Model library, executable and unit tests |
| 62 | set(CXX_SOURCE |
| 63 | src/model_runner.cc |
| 64 | src/model_runner_impl.cc |
| 65 | src/tensor.cc |
| 66 | src/graph_node.cc |
| 67 | src/subgraph_traverser.cc |
| 68 | src/func_debug.cc |
Grant Watson | 64285a1 | 2022-11-16 15:32:39 +0000 | [diff] [blame] | 69 | src/operators.cc |
Matthew Sloyan | ba5fad3 | 2022-09-26 13:31:43 +0100 | [diff] [blame] | 70 | src/ops/op_factory.cc |
| 71 | src/ops/tensor_ops.cc |
| 72 | src/ops/activation_funcs.cc |
| 73 | src/ops/ewise_binary.cc |
| 74 | src/ops/ewise_unary.cc |
| 75 | src/ops/ewise_ternary.cc |
| 76 | src/ops/comparison.cc |
| 77 | src/ops/reduction.cc |
| 78 | src/ops/data_layout.cc |
| 79 | src/ops/scatter_gather.cc |
| 80 | src/ops/image.cc |
| 81 | src/ops/type_conversion.cc |
| 82 | src/ops/data_nodes.cc |
| 83 | src/ops/custom.cc |
| 84 | src/ops/control_flow.cc |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 85 | ) |
| 86 | |
Matthew Sloyan | ba5fad3 | 2022-09-26 13:31:43 +0100 | [diff] [blame] | 87 | # Build TOSA Reference Model library |
| 88 | add_library(tosa_reference_model_lib ${CXX_SOURCE}) |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 89 | |
Matthew Sloyan | ba5fad3 | 2022-09-26 13:31:43 +0100 | [diff] [blame] | 90 | target_include_directories(tosa_reference_model_lib |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 91 | PUBLIC |
| 92 | $<INSTALL_INTERFACE:include> |
| 93 | $<BUILD_INTERFACE:${CMAKE_CURRENT_SRC_DIR}/include> |
| 94 | PRIVATE |
| 95 | ${CMAKE_CURRENT_SOURCE_DIR}/src |
| 96 | ${FLATBUFFERS_DIR}/include |
Matthew Sloyan | ba5fad3 | 2022-09-26 13:31:43 +0100 | [diff] [blame] | 97 | ${EIGEN_DIR} |
| 98 | ${EIGEN_DIR}/unsupported/ |
Kevin Cheng | 550ccc5 | 2021-03-03 11:21:43 -0800 | [diff] [blame] | 99 | ${SERIALIZATION_DIR}/include |
James Ward | 8b39043 | 2022-08-12 20:48:56 +0100 | [diff] [blame] | 100 | ${HALF_DIR}/include |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 101 | ) |
| 102 | |
Matthew Sloyan | ba5fad3 | 2022-09-26 13:31:43 +0100 | [diff] [blame] | 103 | target_link_libraries(tosa_reference_model_lib |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 104 | PRIVATE |
Matthew Sloyan | ba5fad3 | 2022-09-26 13:31:43 +0100 | [diff] [blame] | 105 | ${SERIALIZATION_LIB} |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 106 | ) |
| 107 | |
Matthew Sloyan | ba5fad3 | 2022-09-26 13:31:43 +0100 | [diff] [blame] | 108 | set(PUBLIC_HEADERS) |
| 109 | list(APPEND PUBLIC_HEADERS |
| 110 | include/debug_modes.def |
| 111 | include/debug_types.h |
Tai Ly | a4d748b | 2023-03-28 22:06:56 +0000 | [diff] [blame] | 112 | include/dtype.h |
Matthew Sloyan | ba5fad3 | 2022-09-26 13:31:43 +0100 | [diff] [blame] | 113 | include/func_config.h |
| 114 | include/func_debug.h |
| 115 | include/graph_status.h |
| 116 | include/model_common.h |
| 117 | include/model_runner.h |
| 118 | include/version.h |
| 119 | ) |
| 120 | |
| 121 | set_target_properties(tosa_reference_model_lib PROPERTIES PUBLIC_HEADER "${PUBLIC_HEADERS}") |
| 122 | |
| 123 | # Build TOSA Refererence Model executable |
| 124 | if(BUILD_TOSA_REFERENCE_MODEL_EXECUTABLE) |
| 125 | set(CXX_SOURCE_EX src/main.cpp) |
| 126 | list(APPEND CXX_SOURCE_EX ${CXX_SOURCE}) |
| 127 | |
| 128 | add_executable(tosa_reference_model ${CXX_SOURCE_EX}) |
| 129 | |
| 130 | target_include_directories(tosa_reference_model |
| 131 | PUBLIC |
| 132 | $<INSTALL_INTERFACE:include> |
| 133 | $<BUILD_INTERFACE:${CMAKE_CURRENT_SRC_DIR}/include> |
| 134 | PRIVATE |
| 135 | ${CMAKE_CURRENT_SOURCE_DIR}/src |
| 136 | ${FLATBUFFERS_DIR}/include |
| 137 | ${EIGEN_DIR} |
| 138 | ${EIGEN_DIR}/unsupported/ |
| 139 | ${SERIALIZATION_DIR}/include |
James Ward | 8b39043 | 2022-08-12 20:48:56 +0100 | [diff] [blame] | 140 | ${HALF_DIR}/include |
Matthew Sloyan | ba5fad3 | 2022-09-26 13:31:43 +0100 | [diff] [blame] | 141 | ) |
| 142 | |
| 143 | target_link_libraries(tosa_reference_model |
| 144 | PRIVATE |
| 145 | ${SERIALIZATION_LIB} |
| 146 | nlohmann_json::nlohmann_json |
| 147 | cxxopts |
| 148 | ) |
| 149 | |
| 150 | install(TARGETS tosa_reference_model DESTINATION bin) |
| 151 | endif() |
| 152 | |
| 153 | if(BUILD_TOSA_REFERENCE_MODEL_TESTS) |
| 154 | # Set definition so unit tests can find examples directory. |
| 155 | add_definitions(-DPROJECT_ROOT=\"${CMAKE_CURRENT_SOURCE_DIR}/\") |
| 156 | |
| 157 | # Set doctest location if not specified. |
| 158 | if(NOT DOCTEST_DIR) |
| 159 | set(DOCTEST_DIR "../thirdparty/doctest/doctest") |
| 160 | endif() |
| 161 | |
| 162 | # Sources only required for unit tests. |
| 163 | set(CXX_SOURCE_TESTS |
| 164 | test/model_runner_tests.cpp |
| 165 | ${DOCTEST_DIR}/doctest.h |
| 166 | ) |
| 167 | |
| 168 | list(APPEND CXX_SOURCE_TESTS ${CXX_SOURCE}) |
| 169 | |
| 170 | add_executable(unit_tests ${CXX_SOURCE_TESTS}) |
| 171 | |
| 172 | target_include_directories(unit_tests |
| 173 | PUBLIC |
| 174 | $<INSTALL_INTERFACE:include> |
| 175 | $<BUILD_INTERFACE:${CMAKE_CURRENT_SRC_DIR}/include> |
| 176 | PRIVATE |
| 177 | ${CMAKE_CURRENT_SOURCE_DIR}/src |
| 178 | ${FLATBUFFERS_DIR}/include |
| 179 | ${EIGEN_DIR} |
| 180 | ${EIGEN_DIR}/unsupported/ |
| 181 | ${SERIALIZATION_DIR}/include |
James Ward | 8b39043 | 2022-08-12 20:48:56 +0100 | [diff] [blame] | 182 | ${HALF_DIR}/include |
Matthew Sloyan | ba5fad3 | 2022-09-26 13:31:43 +0100 | [diff] [blame] | 183 | ${DOCTEST_DIR} |
| 184 | ) |
| 185 | |
| 186 | target_link_libraries(unit_tests |
| 187 | PRIVATE |
| 188 | ${SERIALIZATION_LIB} |
| 189 | ) |
| 190 | endif() |
| 191 | |
| 192 | if(BUILD_MODEL_RUNNER_SAMPLE) |
| 193 | # Set definition so sample executable can find examples directory. |
| 194 | add_definitions(-DPROJECT_ROOT=\"${CMAKE_CURRENT_SOURCE_DIR}/\") |
| 195 | |
| 196 | # Sources only required for example executable. |
| 197 | set(CXX_SOURCE_SAMPLE |
| 198 | samples/model_runner_simple_sample.cpp |
| 199 | ) |
| 200 | |
| 201 | list(APPEND CXX_SOURCE_SAMPLE ${CXX_SOURCE}) |
| 202 | |
| 203 | add_executable(model_runner_sample ${CXX_SOURCE_SAMPLE}) |
| 204 | |
| 205 | target_include_directories(model_runner_sample |
| 206 | PUBLIC |
| 207 | $<INSTALL_INTERFACE:include> |
| 208 | $<BUILD_INTERFACE:${CMAKE_CURRENT_SRC_DIR}/include> |
| 209 | PRIVATE |
| 210 | ${CMAKE_CURRENT_SOURCE_DIR}/src |
| 211 | ${FLATBUFFERS_DIR}/include |
| 212 | ${EIGEN_DIR} |
| 213 | ${EIGEN_DIR}/unsupported/ |
| 214 | ${SERIALIZATION_DIR}/include |
James Ward | 8b39043 | 2022-08-12 20:48:56 +0100 | [diff] [blame] | 215 | ${HALF_DIR}/include |
Matthew Sloyan | ba5fad3 | 2022-09-26 13:31:43 +0100 | [diff] [blame] | 216 | ) |
| 217 | |
| 218 | target_link_libraries(model_runner_sample |
| 219 | PRIVATE |
| 220 | ${SERIALIZATION_LIB} |
| 221 | ) |
| 222 | endif() |
| 223 | |
| 224 | # Follow GNU packaging norms for installation directory structure. |
| 225 | include(GNUInstallDirs) |
| 226 | install( |
| 227 | TARGETS tosa_reference_model_lib EXPORT TosaReferenceModelLibTargets |
| 228 | PUBLIC_HEADER |
| 229 | ARCHIVE |
| 230 | ) |
| 231 | |
| 232 | install(EXPORT TosaReferenceModelLibTargets |
| 233 | FILE TosaReferenceModelLibTargets.cmake |
| 234 | NAMESPACE TosaReference:: |
| 235 | DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/tosa_reference_model_lib" |
| 236 | ) |