blob: a79096862beaee644943e60c0b8830e2ff4f5004 [file] [log] [blame]
Eric Kunzee5e26762020-10-13 16:11:07 -07001cmake_minimum_required (VERSION 3.4)
2
Matthew Sloyanba5fad32022-09-26 13:31:43 +01003# Copyright (c) 2020-2022, 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
46# If Flatbuffers or Eigen path isn't specified, set to thirdparty directory.
47if(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
55include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
56
57# Common sources required for TOSA Reference Model library, executable and unit tests
58set(CXX_SOURCE
59 src/model_runner.cc
60 src/model_runner_impl.cc
61 src/tensor.cc
62 src/graph_node.cc
63 src/subgraph_traverser.cc
64 src/func_debug.cc
65 src/ops/op_factory.cc
66 src/ops/tensor_ops.cc
67 src/ops/activation_funcs.cc
68 src/ops/ewise_binary.cc
69 src/ops/ewise_unary.cc
70 src/ops/ewise_ternary.cc
71 src/ops/comparison.cc
72 src/ops/reduction.cc
73 src/ops/data_layout.cc
74 src/ops/scatter_gather.cc
75 src/ops/image.cc
76 src/ops/type_conversion.cc
77 src/ops/data_nodes.cc
78 src/ops/custom.cc
79 src/ops/control_flow.cc
Eric Kunzee5e26762020-10-13 16:11:07 -070080)
81
Matthew Sloyanba5fad32022-09-26 13:31:43 +010082# Build TOSA Reference Model library
83add_library(tosa_reference_model_lib ${CXX_SOURCE})
Eric Kunzee5e26762020-10-13 16:11:07 -070084
Matthew Sloyanba5fad32022-09-26 13:31:43 +010085target_include_directories(tosa_reference_model_lib
Eric Kunzee5e26762020-10-13 16:11:07 -070086 PUBLIC
87 $<INSTALL_INTERFACE:include>
88 $<BUILD_INTERFACE:${CMAKE_CURRENT_SRC_DIR}/include>
89 PRIVATE
90 ${CMAKE_CURRENT_SOURCE_DIR}/src
91 ${FLATBUFFERS_DIR}/include
Matthew Sloyanba5fad32022-09-26 13:31:43 +010092 ${EIGEN_DIR}
93 ${EIGEN_DIR}/unsupported/
Kevin Cheng550ccc52021-03-03 11:21:43 -080094 ${SERIALIZATION_DIR}/include
Eric Kunzee5e26762020-10-13 16:11:07 -070095)
96
Matthew Sloyanba5fad32022-09-26 13:31:43 +010097target_link_libraries(tosa_reference_model_lib
Eric Kunzee5e26762020-10-13 16:11:07 -070098 PRIVATE
Matthew Sloyanba5fad32022-09-26 13:31:43 +010099 ${SERIALIZATION_LIB}
Eric Kunzee5e26762020-10-13 16:11:07 -0700100)
101
Matthew Sloyanba5fad32022-09-26 13:31:43 +0100102set(PUBLIC_HEADERS)
103list(APPEND PUBLIC_HEADERS
104 include/debug_modes.def
105 include/debug_types.h
106 include/func_config.h
107 include/func_debug.h
108 include/graph_status.h
109 include/model_common.h
110 include/model_runner.h
111 include/version.h
112)
113
114set_target_properties(tosa_reference_model_lib PROPERTIES PUBLIC_HEADER "${PUBLIC_HEADERS}")
115
116# Build TOSA Refererence Model executable
117if(BUILD_TOSA_REFERENCE_MODEL_EXECUTABLE)
118 set(CXX_SOURCE_EX src/main.cpp)
119 list(APPEND CXX_SOURCE_EX ${CXX_SOURCE})
120
121 add_executable(tosa_reference_model ${CXX_SOURCE_EX})
122
123 target_include_directories(tosa_reference_model
124 PUBLIC
125 $<INSTALL_INTERFACE:include>
126 $<BUILD_INTERFACE:${CMAKE_CURRENT_SRC_DIR}/include>
127 PRIVATE
128 ${CMAKE_CURRENT_SOURCE_DIR}/src
129 ${FLATBUFFERS_DIR}/include
130 ${EIGEN_DIR}
131 ${EIGEN_DIR}/unsupported/
132 ${SERIALIZATION_DIR}/include
133 )
134
135 target_link_libraries(tosa_reference_model
136 PRIVATE
137 ${SERIALIZATION_LIB}
138 nlohmann_json::nlohmann_json
139 cxxopts
140 )
141
142 install(TARGETS tosa_reference_model DESTINATION bin)
143endif()
144
145if(BUILD_TOSA_REFERENCE_MODEL_TESTS)
146 # Set definition so unit tests can find examples directory.
147 add_definitions(-DPROJECT_ROOT=\"${CMAKE_CURRENT_SOURCE_DIR}/\")
148
149 # Set doctest location if not specified.
150 if(NOT DOCTEST_DIR)
151 set(DOCTEST_DIR "../thirdparty/doctest/doctest")
152 endif()
153
154 # Sources only required for unit tests.
155 set(CXX_SOURCE_TESTS
156 test/model_runner_tests.cpp
157 ${DOCTEST_DIR}/doctest.h
158 )
159
160 list(APPEND CXX_SOURCE_TESTS ${CXX_SOURCE})
161
162 add_executable(unit_tests ${CXX_SOURCE_TESTS})
163
164 target_include_directories(unit_tests
165 PUBLIC
166 $<INSTALL_INTERFACE:include>
167 $<BUILD_INTERFACE:${CMAKE_CURRENT_SRC_DIR}/include>
168 PRIVATE
169 ${CMAKE_CURRENT_SOURCE_DIR}/src
170 ${FLATBUFFERS_DIR}/include
171 ${EIGEN_DIR}
172 ${EIGEN_DIR}/unsupported/
173 ${SERIALIZATION_DIR}/include
174 ${DOCTEST_DIR}
175 )
176
177 target_link_libraries(unit_tests
178 PRIVATE
179 ${SERIALIZATION_LIB}
180 )
181endif()
182
183if(BUILD_MODEL_RUNNER_SAMPLE)
184 # Set definition so sample executable can find examples directory.
185 add_definitions(-DPROJECT_ROOT=\"${CMAKE_CURRENT_SOURCE_DIR}/\")
186
187 # Sources only required for example executable.
188 set(CXX_SOURCE_SAMPLE
189 samples/model_runner_simple_sample.cpp
190 )
191
192 list(APPEND CXX_SOURCE_SAMPLE ${CXX_SOURCE})
193
194 add_executable(model_runner_sample ${CXX_SOURCE_SAMPLE})
195
196 target_include_directories(model_runner_sample
197 PUBLIC
198 $<INSTALL_INTERFACE:include>
199 $<BUILD_INTERFACE:${CMAKE_CURRENT_SRC_DIR}/include>
200 PRIVATE
201 ${CMAKE_CURRENT_SOURCE_DIR}/src
202 ${FLATBUFFERS_DIR}/include
203 ${EIGEN_DIR}
204 ${EIGEN_DIR}/unsupported/
205 ${SERIALIZATION_DIR}/include
206 )
207
208 target_link_libraries(model_runner_sample
209 PRIVATE
210 ${SERIALIZATION_LIB}
211 )
212endif()
213
214# Follow GNU packaging norms for installation directory structure.
215include(GNUInstallDirs)
216install(
217 TARGETS tosa_reference_model_lib EXPORT TosaReferenceModelLibTargets
218 PUBLIC_HEADER
219 ARCHIVE
220)
221
222install(EXPORT TosaReferenceModelLibTargets
223 FILE TosaReferenceModelLibTargets.cmake
224 NAMESPACE TosaReference::
225 DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/tosa_reference_model_lib"
226)