1set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-sign-compare") 2set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-reorder") 3set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-switch") 4 5if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") 6 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-uninitialized -Wno-deprecated-declarations 7 -Wno-delete-non-abstract-non-virtual-dtor 8 -Wno-constant-conversion -Wno-unknown-warning-option") 9else() 10 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-maybe-uninitialized") 11endif() 12 13# fix for GCC8.0 14set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-class-memaccess -Wno-stringop-truncation") 15set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-format") 16set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-attributes") 17 18############################# Options ################################ 19if(${CMAKE_SYSTEM_NAME} MATCHES "Windows") 20 add_definitions(-D _CRT_RAND_S) 21endif() 22if(ENABLE_ACL) 23 add_definitions(-D ENABLE_ACL) 24 message(STATUS "ACL module is enabled") 25endif() 26if(ENABLE_GPUQUE) 27 add_definitions(-D ENABLE_GPUQUE) 28 message(STATUS "GPU queue is enabled") 29endif() 30if(ENABLE_TDTQUE) 31 add_definitions(-D ENABLE_TDTQUE) 32 message(STATUS "TDT queue is enabled") 33endif() 34if(MS_BUILD_GRPC) 35 set(ENABLE_CACHE true) 36 add_definitions(-D ENABLE_CACHE) 37 message(STATUS "Cache is enabled") 38endif() 39 40# conde coverage 41# option(ENABLE_COVERAGE "Enable code coverage report" OFF) 42# if(ENABLE_COVERAGE) 43# include(${CMAKE_SOURCE_DIR}/cmake/CodeCoverage.cmake) 44# append_coverage_compiler_flags() 45# endif() 46 47########### Set up the include directories ########################### 48include_directories(${CMAKE_SOURCE_DIR}/mindspore/ccsrc) 49include_directories(${CMAKE_SOURCE_DIR}/mindspore/ccsrc/runtime/device/ascend/platform) 50 51include_directories(${CMAKE_BINARY_DIR}) # for protobuf generated .h 52 53include_directories(${CMAKE_SOURCE_DIR}/mindspore) 54include_directories(${CMAKE_SOURCE_DIR}/mindspore/ccsrc/minddata/mindrecord/include) 55include_directories(${CMAKE_SOURCE_DIR}/mindspore/ccsrc/minddata/dataset) 56include_directories(${CMAKE_SOURCE_DIR}/mindspore/ccsrc/minddata/dataset/kernels/image) 57 58###################################################################### 59 60####################### Flags ######################################## 61# compile flags 62set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=default") 63 64if(CMAKE_SYSTEM_NAME MATCHES "Darwin") 65 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-delete-abstract-non-virtual-dtor") 66else() 67 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wl,-rpath,$ORIGIN:$ORIGIN/lib") 68endif() 69 70################## Include sub-modules ############################### 71add_subdirectory(util) 72add_subdirectory(core) 73add_subdirectory(kernels) 74add_subdirectory(engine) 75add_subdirectory(api) 76add_subdirectory(audio) 77add_subdirectory(text) 78add_subdirectory(callback) 79add_subdirectory(plugin) 80###################################################################### 81add_dependencies(utils core) 82add_dependencies(kernels-image core) 83add_dependencies(kernels-data core) 84add_dependencies(kernels-soft-dvpp-image core soft-dvpp-utils) 85add_dependencies(kernels core) 86add_dependencies(engine-datasetops-source core) 87add_dependencies(engine-datasetops-source-sampler core) 88add_dependencies(engine-datasetops core) 89add_dependencies(engine-datasetops-mapop core) 90add_dependencies(engine-opt core) 91add_dependencies(engine-gnn core) 92add_dependencies(engine core) 93add_dependencies(callback core) 94add_dependencies(audio-kernels core) 95add_dependencies(audio-ir core) 96add_dependencies(audio-ir-kernels core) 97add_dependencies(text core) 98add_dependencies(text-kernels core) 99add_dependencies(text-ir core) 100add_dependencies(text-ir-kernels core) 101add_dependencies(cpp-API core) 102add_dependencies(engine-ir-datasetops core) 103add_dependencies(engine-ir-datasetops-source core) 104add_dependencies(engine-ir-datasetops-source-samplers core) 105add_dependencies(engine-ir-cache core) 106add_dependencies(kernels-ir core) 107add_dependencies(kernels-ir-data core) 108add_dependencies(kernels-ir-vision core) 109 110 111if(ENABLE_ACL) 112 add_dependencies(kernels-dvpp-image core dvpp-utils) 113endif() 114 115if(ENABLE_PYTHON) 116 add_dependencies(APItoPython core) 117endif() 118if(NOT ENABLE_SECURITY) 119 add_dependencies(engine-perf core) 120endif() 121if(ENABLE_TDTQUE) 122 add_dependencies(engine-tdt core) 123endif() 124if(ENABLE_CACHE) 125 add_dependencies(APItoPython engine-cache-client) 126 add_dependencies(cpp-API engine-cache-client) 127 add_dependencies(engine-ir-cache engine-cache-client) 128 add_dependencies(engine-ir-datasetops engine-cache-client) 129 add_dependencies(engine-ir-datasetops-source engine-cache-client) 130 add_dependencies(engine-opt engine-cache-client) 131 add_dependencies(engine-datasetops engine-cache-client) 132 if(NOT ENABLE_SECURITY) 133 add_dependencies(engine-perf engine-cache-client) 134 endif() 135 add_dependencies(engine-cache-client core) 136 add_dependencies(engine-cache-server core) 137endif() 138################### Create _c_dataengine Library ###################### 139set(submodules 140 $<TARGET_OBJECTS:core> 141 $<TARGET_OBJECTS:callback> 142 $<TARGET_OBJECTS:utils> 143 $<TARGET_OBJECTS:kernels> 144 $<TARGET_OBJECTS:kernels-image> 145 $<TARGET_OBJECTS:lite-cv> 146 $<TARGET_OBJECTS:kernels-data> 147 $<TARGET_OBJECTS:cpp-API> 148 $<TARGET_OBJECTS:engine-ir-datasetops> 149 $<TARGET_OBJECTS:engine-ir-datasetops-source> 150 $<TARGET_OBJECTS:engine-ir-datasetops-source-samplers> 151 $<TARGET_OBJECTS:engine-ir-cache> 152 $<TARGET_OBJECTS:kernels-soft-dvpp-image> 153 $<TARGET_OBJECTS:soft-dvpp-utils> 154 $<TARGET_OBJECTS:engine-datasetops-source> 155 $<TARGET_OBJECTS:engine-datasetops-source-sampler> 156 $<TARGET_OBJECTS:engine-datasetops-mapop> 157 $<TARGET_OBJECTS:engine-gnn> 158 $<TARGET_OBJECTS:engine-datasetops> 159 $<TARGET_OBJECTS:engine-opt> 160 $<TARGET_OBJECTS:engine-cache-client> 161 $<TARGET_OBJECTS:engine> 162 $<TARGET_OBJECTS:audio-kernels> 163 $<TARGET_OBJECTS:audio-ir> 164 $<TARGET_OBJECTS:audio-ir-kernels> 165 $<TARGET_OBJECTS:text> 166 $<TARGET_OBJECTS:text-kernels> 167 $<TARGET_OBJECTS:text-ir> 168 $<TARGET_OBJECTS:text-ir-kernels> 169 $<TARGET_OBJECTS:kernels-ir> 170 $<TARGET_OBJECTS:kernels-ir-data> 171 $<TARGET_OBJECTS:kernels-ir-vision> 172 $<TARGET_OBJECTS:md_plugin> 173 ) 174 175 176if(ENABLE_ACL) 177 set(submodules 178 ${submodules} 179 $<TARGET_OBJECTS:kernels-dvpp-image> 180 $<TARGET_OBJECTS:dvpp-utils>) 181endif() 182 183if(ENABLE_PYTHON) 184 set(submodules 185 ${submodules} 186 $<TARGET_OBJECTS:APItoPython>) 187endif() 188 189if(ENABLE_TDTQUE) 190 if(NOT ENABLE_SECURITY) 191 add_library(_c_dataengine SHARED ${submodules} $<TARGET_OBJECTS:engine-perf> $<TARGET_OBJECTS:engine-tdt>) 192 else() 193 add_library(_c_dataengine SHARED ${submodules} $<TARGET_OBJECTS:engine-tdt>) 194 endif() 195else() 196 if(NOT ENABLE_SECURITY) 197 add_library(_c_dataengine SHARED ${submodules} $<TARGET_OBJECTS:engine-perf>) 198 else() 199 add_library(_c_dataengine SHARED ${submodules}) 200 endif() 201endif() 202 203if(ENABLE_PYTHON) 204set_target_properties(_c_dataengine PROPERTIES 205 PREFIX "${PYTHON_MODULE_PREFIX}" 206 SUFFIX "${PYTHON_MODULE_EXTENSION}" 207 ) 208endif() 209 210###################################################################### 211 212################# Link with external libraries ######################## 213target_link_libraries(_c_dataengine PRIVATE mindspore mindspore_gvar) 214 215if(CMAKE_SYSTEM_NAME MATCHES "Darwin") 216 set(CMAKE_MACOSX_RPATH 1) 217 set(CMAKE_INSTALL_RPATH "@loader_path/lib;@loader_path") 218 set_target_properties(_c_dataengine PROPERTIES INSTALL_RPATH "${CMAKE_INSTALL_RPATH}") 219endif() 220 221set(targetso $<TARGET_FILE:_c_dataengine>) 222set(target_tiny "libtinyxml") 223set(target_icuuc "libicuuc") 224set(target_icudata "libicudata") 225set(target_icui18n "libicui18n") 226function(changerpath targetso linkso) 227 set(some-file "${CMAKE_SOURCE_DIR}/mindspore/ccsrc/minddata/dataset/${linkso}.txt") 228 set(some-file1 "${CMAKE_SOURCE_DIR}/mindspore/ccsrc/minddata/dataset/${linkso}1.txt") 229 set(some-file2 "${CMAKE_SOURCE_DIR}/mindspore/ccsrc/minddata/dataset/${linkso}2.txt") 230 add_custom_command( 231 OUTPUT 232 ${some-file} 233 COMMAND 234 otool -L ${targetso} | grep ${linkso} > ${some-file} 235 WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/mindspore/ccsrc/minddata/dataset" 236 VERBATIM 237 ) 238 add_custom_command( 239 OUTPUT 240 ${some-file1} 241 COMMAND 242 cat ${some-file} | cut -d " " -f 1 | sed -E "s/^.//g" > ${some-file1} 243 DEPENDS 244 ${some-file} 245 WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/mindspore/ccsrc/minddata/dataset" 246 VERBATIM 247 ) 248 add_custom_command( 249 OUTPUT 250 ${some-file2} 251 COMMAND 252 awk -F "/" "{print $NF}" ${some-file1} > ${some-file2} 253 DEPENDS 254 ${some-file1} 255 WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/mindspore/ccsrc/minddata/dataset" 256 VERBATIM 257 ) 258 add_custom_target( 259 link_${linkso} ALL 260 COMMAND install_name_tool -change `cat ${some-file1}` @rpath/`cat ${some-file2}` ${targetso} 261 WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/mindspore/ccsrc/minddata/dataset" 262 DEPENDS ${targetso} ${some-file1} ${some-file2} 263 COMMENT "install tool name") 264endfunction() 265 266if(CMAKE_SYSTEM_NAME MATCHES "Darwin") 267 changerpath(${targetso} ${target_tiny}) 268 changerpath(${targetso} ${target_icuuc}) 269 add_dependencies(link_${target_icuuc} link_${target_tiny}) 270 changerpath(${targetso} ${target_icudata}) 271 add_dependencies(link_${target_icudata} link_${target_icuuc}) 272 changerpath(${targetso} ${target_icui18n}) 273 add_dependencies(link_${target_icui18n} link_${target_icudata}) 274endif() 275 276if(${CMAKE_SYSTEM_NAME} MATCHES "Windows") 277 if(ENABLE_PYTHON) 278 target_link_libraries(_c_dataengine PRIVATE mindspore::pybind11_module ${PYTHON_LIBRARIES} ${SECUREC_LIBRARY}) 279 else() 280 target_link_libraries(_c_dataengine PRIVATE ${SECUREC_LIBRARY}) 281 endif() 282 target_link_options(_c_dataengine PRIVATE -Wl,--allow-multiple-definition) 283else() 284 set(ICU_LIB mindspore::icuuc mindspore::icudata mindspore::icui18n) 285 if(ENABLE_PYTHON) 286 target_link_libraries(_c_dataengine PRIVATE mindspore::pybind11_module -ldl ${SECUREC_LIBRARY}) 287 else() 288 target_link_libraries(_c_dataengine PRIVATE -ldl ${SECUREC_LIBRARY}) 289 endif() 290 target_link_libraries(_c_dataengine PUBLIC mindspore::sentencepiece) 291endif() 292 293target_link_libraries(_c_dataengine PUBLIC mindspore::jpeg_turbo mindspore::turbojpeg mindspore::opencv_core 294 mindspore::opencv_imgcodecs mindspore::opencv_imgproc mindspore::tinyxml2 295 mindspore::sentencepiece_train ${ICU_LIB}) 296if(ENABLE_GPUQUE) 297 target_link_libraries(_c_dataengine PRIVATE gpu_queue 298 ${CUDNN_LIBRARY_PATH} 299 ${CUDA_PATH}/lib64/libcudart.so 300 ${CUDA_PATH}/lib64/stubs/libcuda.so) 301endif() 302 303if(ENABLE_TDTQUE) 304 target_link_libraries(_c_dataengine PRIVATE ${ACL} ${ACL_TDT_CHANNEL}) 305endif() 306 307add_dependencies(_c_dataengine _c_mindrecord) 308if(${CMAKE_SYSTEM_NAME} MATCHES "Windows") 309 set(MINDRECORD_LINK_OBJECT 310 ${CMAKE_BINARY_DIR}/mindspore/ccsrc/minddata/mindrecord/CMakeFiles/_c_mindrecord.dir/objects.a) 311 target_link_libraries(_c_dataengine PRIVATE _c_mindrecord ${MINDRECORD_LINK_OBJECT} mindspore::sqlite) 312else() 313 target_link_libraries(_c_dataengine PRIVATE _c_mindrecord) 314 if(ENABLE_CPU AND NOT WIN32) 315 if(${ENABLE_IBVERBS} STREQUAL "ON") 316 target_link_libraries(_c_dataengine PRIVATE ibverbs rdmacm) 317 endif() 318 target_link_libraries(_c_dataengine PRIVATE ps_cache) 319 endif() 320endif() 321 322target_link_libraries(_c_dataengine PRIVATE mindspore_core mindspore_shared_lib) 323 324if(USE_GLOG) 325 target_link_libraries(_c_dataengine PRIVATE mindspore::glog) 326else() 327 if(CMAKE_SYSTEM_NAME MATCHES "Linux") 328 target_link_options(_c_dataengine PRIVATE -Wl,-init,mindspore_log_init) 329 elseif(CMAKE_SYSTEM_NAME MATCHES "Darwin") 330 set_target_properties(_c_dataengine PROPERTIES MACOSX_RPATH ON) 331 endif() 332endif() 333 334if(MS_BUILD_GRPC) 335 target_link_libraries(_c_dataengine PRIVATE -Wl,--no-as-needed mindspore::grpc++) 336endif() 337 338set_target_properties(_c_dataengine PROPERTIES INSTALL_RPATH ${MINDSPORE_RPATH}) 339