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 | |
Georgios Pinitas | 7021ef0 | 2023-08-22 08:25:57 +0100 | [diff] [blame] | 59 | if(NOT JSON_DIR) |
| 60 | set(JSON_DIR "../thirdparty/json") |
| 61 | endif() |
| 62 | |
Matthew Sloyan | ba5fad3 | 2022-09-26 13:31:43 +0100 | [diff] [blame] | 63 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include) |
| 64 | |
| 65 | # Common sources required for TOSA Reference Model library, executable and unit tests |
| 66 | set(CXX_SOURCE |
Matthew Sloyan | ba5fad3 | 2022-09-26 13:31:43 +0100 | [diff] [blame] | 67 | src/func_debug.cc |
Georgios Pinitas | 41df428 | 2023-05-30 12:20:31 +0100 | [diff] [blame] | 68 | src/graph_node.cc |
| 69 | src/model_runner_impl.cc |
| 70 | src/model_runner.cc |
Grant Watson | 64285a1 | 2022-11-16 15:32:39 +0000 | [diff] [blame] | 71 | src/operators.cc |
Georgios Pinitas | 41df428 | 2023-05-30 12:20:31 +0100 | [diff] [blame] | 72 | src/subgraph_traverser.cc |
| 73 | src/tensor.cc |
Jeremy Johnson | b20b0c9 | 2023-10-04 14:17:55 +0100 | [diff] [blame] | 74 | src/generate/generate_dot_product_states.cc |
| 75 | src/generate/generate_dot_product.cc |
Jeremy Johnson | d41feb7 | 2023-10-12 16:03:15 +0100 | [diff] [blame^] | 76 | src/generate/generate_pseudo_random.cc |
Jeremy Johnson | b20b0c9 | 2023-10-04 14:17:55 +0100 | [diff] [blame] | 77 | src/generate/generate_entry.cc |
| 78 | src/generate/generate_utils.cc |
Georgios Pinitas | 7021ef0 | 2023-08-22 08:25:57 +0100 | [diff] [blame] | 79 | src/verify/verify_dot_product.cc |
| 80 | src/verify/verify_entry.cc |
Jack Frankland | aafc850 | 2023-09-13 11:03:50 +0100 | [diff] [blame] | 81 | src/verify/verify_exact.cc |
Jack Frankland | 12ee1a7 | 2023-09-20 09:08:34 +0100 | [diff] [blame] | 82 | src/verify/verify_reduce_product.cc |
Jack Frankland | 62737b1 | 2023-09-13 15:47:48 +0100 | [diff] [blame] | 83 | src/verify/verify_ulp.cc |
Georgios Pinitas | 7021ef0 | 2023-08-22 08:25:57 +0100 | [diff] [blame] | 84 | src/verify/verify_utils.cc |
Matthew Sloyan | ba5fad3 | 2022-09-26 13:31:43 +0100 | [diff] [blame] | 85 | src/ops/op_factory.cc |
| 86 | src/ops/tensor_ops.cc |
| 87 | src/ops/activation_funcs.cc |
| 88 | src/ops/ewise_binary.cc |
| 89 | src/ops/ewise_unary.cc |
| 90 | src/ops/ewise_ternary.cc |
| 91 | src/ops/comparison.cc |
| 92 | src/ops/reduction.cc |
| 93 | src/ops/data_layout.cc |
| 94 | src/ops/scatter_gather.cc |
| 95 | src/ops/image.cc |
| 96 | src/ops/type_conversion.cc |
| 97 | src/ops/data_nodes.cc |
| 98 | src/ops/custom.cc |
| 99 | src/ops/control_flow.cc |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 100 | ) |
| 101 | |
Jeremy Johnson | 48df8c7 | 2023-09-12 14:52:34 +0100 | [diff] [blame] | 102 | set(PUBLIC_INCLUDE_DIRS |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 103 | $<INSTALL_INTERFACE:include> |
| 104 | $<BUILD_INTERFACE:${CMAKE_CURRENT_SRC_DIR}/include> |
Jeremy Johnson | 48df8c7 | 2023-09-12 14:52:34 +0100 | [diff] [blame] | 105 | ) |
| 106 | set(PRIVATE_INCLUDE_DIRS |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 107 | ${CMAKE_CURRENT_SOURCE_DIR}/src |
| 108 | ${FLATBUFFERS_DIR}/include |
Matthew Sloyan | ba5fad3 | 2022-09-26 13:31:43 +0100 | [diff] [blame] | 109 | ${EIGEN_DIR} |
| 110 | ${EIGEN_DIR}/unsupported/ |
Kevin Cheng | 550ccc5 | 2021-03-03 11:21:43 -0800 | [diff] [blame] | 111 | ${SERIALIZATION_DIR}/include |
James Ward | 8b39043 | 2022-08-12 20:48:56 +0100 | [diff] [blame] | 112 | ${HALF_DIR}/include |
Georgios Pinitas | 7021ef0 | 2023-08-22 08:25:57 +0100 | [diff] [blame] | 113 | ${JSON_DIR}/single_include |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 114 | ) |
| 115 | |
Jeremy Johnson | 48df8c7 | 2023-09-12 14:52:34 +0100 | [diff] [blame] | 116 | # Build TOSA Reference Model library |
| 117 | add_library(tosa_reference_model_lib STATIC ${CXX_SOURCE}) |
| 118 | |
| 119 | target_include_directories(tosa_reference_model_lib |
| 120 | PUBLIC |
| 121 | ${PUBLIC_INCLUDE_DIRS} |
| 122 | PRIVATE |
| 123 | ${PRIVATE_INCLUDE_DIRS} |
| 124 | ) |
| 125 | |
Matthew Sloyan | ba5fad3 | 2022-09-26 13:31:43 +0100 | [diff] [blame] | 126 | target_link_libraries(tosa_reference_model_lib |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 127 | PRIVATE |
Matthew Sloyan | ba5fad3 | 2022-09-26 13:31:43 +0100 | [diff] [blame] | 128 | ${SERIALIZATION_LIB} |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 129 | ) |
| 130 | |
Matthew Sloyan | ba5fad3 | 2022-09-26 13:31:43 +0100 | [diff] [blame] | 131 | set(PUBLIC_HEADERS) |
| 132 | list(APPEND PUBLIC_HEADERS |
| 133 | include/debug_modes.def |
| 134 | include/debug_types.h |
Tai Ly | a4d748b | 2023-03-28 22:06:56 +0000 | [diff] [blame] | 135 | include/dtype.h |
Matthew Sloyan | ba5fad3 | 2022-09-26 13:31:43 +0100 | [diff] [blame] | 136 | include/func_config.h |
| 137 | include/func_debug.h |
Jeremy Johnson | b20b0c9 | 2023-10-04 14:17:55 +0100 | [diff] [blame] | 138 | include/generate.h |
Matthew Sloyan | ba5fad3 | 2022-09-26 13:31:43 +0100 | [diff] [blame] | 139 | include/graph_status.h |
| 140 | include/model_common.h |
| 141 | include/model_runner.h |
Georgios Pinitas | 7021ef0 | 2023-08-22 08:25:57 +0100 | [diff] [blame] | 142 | include/types.h |
Georgios Pinitas | 41df428 | 2023-05-30 12:20:31 +0100 | [diff] [blame] | 143 | include/verify.h |
Matthew Sloyan | ba5fad3 | 2022-09-26 13:31:43 +0100 | [diff] [blame] | 144 | include/version.h |
| 145 | ) |
| 146 | |
| 147 | set_target_properties(tosa_reference_model_lib PROPERTIES PUBLIC_HEADER "${PUBLIC_HEADERS}") |
| 148 | |
Jeremy Johnson | 48df8c7 | 2023-09-12 14:52:34 +0100 | [diff] [blame] | 149 | # Build TOSA verification library |
| 150 | add_library(tosa_reference_verify_lib SHARED |
| 151 | src/verify/verify_dot_product.cc |
| 152 | src/verify/verify_entry.cc |
Jack Frankland | aafc850 | 2023-09-13 11:03:50 +0100 | [diff] [blame] | 153 | src/verify/verify_exact.cc |
Jack Frankland | 12ee1a7 | 2023-09-20 09:08:34 +0100 | [diff] [blame] | 154 | src/verify/verify_reduce_product.cc |
Jack Frankland | 62737b1 | 2023-09-13 15:47:48 +0100 | [diff] [blame] | 155 | src/verify/verify_ulp.cc |
Jeremy Johnson | 48df8c7 | 2023-09-12 14:52:34 +0100 | [diff] [blame] | 156 | src/verify/verify_utils.cc |
| 157 | src/verify/verify_config.cc |
| 158 | src/func_debug.cc |
| 159 | ) |
| 160 | target_include_directories(tosa_reference_verify_lib |
| 161 | PUBLIC |
| 162 | ${PUBLIC_INCLUDE_DIRS} |
| 163 | PRIVATE |
| 164 | ${PRIVATE_INCLUDE_DIRS} |
| 165 | ) |
| 166 | |
Jeremy Johnson | b20b0c9 | 2023-10-04 14:17:55 +0100 | [diff] [blame] | 167 | # Build TOSA generator library |
| 168 | add_library(tosa_reference_generate_lib SHARED |
| 169 | src/generate/generate_dot_product_states.cc |
| 170 | src/generate/generate_dot_product.cc |
Jeremy Johnson | d41feb7 | 2023-10-12 16:03:15 +0100 | [diff] [blame^] | 171 | src/generate/generate_pseudo_random.cc |
Jeremy Johnson | b20b0c9 | 2023-10-04 14:17:55 +0100 | [diff] [blame] | 172 | src/generate/generate_entry.cc |
| 173 | src/generate/generate_utils.cc |
Jeremy Johnson | 65ba809 | 2023-10-09 16:31:13 +0100 | [diff] [blame] | 174 | src/generate/generate_config.cc |
Jeremy Johnson | b20b0c9 | 2023-10-04 14:17:55 +0100 | [diff] [blame] | 175 | src/func_debug.cc |
| 176 | ) |
| 177 | target_include_directories(tosa_reference_generate_lib |
| 178 | PUBLIC |
| 179 | ${PUBLIC_INCLUDE_DIRS} |
| 180 | PRIVATE |
| 181 | ${PRIVATE_INCLUDE_DIRS} |
| 182 | ) |
| 183 | |
Matthew Sloyan | ba5fad3 | 2022-09-26 13:31:43 +0100 | [diff] [blame] | 184 | # Build TOSA Refererence Model executable |
| 185 | if(BUILD_TOSA_REFERENCE_MODEL_EXECUTABLE) |
| 186 | set(CXX_SOURCE_EX src/main.cpp) |
| 187 | list(APPEND CXX_SOURCE_EX ${CXX_SOURCE}) |
| 188 | |
| 189 | add_executable(tosa_reference_model ${CXX_SOURCE_EX}) |
| 190 | |
| 191 | target_include_directories(tosa_reference_model |
| 192 | PUBLIC |
Jeremy Johnson | 48df8c7 | 2023-09-12 14:52:34 +0100 | [diff] [blame] | 193 | ${PUBLIC_INCLUDE_DIRS} |
Matthew Sloyan | ba5fad3 | 2022-09-26 13:31:43 +0100 | [diff] [blame] | 194 | PRIVATE |
Jeremy Johnson | 48df8c7 | 2023-09-12 14:52:34 +0100 | [diff] [blame] | 195 | ${PRIVATE_INCLUDE_DIRS} |
Matthew Sloyan | ba5fad3 | 2022-09-26 13:31:43 +0100 | [diff] [blame] | 196 | ) |
| 197 | |
| 198 | target_link_libraries(tosa_reference_model |
| 199 | PRIVATE |
| 200 | ${SERIALIZATION_LIB} |
| 201 | nlohmann_json::nlohmann_json |
| 202 | cxxopts |
| 203 | ) |
| 204 | |
| 205 | install(TARGETS tosa_reference_model DESTINATION bin) |
| 206 | endif() |
| 207 | |
| 208 | if(BUILD_TOSA_REFERENCE_MODEL_TESTS) |
| 209 | # Set definition so unit tests can find examples directory. |
| 210 | add_definitions(-DPROJECT_ROOT=\"${CMAKE_CURRENT_SOURCE_DIR}/\") |
| 211 | |
| 212 | # Set doctest location if not specified. |
| 213 | if(NOT DOCTEST_DIR) |
| 214 | set(DOCTEST_DIR "../thirdparty/doctest/doctest") |
| 215 | endif() |
| 216 | |
| 217 | # Sources only required for unit tests. |
| 218 | set(CXX_SOURCE_TESTS |
Jeremy Johnson | b20b0c9 | 2023-10-04 14:17:55 +0100 | [diff] [blame] | 219 | test/generate_tests.cpp |
Matthew Sloyan | ba5fad3 | 2022-09-26 13:31:43 +0100 | [diff] [blame] | 220 | test/model_runner_tests.cpp |
Georgios Pinitas | 41df428 | 2023-05-30 12:20:31 +0100 | [diff] [blame] | 221 | test/verify_tests.cpp |
Matthew Sloyan | ba5fad3 | 2022-09-26 13:31:43 +0100 | [diff] [blame] | 222 | ${DOCTEST_DIR}/doctest.h |
| 223 | ) |
| 224 | |
| 225 | list(APPEND CXX_SOURCE_TESTS ${CXX_SOURCE}) |
| 226 | |
| 227 | add_executable(unit_tests ${CXX_SOURCE_TESTS}) |
| 228 | |
| 229 | target_include_directories(unit_tests |
| 230 | PUBLIC |
Jeremy Johnson | 48df8c7 | 2023-09-12 14:52:34 +0100 | [diff] [blame] | 231 | ${PUBLIC_INCLUDE_DIRS} |
Matthew Sloyan | ba5fad3 | 2022-09-26 13:31:43 +0100 | [diff] [blame] | 232 | PRIVATE |
Jeremy Johnson | 48df8c7 | 2023-09-12 14:52:34 +0100 | [diff] [blame] | 233 | ${PRIVATE_INCLUDE_DIRS} |
Matthew Sloyan | ba5fad3 | 2022-09-26 13:31:43 +0100 | [diff] [blame] | 234 | ${DOCTEST_DIR} |
| 235 | ) |
| 236 | |
| 237 | target_link_libraries(unit_tests |
| 238 | PRIVATE |
| 239 | ${SERIALIZATION_LIB} |
| 240 | ) |
| 241 | endif() |
| 242 | |
| 243 | if(BUILD_MODEL_RUNNER_SAMPLE) |
| 244 | # Set definition so sample executable can find examples directory. |
| 245 | add_definitions(-DPROJECT_ROOT=\"${CMAKE_CURRENT_SOURCE_DIR}/\") |
| 246 | |
| 247 | # Sources only required for example executable. |
| 248 | set(CXX_SOURCE_SAMPLE |
| 249 | samples/model_runner_simple_sample.cpp |
| 250 | ) |
| 251 | |
| 252 | list(APPEND CXX_SOURCE_SAMPLE ${CXX_SOURCE}) |
| 253 | |
| 254 | add_executable(model_runner_sample ${CXX_SOURCE_SAMPLE}) |
| 255 | |
| 256 | target_include_directories(model_runner_sample |
| 257 | PUBLIC |
Jeremy Johnson | 48df8c7 | 2023-09-12 14:52:34 +0100 | [diff] [blame] | 258 | ${PUBLIC_INCLUDE_DIRS} |
Matthew Sloyan | ba5fad3 | 2022-09-26 13:31:43 +0100 | [diff] [blame] | 259 | PRIVATE |
Jeremy Johnson | 48df8c7 | 2023-09-12 14:52:34 +0100 | [diff] [blame] | 260 | ${PRIVATE_INCLUDE_DIRS} |
Matthew Sloyan | ba5fad3 | 2022-09-26 13:31:43 +0100 | [diff] [blame] | 261 | ) |
| 262 | |
| 263 | target_link_libraries(model_runner_sample |
| 264 | PRIVATE |
| 265 | ${SERIALIZATION_LIB} |
| 266 | ) |
| 267 | endif() |
| 268 | |
| 269 | # Follow GNU packaging norms for installation directory structure. |
| 270 | include(GNUInstallDirs) |
| 271 | install( |
| 272 | TARGETS tosa_reference_model_lib EXPORT TosaReferenceModelLibTargets |
| 273 | PUBLIC_HEADER |
| 274 | ARCHIVE |
| 275 | ) |
| 276 | |
| 277 | install(EXPORT TosaReferenceModelLibTargets |
| 278 | FILE TosaReferenceModelLibTargets.cmake |
| 279 | NAMESPACE TosaReference:: |
| 280 | DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/tosa_reference_model_lib" |
Jack Frankland | aafc850 | 2023-09-13 11:03:50 +0100 | [diff] [blame] | 281 | ) |