blob: cc2a5e31a2e68af52c783ebeb5944c9008953c4b [file] [log] [blame]
Eric Kunzee5e26762020-10-13 16:11:07 -07001cmake_minimum_required (VERSION 3.4)
2
Tai Lya4d748b2023-03-28 22:06:56 +00003# Copyright (c) 2020-2023, ARM Limited.
Eric Kunzee5e26762020-10-13 16:11:07 -07004#
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 Kunzee5e26762020-10-13 16:11:07 -070017project(tosa_reference_model LANGUAGES CXX)
18
19set(CMAKE_CXX_STANDARD 17)
20set(CMAKE_CXX_STANDARD_REQUIRED ON)
21
22if(CMAKE_CXX_COMPILER_ID STREQUAL GNU)
23 set(CMAKE_CXX_FLAGS "-Wall -Wno-ignored-attributes -Wno-format-truncation")
24else()
25 set(CMAKE_CXX_FLAGS "-Wall -Wno-ignored-attributes")
26endif()
27
Matthew Sloyanba5fad32022-09-26 13:31:43 +010028# 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.
30if(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 Kunzee5e26762020-10-13 16:11:07 -070036
Matthew Sloyanba5fad32022-09-26 13:31:43 +010037 if(NOT SERIALIZATION_LIB)
38 message(FATAL_ERROR "TOSA Serialization Library location was specified but not found at: ${SERIALIZATION_LIB_DIR}")
39 endif()
40else()
41 # Build from third party directory if not found.
42 set(SERIALIZATION_LIB tosa_serialization_lib)
43 set(SERIALIZATION_DIR "../thirdparty/serialization_lib/")
44endif()
45
James Ward8b390432022-08-12 20:48:56 +010046# If Flatbuffers, Eigen, Half path isn't specified, set to thirdparty directory.
Matthew Sloyanba5fad32022-09-26 13:31:43 +010047if(NOT FLATBUFFERS_DIR)
48 set(FLATBUFFERS_DIR "../thirdparty/serialization_lib/third_party/flatbuffers/")
49endif()
50
51if(NOT EIGEN_DIR)
52 set(EIGEN_DIR "../thirdparty/eigen/")
53endif()
54
James Ward8b390432022-08-12 20:48:56 +010055if(NOT HALF_DIR)
56 set(HALF_DIR "../thirdparty/serialization_lib/third_party/half")
57endif()
58
Georgios Pinitas7021ef02023-08-22 08:25:57 +010059if(NOT JSON_DIR)
60 set(JSON_DIR "../thirdparty/json")
61endif()
62
Matthew Sloyanba5fad32022-09-26 13:31:43 +010063include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
64
65# Common sources required for TOSA Reference Model library, executable and unit tests
66set(CXX_SOURCE
Matthew Sloyanba5fad32022-09-26 13:31:43 +010067 src/func_debug.cc
Georgios Pinitas41df4282023-05-30 12:20:31 +010068 src/graph_node.cc
69 src/model_runner_impl.cc
70 src/model_runner.cc
Grant Watson64285a12022-11-16 15:32:39 +000071 src/operators.cc
Georgios Pinitas41df4282023-05-30 12:20:31 +010072 src/subgraph_traverser.cc
73 src/tensor.cc
Georgios Pinitas7021ef02023-08-22 08:25:57 +010074 src/verify/verify_dot_product.cc
75 src/verify/verify_entry.cc
Jack Franklandaafc8502023-09-13 11:03:50 +010076 src/verify/verify_exact.cc
Jack Frankland12ee1a72023-09-20 09:08:34 +010077 src/verify/verify_reduce_product.cc
Jack Frankland62737b12023-09-13 15:47:48 +010078 src/verify/verify_ulp.cc
Georgios Pinitas7021ef02023-08-22 08:25:57 +010079 src/verify/verify_utils.cc
Matthew Sloyanba5fad32022-09-26 13:31:43 +010080 src/ops/op_factory.cc
81 src/ops/tensor_ops.cc
82 src/ops/activation_funcs.cc
83 src/ops/ewise_binary.cc
84 src/ops/ewise_unary.cc
85 src/ops/ewise_ternary.cc
86 src/ops/comparison.cc
87 src/ops/reduction.cc
88 src/ops/data_layout.cc
89 src/ops/scatter_gather.cc
90 src/ops/image.cc
91 src/ops/type_conversion.cc
92 src/ops/data_nodes.cc
93 src/ops/custom.cc
94 src/ops/control_flow.cc
Eric Kunzee5e26762020-10-13 16:11:07 -070095)
96
Jeremy Johnson48df8c72023-09-12 14:52:34 +010097set(PUBLIC_INCLUDE_DIRS
Eric Kunzee5e26762020-10-13 16:11:07 -070098 $<INSTALL_INTERFACE:include>
99 $<BUILD_INTERFACE:${CMAKE_CURRENT_SRC_DIR}/include>
Jeremy Johnson48df8c72023-09-12 14:52:34 +0100100)
101set(PRIVATE_INCLUDE_DIRS
Eric Kunzee5e26762020-10-13 16:11:07 -0700102 ${CMAKE_CURRENT_SOURCE_DIR}/src
103 ${FLATBUFFERS_DIR}/include
Matthew Sloyanba5fad32022-09-26 13:31:43 +0100104 ${EIGEN_DIR}
105 ${EIGEN_DIR}/unsupported/
Kevin Cheng550ccc52021-03-03 11:21:43 -0800106 ${SERIALIZATION_DIR}/include
James Ward8b390432022-08-12 20:48:56 +0100107 ${HALF_DIR}/include
Georgios Pinitas7021ef02023-08-22 08:25:57 +0100108 ${JSON_DIR}/single_include
Eric Kunzee5e26762020-10-13 16:11:07 -0700109)
110
Jeremy Johnson48df8c72023-09-12 14:52:34 +0100111# Build TOSA Reference Model library
112add_library(tosa_reference_model_lib STATIC ${CXX_SOURCE})
113
114target_include_directories(tosa_reference_model_lib
115 PUBLIC
116 ${PUBLIC_INCLUDE_DIRS}
117 PRIVATE
118 ${PRIVATE_INCLUDE_DIRS}
119)
120
Matthew Sloyanba5fad32022-09-26 13:31:43 +0100121target_link_libraries(tosa_reference_model_lib
Eric Kunzee5e26762020-10-13 16:11:07 -0700122 PRIVATE
Matthew Sloyanba5fad32022-09-26 13:31:43 +0100123 ${SERIALIZATION_LIB}
Eric Kunzee5e26762020-10-13 16:11:07 -0700124)
125
Matthew Sloyanba5fad32022-09-26 13:31:43 +0100126set(PUBLIC_HEADERS)
127list(APPEND PUBLIC_HEADERS
128 include/debug_modes.def
129 include/debug_types.h
Tai Lya4d748b2023-03-28 22:06:56 +0000130 include/dtype.h
Matthew Sloyanba5fad32022-09-26 13:31:43 +0100131 include/func_config.h
132 include/func_debug.h
133 include/graph_status.h
134 include/model_common.h
135 include/model_runner.h
Georgios Pinitas7021ef02023-08-22 08:25:57 +0100136 include/types.h
Georgios Pinitas41df4282023-05-30 12:20:31 +0100137 include/verify.h
Matthew Sloyanba5fad32022-09-26 13:31:43 +0100138 include/version.h
139)
140
141set_target_properties(tosa_reference_model_lib PROPERTIES PUBLIC_HEADER "${PUBLIC_HEADERS}")
142
Jeremy Johnson48df8c72023-09-12 14:52:34 +0100143# Build TOSA verification library
144add_library(tosa_reference_verify_lib SHARED
145 src/verify/verify_dot_product.cc
146 src/verify/verify_entry.cc
Jack Franklandaafc8502023-09-13 11:03:50 +0100147 src/verify/verify_exact.cc
Jack Frankland12ee1a72023-09-20 09:08:34 +0100148 src/verify/verify_reduce_product.cc
Jack Frankland62737b12023-09-13 15:47:48 +0100149 src/verify/verify_ulp.cc
Jeremy Johnson48df8c72023-09-12 14:52:34 +0100150 src/verify/verify_utils.cc
151 src/verify/verify_config.cc
152 src/func_debug.cc
153)
154target_include_directories(tosa_reference_verify_lib
155 PUBLIC
156 ${PUBLIC_INCLUDE_DIRS}
157 PRIVATE
158 ${PRIVATE_INCLUDE_DIRS}
159)
160
Matthew Sloyanba5fad32022-09-26 13:31:43 +0100161# Build TOSA Refererence Model executable
162if(BUILD_TOSA_REFERENCE_MODEL_EXECUTABLE)
163 set(CXX_SOURCE_EX src/main.cpp)
164 list(APPEND CXX_SOURCE_EX ${CXX_SOURCE})
165
166 add_executable(tosa_reference_model ${CXX_SOURCE_EX})
167
168 target_include_directories(tosa_reference_model
169 PUBLIC
Jeremy Johnson48df8c72023-09-12 14:52:34 +0100170 ${PUBLIC_INCLUDE_DIRS}
Matthew Sloyanba5fad32022-09-26 13:31:43 +0100171 PRIVATE
Jeremy Johnson48df8c72023-09-12 14:52:34 +0100172 ${PRIVATE_INCLUDE_DIRS}
Matthew Sloyanba5fad32022-09-26 13:31:43 +0100173 )
174
175 target_link_libraries(tosa_reference_model
176 PRIVATE
177 ${SERIALIZATION_LIB}
178 nlohmann_json::nlohmann_json
179 cxxopts
180 )
181
182 install(TARGETS tosa_reference_model DESTINATION bin)
183endif()
184
185if(BUILD_TOSA_REFERENCE_MODEL_TESTS)
186 # Set definition so unit tests can find examples directory.
187 add_definitions(-DPROJECT_ROOT=\"${CMAKE_CURRENT_SOURCE_DIR}/\")
188
189 # Set doctest location if not specified.
190 if(NOT DOCTEST_DIR)
191 set(DOCTEST_DIR "../thirdparty/doctest/doctest")
192 endif()
193
194 # Sources only required for unit tests.
195 set(CXX_SOURCE_TESTS
196 test/model_runner_tests.cpp
Georgios Pinitas41df4282023-05-30 12:20:31 +0100197 test/verify_tests.cpp
Matthew Sloyanba5fad32022-09-26 13:31:43 +0100198 ${DOCTEST_DIR}/doctest.h
199 )
200
201 list(APPEND CXX_SOURCE_TESTS ${CXX_SOURCE})
202
203 add_executable(unit_tests ${CXX_SOURCE_TESTS})
204
205 target_include_directories(unit_tests
206 PUBLIC
Jeremy Johnson48df8c72023-09-12 14:52:34 +0100207 ${PUBLIC_INCLUDE_DIRS}
Matthew Sloyanba5fad32022-09-26 13:31:43 +0100208 PRIVATE
Jeremy Johnson48df8c72023-09-12 14:52:34 +0100209 ${PRIVATE_INCLUDE_DIRS}
Matthew Sloyanba5fad32022-09-26 13:31:43 +0100210 ${DOCTEST_DIR}
211 )
212
213 target_link_libraries(unit_tests
214 PRIVATE
215 ${SERIALIZATION_LIB}
216 )
217endif()
218
219if(BUILD_MODEL_RUNNER_SAMPLE)
220 # Set definition so sample executable can find examples directory.
221 add_definitions(-DPROJECT_ROOT=\"${CMAKE_CURRENT_SOURCE_DIR}/\")
222
223 # Sources only required for example executable.
224 set(CXX_SOURCE_SAMPLE
225 samples/model_runner_simple_sample.cpp
226 )
227
228 list(APPEND CXX_SOURCE_SAMPLE ${CXX_SOURCE})
229
230 add_executable(model_runner_sample ${CXX_SOURCE_SAMPLE})
231
232 target_include_directories(model_runner_sample
233 PUBLIC
Jeremy Johnson48df8c72023-09-12 14:52:34 +0100234 ${PUBLIC_INCLUDE_DIRS}
Matthew Sloyanba5fad32022-09-26 13:31:43 +0100235 PRIVATE
Jeremy Johnson48df8c72023-09-12 14:52:34 +0100236 ${PRIVATE_INCLUDE_DIRS}
Matthew Sloyanba5fad32022-09-26 13:31:43 +0100237 )
238
239 target_link_libraries(model_runner_sample
240 PRIVATE
241 ${SERIALIZATION_LIB}
242 )
243endif()
244
245# Follow GNU packaging norms for installation directory structure.
246include(GNUInstallDirs)
247install(
248 TARGETS tosa_reference_model_lib EXPORT TosaReferenceModelLibTargets
249 PUBLIC_HEADER
250 ARCHIVE
251)
252
253install(EXPORT TosaReferenceModelLibTargets
254 FILE TosaReferenceModelLibTargets.cmake
255 NAMESPACE TosaReference::
256 DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/tosa_reference_model_lib"
Jack Franklandaafc8502023-09-13 11:03:50 +0100257)