MNN/CMakeLists.txt

1048 lines
40 KiB
CMake
Raw Normal View History

cmake_minimum_required(VERSION 3.6)
2019-12-27 22:16:57 +08:00
# Versioning stuff
2022-06-24 18:30:05 +08:00
file(STRINGS "${CMAKE_CURRENT_LIST_DIR}/include/MNN/MNNDefine.h" MNN_DEFINE)
string(REGEX MATCH "MNN_VERSION_MAJOR [0-9]+" MNN_VERSION_MAJOR_DEFINE ${MNN_DEFINE})
string(REGEX MATCH "[0-9]+" MNN_VERSION_MAJOR ${MNN_VERSION_MAJOR_DEFINE})
string(REGEX MATCH "MNN_VERSION_MINOR [0-9]+" MNN_VERSION_MINOR_DEFINE ${MNN_DEFINE})
string(REGEX MATCH "[0-9]+" MNN_VERSION_MINOR ${MNN_VERSION_MINOR_DEFINE})
string(REGEX MATCH "MNN_VERSION_PATCH [0-9]+" MNN_VERSION_PATCH_DEFINE ${MNN_DEFINE})
string(REGEX MATCH "[0-9]+" MNN_VERSION_PATCH ${MNN_VERSION_PATCH_DEFINE})
set(MNN_VERSION ${MNN_VERSION_MAJOR}.${MNN_VERSION_MINOR}.${MNN_VERSION_PATCH})
2019-12-27 22:16:57 +08:00
2022-02-18 11:30:27 +08:00
# Clear VERSION variables when no VERSION is given to project()
if(POLICY CMP0048)
cmake_policy(SET CMP0048 NEW)
endif()
# MSVC runtime library flags are selected by an abstraction.
if(POLICY CMP0091)
cmake_policy(SET CMP0091 NEW)
endif()
2022-06-24 18:30:05 +08:00
project(MNN VERSION ${MNN_VERSION} LANGUAGES C CXX ASM)
2019-04-17 10:49:11 +08:00
# complier options
set(CMAKE_C_STANDARD 99)
2025-02-24 11:44:27 +08:00
IF (NOT (CMAKE_CXX_STANDARD EQUAL 17))
set(CMAKE_CXX_STANDARD 11)
ENDIF()
2019-12-27 22:16:57 +08:00
set(CMAKE_MODULE_PATH
${CMAKE_MODULE_PATH}
"${CMAKE_CURRENT_LIST_DIR}/cmake"
)
2024-10-14 19:26:28 +08:00
if(WIN32)
if(NOT MSVC)
set(CMAKE_MSVC_RUNTIME_LIBRARY "")
set(MSVC_RUNTIME_LIBRARY "")
endif()
endif()
2019-04-17 10:49:11 +08:00
# build options
option(MNN_USE_SYSTEM_LIB "For opencl and vulkan, use system lib or use dlopen" OFF)
2019-04-17 10:49:11 +08:00
option(MNN_BUILD_HARD "Build -mfloat-abi=hard or not" OFF)
option(MNN_BUILD_SHARED_LIBS "MNN build shared or static lib" ON)
2020-11-05 16:41:56 +08:00
option(MNN_WIN_RUNTIME_MT "MNN use /MT on Windows dll" OFF)
2019-04-17 10:49:11 +08:00
option(MNN_FORBID_MULTI_THREAD "Disable Multi Thread" OFF)
option(MNN_OPENMP "Use OpenMP's thread pool implementation. Does not work on iOS or Mac OS" OFF)
option(MNN_USE_THREAD_POOL "Use MNN's own thread pool implementation" ON)
option(MNN_BUILD_TRAIN "Build MNN's training framework" OFF)
option(MNN_BUILD_DEMO "Build demo/exec or not" OFF)
option(MNN_BUILD_TOOLS "Build tools/cpp or not" ON)
option(MNN_BUILD_QUANTOOLS "Build Quantized Tools or not" OFF)
option(MNN_EVALUATION "Build Evaluation Tools or not" OFF)
- build: - unify schema building in core and converter; - add more build script for android; - add linux build script for python; - ops impl: - add floor mod support in binary; - use eltwise impl in add/max/sub/mul binary for optimization; - remove fake double support in cast; - fix 5d support for concat; - add adjX and adjY support for batch matmul; - optimize conv2d back prop filter; - add pad mode support for conv3d; - fix bug in conv2d & conv depthwise with very small feature map; - optimize binary without broacast; - add data types support for gather; - add gather ND support; - use uint8 data type in gather v2; - add transpose support for matmul; - add matrix band part; - add dim != 4 support for padding, reshape & tensor convert; - add pad type support for pool3d; - make ops based on TensorFlow Lite quantization optional; - add all & any support for reduction; - use type in parameter as output type in reduction; - add int support for unary; - add variable weight support for conv2d; - fix conv2d depthwise weights initialization; - fix type support for transpose; - fix grad outputs count for reduce grad and reshape grad; - fix priorbox & detection output; - fix metal softmax error; - python: - add runSessionWithCallBackInfo interface; - add max nodes limit (1400) for visualization tool; - fix save error in python3; - align default dim; - convert: - add extra design for optimization; - add more post converting optimizers; - add caffe v1 weights blob support; - add cast, unary, conv transpose support for onnx model; - optimize batchnorm, conv with variable weights, prelu, reshape, slice, upsample for onnx model; - add cos/sin/atan/tan support for unary for tensorflow model; - add any/all support for reduction for tensorflow model; - add elu, conv3d, pool3d support for tensorflow model; - optimize argmax, batchnorm, concat, batch to space, conv with variable weights, prelu, slice for tensorflow model; - others: - fix size computer lock; - fix thread pool deadlock; - add express & parameters in express; - rewrite blitter chooser without static map; - add tests for expr;
2019-10-29 13:37:26 +08:00
option(MNN_BUILD_CONVERTER "Build Converter" OFF)
option(MNN_REDUCE_SIZE "Remove not common op and optimize code" OFF)
option(MNN_SUPPORT_QUANT_EXTEND "Add int8 op for layernorm, binary, unary, scale, softmax, interp" ON)
2024-12-19 16:20:00 +08:00
option(MNN_SUPPORT_DEPRECATED_OP "Enable MNN's tflite quantized op" OFF)
option(MNN_SUPPORT_DEPRECATED_OPV2 "Enable MNN's DEPRECATED op's geometry such as conv3d / deconv3d, which has been treated in converter" ON)
2019-12-27 22:16:57 +08:00
option(MNN_DEBUG_MEMORY "MNN Debug Memory Access" OFF)
option(MNN_DEBUG_TENSOR_SIZE "Enable Tensor Size" OFF)
option(MNN_GPU_TRACE "Enable MNN Gpu Debug" OFF)
2023-12-04 11:12:20 +08:00
option(MNN_SUPPORT_RENDER "Enable MNN Render Ops" OFF)
2024-02-29 16:21:40 +08:00
option(MNN_SUPPORT_TRANSFORMER_FUSE "Enable MNN transformer Fuse Ops" OFF)
2022-05-27 23:48:09 +08:00
option(MNN_SEP_BUILD "Build MNN Backends and expression separately. Only works with MNN_BUILD_SHARED_LIBS=ON" ON)
2019-12-27 22:16:57 +08:00
option(NATIVE_LIBRARY_OUTPUT "Native Library Path" OFF)
option(NATIVE_INCLUDE_OUTPUT "Native Include Path" OFF)
2020-01-17 10:20:15 +08:00
option(MNN_AAPL_FMWK "Build MNN.framework instead of traditional .a/.dylib" OFF)
option(MNN_WITH_PLUGIN "Build with plugin op support." OFF)
option(MNN_SKIPBUILD_GEOMETRY "Skip Build MNN-Geometry, then only supports fixed shape models." OFF)
option(MNN_BUILD_MINI "Build minimal MNN so, set MNN_SKIPBUILD_GEOMETRY and MNN_REDUCE_SIZE ON" OFF)
2020-11-05 16:41:56 +08:00
option(MNN_USE_SSE "Use SSE optimization for x86 if possiable" ON)
2021-01-06 16:29:37 +08:00
option(MNN_BUILD_CODEGEN "Build with codegen" OFF)
2021-01-08 14:36:59 +08:00
option(MNN_ENABLE_COVERAGE "Build with coverage enable" OFF)
option(MNN_BUILD_PROTOBUFFER "Build with protobuffer in MNN" ON)
option(MNN_BUILD_OPENCV "Build OpenCV api in MNN." OFF)
2023-10-18 10:31:02 +08:00
option(MNN_BUILD_LLM "Build llm library based MNN." OFF)
2025-09-22 23:05:26 +08:00
option(MNN_BUILD_LLM_OMNI "If build llm library, build it with omni (support image / audio)" OFF)
2024-05-11 19:17:02 +08:00
option(MNN_BUILD_DIFFUSION "Build diffusion demo based MNN." OFF)
2022-01-04 10:50:40 +08:00
option(MNN_INTERNAL "Build with MNN internal features, such as model authentication, metrics logging" OFF)
2022-06-10 10:39:50 +08:00
option(MNN_JNI "Build MNN Jni for java to use" OFF)
option(MNN_SUPPORT_BF16 "Enable MNN's bf16 op" OFF)
option(MNN_LOW_MEMORY "Build MNN support low memory for weight quant model." OFF)
2024-09-12 12:57:57 +08:00
option(MNN_CPU_WEIGHT_DEQUANT_GEMM "Build MNN CPU weight dequant related gemm kernels." OFF)
2024-12-19 16:20:00 +08:00
option(MNN_BUILD_AUDIO "Build audio api in MNN." OFF)
2025-07-23 14:10:58 +08:00
option(MNN_SME2 "Use Arm sme2 instructions" ON)
if (MNN_BUILD_MINI)
set(MNN_SKIPBUILD_GEOMETRY ON)
set(MNN_REDUCE_SIZE ON)
endif()
if (MNN_REDUCE_SIZE)
set(MNN_SUPPORT_DEPRECATED_OP OFF)
set(MNN_SUPPORT_DEPRECATED_OPV2 OFF)
set(MNN_SUPPORT_QUANT_EXTEND OFF)
set(MNN_USE_SPARSE_COMPUTE OFF)
endif()
2024-11-18 14:37:45 +08:00
IF (OHOS AND MNN_INTERNAL)
2024-05-11 19:17:02 +08:00
include($ENV{NODE_PATH}/@ali/tcpkg/tcpkg.cmake)
export_headers(DIR ${CMAKE_SOURCE_DIR}/include/MNN)
IF (MNN_BUILD_OPENCV)
export_headers(DIR ${CMAKE_SOURCE_DIR}/tools/cv/include/cv)
ENDIF()
ENDIF()
IF (NOT DEFINED MNN_USE_SPARSE_COMPUTE)
set(MNN_USE_SPARSE_COMPUTE ON)
ENDIF()
2025-09-22 23:05:26 +08:00
IF (MNN_BUILD_LLM)
set(MNN_LOW_MEMORY ON)
set(MNN_SUPPORT_TRANSFORMER_FUSE ON)
IF (MNN_BUILD_LLM_OMNI)
set(MNN_BUILD_OPENCV ON)
set(MNN_BUILD_AUDIO ON)
ENDIF()
ENDIF()
IF (MNN_BUILD_DIFFUSION)
set(MNN_LOW_MEMORY ON)
set(MNN_SUPPORT_TRANSFORMER_FUSE ON)
set(MNN_BUILD_OPENCV ON)
ENDIF()
IF(NOT MNN_BUILD_SHARED_LIBS AND MNN_SEP_BUILD)
message(WARNING "Close MNN_SEP_BUILD for static library")
SET(MNN_SEP_BUILD OFF CACHE BOOL "<docstring>" FORCE)
ENDIF()
2019-12-27 22:16:57 +08:00
IF(APPLE AND MNN_AAPL_FMWK AND MNN_SEP_BUILD)
message(WARNING "MNN_SEP_BUILD AND MNN_AAPL_FMWK can't coexist. Turning off MNN_SEP_BUILD")
SET(MNN_SEP_BUILD OFF CACHE BOOL "<docstring>" FORCE)
2019-12-27 22:16:57 +08:00
ENDIF()
2020-11-05 16:41:56 +08:00
IF(WIN32)
IF(MNN_SEP_BUILD)
message(WARNING "MNN_SEP_BUILD IS TROUBLESOME ON Windows. Forcing OFF...")
SET(MNN_SEP_BUILD OFF CACHE BOOL "<docstring>" FORCE)
ENDIF()
2020-11-05 16:41:56 +08:00
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
2020-11-05 16:41:56 +08:00
IF(MSVC)
# generate optimized (release) exe and library with pdb debug file, https://stackoverflow.com/a/31264946
SET(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /DEBUG /OPT:REF /OPT:ICF")
SET(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /DEBUG /OPT:REF /OPT:ICF")
SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /Zi")
SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Zi")
2022-02-18 11:30:27 +08:00
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4267 /wd4018 /wd4251 /wd4996 /wd4244 /wd4146 /wd4129 /wd4305 /wd4275 /wd4101")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4267 /wd4018 /wd4251 /wd4996 /wd4244 /wd4146 /wd4129 /wd4305 /wd4275 /wd4101")
2020-11-05 16:41:56 +08:00
ENDIF()
ENDIF()
IF (NOT MNN_BUILD_SHARED_LIBS)
add_definitions(-DMNN_BUILD_STATIC_LIBS)
ENDIF()
2021-01-08 14:36:59 +08:00
# for coverage test
IF( MNN_ENABLE_COVERAGE)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")
ENDIF()
2023-07-13 10:40:21 +08:00
if ((CMAKE_SYSTEM_NAME STREQUAL "Darwin") AND CMAKE_OSX_ARCHITECTURES)
set(CMAKE_SYSTEM_PROCESSOR ${CMAKE_OSX_ARCHITECTURES})
endif()
2022-02-18 11:30:27 +08:00
# do this before protobuf, make sure wincrt config of protobuf and MNN is same
if(MSVC)
# same as protobuf, otherwise config is inconsistent
if(CMAKE_VERSION VERSION_GREATER 3.15 OR CMAKE_VERSION VERSION_EQUAL 3.15)
set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreaded$<$<CONFIG:Debug>:Debug>)
if(NOT MNN_WIN_RUNTIME_MT)
set(CMAKE_MSVC_RUNTIME_LIBRARY ${CMAKE_MSVC_RUNTIME_LIBRARY}DLL)
endif()
else()
foreach(flag_var
CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
if (MNN_WIN_RUNTIME_MT)
if(${flag_var} MATCHES "/MD")
string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
endif()
else ()
if(${flag_var} MATCHES "/MT")
string(REGEX REPLACE "/MT" "/MD" ${flag_var} "${${flag_var}}")
endif()
endif ()
endforeach()
endif()
set(protobuf_BUILD_SHARED_LIBS ${MNN_BUILD_SHARED_LIBS})
endif()
2019-12-27 22:16:57 +08:00
include(${CMAKE_CURRENT_LIST_DIR}/cmake/macros.cmake)
IF(MNN_BUILD_PROTOBUFFER)
IF(MNN_BUILD_CONVERTER)
2022-02-18 11:30:27 +08:00
IF(MSVC)
set(protobuf_BUILD_SHARED_LIBS ${MNN_BUILD_SHARED_LIBS})
IF((NOT MNN_BUILD_SHARED_LIBS) AND (NOT MNN_WIN_RUNTIME_MT))
message(FATAL_ERROR "When MNN_BUILD_CONVERTER=ON and MNN_BUILD_SHARED_LIBS=OFF, MNN_WIN_RUNTIME_MT must be ON. Because protobuf not support the config(static /MD)")
ENDIF()
ENDIF()
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/3rd_party/protobuf/cmake)
ENDIF()
ENDIF()
2022-02-18 11:30:27 +08:00
# specify source file encoding explicitly, fix cross-platform garbled output issue
# we need do this after protobuf which set different execution-charset
IF(MSVC)
set(CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS} /source-charset:utf-8")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /source-charset:utf-8")
ENDIF()
IF(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND NOT MNN_BUILD_SHARED_LIBS AND NOT (MSVC OR WIN32))
2020-11-05 16:41:56 +08:00
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}")
SET(MNN_SEP_BUILD OFF CACHE BOOL "<docstring>" FORCE)
ENDIF()
2019-04-17 10:49:11 +08:00
if(MNN_FORBID_MULTI_THREAD)
add_definitions(-DMNN_FORBIT_MULTI_THREADS)
endif()
if(MNN_SUPPORT_DEPRECATED_OP)
add_definitions(-DMNN_SUPPORT_DEPRECATED_OP)
- build: - unify schema building in core and converter; - add more build script for android; - add linux build script for python; - ops impl: - add floor mod support in binary; - use eltwise impl in add/max/sub/mul binary for optimization; - remove fake double support in cast; - fix 5d support for concat; - add adjX and adjY support for batch matmul; - optimize conv2d back prop filter; - add pad mode support for conv3d; - fix bug in conv2d & conv depthwise with very small feature map; - optimize binary without broacast; - add data types support for gather; - add gather ND support; - use uint8 data type in gather v2; - add transpose support for matmul; - add matrix band part; - add dim != 4 support for padding, reshape & tensor convert; - add pad type support for pool3d; - make ops based on TensorFlow Lite quantization optional; - add all & any support for reduction; - use type in parameter as output type in reduction; - add int support for unary; - add variable weight support for conv2d; - fix conv2d depthwise weights initialization; - fix type support for transpose; - fix grad outputs count for reduce grad and reshape grad; - fix priorbox & detection output; - fix metal softmax error; - python: - add runSessionWithCallBackInfo interface; - add max nodes limit (1400) for visualization tool; - fix save error in python3; - align default dim; - convert: - add extra design for optimization; - add more post converting optimizers; - add caffe v1 weights blob support; - add cast, unary, conv transpose support for onnx model; - optimize batchnorm, conv with variable weights, prelu, reshape, slice, upsample for onnx model; - add cos/sin/atan/tan support for unary for tensorflow model; - add any/all support for reduction for tensorflow model; - add elu, conv3d, pool3d support for tensorflow model; - optimize argmax, batchnorm, concat, batch to space, conv with variable weights, prelu, slice for tensorflow model; - others: - fix size computer lock; - fix thread pool deadlock; - add express & parameters in express; - rewrite blitter chooser without static map; - add tests for expr;
2019-10-29 13:37:26 +08:00
endif()
if(MNN_SUPPORT_DEPRECATED_OPV2)
add_definitions(-DMNN_SUPPORT_DEPRECATED_OPV2)
endif()
if (MNN_REDUCE_SIZE)
add_definitions(-DMNN_REDUCE_SIZE)
endif()
if(MNN_SUPPORT_QUANT_EXTEND)
add_definitions(-DMNN_SUPPORT_QUANT_EXTEND)
endif()
if(MNN_LOW_MEMORY)
add_definitions(-DMNN_LOW_MEMORY)
endif()
2023-12-04 11:12:20 +08:00
if(MNN_SUPPORT_RENDER)
add_definitions(-DMNN_SUPPORT_RENDER)
endif()
2024-02-29 16:21:40 +08:00
if(MNN_SUPPORT_TRANSFORMER_FUSE)
add_definitions(-DMNN_SUPPORT_TRANSFORMER_FUSE)
endif()
2019-04-17 10:49:11 +08:00
# debug options
if(MNN_DEBUG_MEMORY)
add_definitions(-DMNN_DEBUG_MEMORY)
endif()
if(MNN_DEBUG_TENSOR_SIZE)
add_definitions(-DMNN_DEBUG_TENSOR_SIZE)
endif()
if(MNN_GPU_TRACE)
add_definitions(-DMNN_GPU_FORCE_FINISH)
endif()
# backend options
option(MNN_METAL "Enable Metal" OFF)
option(MNN_OPENCL "Enable OpenCL" OFF)
option(MNN_OPENGL "Enable OpenGL" OFF)
option(MNN_VULKAN "Enable Vulkan" OFF)
2024-10-14 19:26:28 +08:00
option(MNN_ARM82 "Enable ARMv8.2's FP16 Compute" ON)
2025-03-27 11:19:34 +08:00
option(MNN_SUPPORT_FP16_ARMV7 "Enable ARMv8.2's FP16 Compute for armv7 arch, may cause library not valid for 32 bit cpu" OFF)
option(MNN_KLEIDIAI "Enable KLEIDIAI" ON)
2021-01-06 16:29:37 +08:00
option(MNN_ONEDNN "Enable oneDNN" OFF)
2024-11-18 14:37:45 +08:00
option(MNN_AVX2 "Open AVX2 Compile for x86 if possible" ON)
2021-01-06 16:29:37 +08:00
option(MNN_AVX512 "Enable AVX512" OFF)
2025-09-22 23:05:26 +08:00
option(MNN_USE_RVV "Enable RVV" OFF)
2020-11-05 16:41:56 +08:00
option(MNN_CUDA "Enable CUDA" OFF)
option(MNN_TENSORRT "Enable TensorRT" OFF)
option(MNN_COREML "Enable CoreML" OFF)
2022-09-30 10:02:52 +08:00
option(MNN_NNAPI "Enable NNAPI" OFF)
2025-09-22 23:05:26 +08:00
option(MNN_QNN "Enable QNN" OFF)
option(MNN_QNN_ONLINE_FINALIZE "Enable QNN Online Finalize" ON)
2025-02-12 11:14:19 +08:00
option(MNN_GPU_TIME_PROFILE "Enable time profiling for the OpenCL backend and Vulkan backend." OFF)
2022-09-30 10:02:52 +08:00
option(MNN_CUDA_PROFILE "Enable CUDA profile" OFF)
if (NOT MNN_CUDA OR NOT CMAKE_SYSTEM_NAME MATCHES "^Linux")
set(MNN_CUDA_PROFILE OFF)
endif()
2019-05-09 19:39:33 +08:00
2025-09-22 23:05:26 +08:00
if (NOT MNN_QNN)
set(MNN_QNN_ONLINE_FINALIZE OFF)
endif()
2021-01-06 16:29:37 +08:00
if (MNN_USE_THREAD_POOL)
message(STATUS "Use Threadpool, forbid openmp")
set(MNN_OPENMP OFF)
add_definitions(-DMNN_USE_THREAD_POOL)
endif()
2021-04-08 15:34:23 +08:00
# When build Android based on arm32 by MTL, force turn off MNN_ARM82
2025-03-27 11:19:34 +08:00
if(CMAKE_SYSTEM_PROCESSOR MATCHES "^armv7" OR ARCHS MATCHES "^armv7(;armv7s)?")
if (NOT MNN_SUPPORT_FP16_ARMV7)
message(STATUS "force turn off MNN_ARM82 when build for Android based on arm32 by MTL")
SET(MNN_ARM82 OFF CACHE BOOL "Enable ARM82" FORCE)
endif()
2021-04-08 15:34:23 +08:00
endif()
2019-04-17 10:49:11 +08:00
# target options
option(MNN_BUILD_BENCHMARK "Build benchmark or not" OFF)
2019-04-17 10:49:11 +08:00
option(MNN_BUILD_TEST "Build tests or not" OFF)
option(MNN_BUILD_FOR_ANDROID_COMMAND "Build from command" OFF)
2020-02-26 09:57:17 +08:00
option(MNN_USE_LOGCAT "Use Logcat intead of print for info" ON)
2019-04-17 10:49:11 +08:00
set (MNN_HIDDEN FALSE)
2020-02-26 09:57:17 +08:00
IF(CMAKE_BUILD_TYPE MATCHES Debug)
2019-12-27 22:16:57 +08:00
ELSE()
set(MNN_HIDDEN TRUE)
2020-02-26 09:57:17 +08:00
ENDIF(CMAKE_BUILD_TYPE MATCHES Debug)
2019-04-17 10:49:11 +08:00
message(STATUS ">>>>>>>>>>>>>")
message(STATUS "MNN BUILD INFO:")
message(STATUS "\tSystem: ${CMAKE_SYSTEM_NAME}")
message(STATUS "\tProcessor: ${CMAKE_SYSTEM_PROCESSOR}")
2022-06-24 18:30:05 +08:00
message(STATUS "\tVersion: ${MNN_VERSION}")
2019-04-17 10:49:11 +08:00
message(STATUS "\tMetal: ${MNN_METAL}")
message(STATUS "\tOpenCL: ${MNN_OPENCL}")
message(STATUS "\tOpenGL: ${MNN_OPENGL}")
message(STATUS "\tVulkan: ${MNN_VULKAN}")
message(STATUS "\tARM82: ${MNN_ARM82}")
2024-10-21 14:32:47 +08:00
message(STATUS "\tKleidiAI: ${MNN_KLEIDIAI}")
2021-01-06 16:29:37 +08:00
message(STATUS "\toneDNN: ${MNN_ONEDNN}")
2020-11-05 16:41:56 +08:00
message(STATUS "\tTensorRT: ${MNN_TENSORRT}")
message(STATUS "\tCoreML: ${MNN_COREML}")
2022-09-30 10:02:52 +08:00
message(STATUS "\tNNAPI: ${MNN_NNAPI}")
2025-09-22 23:05:26 +08:00
message(STATUS "\tQNN: ${MNN_QNN}")
2020-11-05 16:41:56 +08:00
message(STATUS "\tCUDA: ${MNN_CUDA}")
2019-04-17 10:49:11 +08:00
message(STATUS "\tOpenMP: ${MNN_OPENMP}")
2021-04-08 15:34:23 +08:00
message(STATUS "\tBF16: ${MNN_SUPPORT_BF16}")
2021-01-06 16:29:37 +08:00
message(STATUS "\tThreadPool: ${MNN_USE_THREAD_POOL}")
message(STATUS "\tHidden: ${MNN_HIDDEN}")
2019-12-27 22:16:57 +08:00
message(STATUS "\tBuild Path: ${CMAKE_CURRENT_BINARY_DIR}")
2022-09-30 10:02:52 +08:00
message(STATUS "\tCUDA PROFILE: ${MNN_CUDA_PROFILE}")
2019-04-17 10:49:11 +08:00
2022-02-18 11:30:27 +08:00
if(CMAKE_SYSTEM_NAME MATCHES "^Android" OR CMAKE_SYSTEM_NAME MATCHES "^Linux")
2019-04-17 10:49:11 +08:00
add_definitions(-fPIC)
endif()
2022-05-30 21:15:15 +08:00
# Raspberry Pi 32-bit fix
if(CMAKE_SYSTEM_NAME MATCHES "^Linux" AND CMAKE_SYSTEM_PROCESSOR MATCHES "^armv7")
add_definitions(-march=armv7-a -mfpu=neon-vfpv4)
endif()
2019-12-27 22:16:57 +08:00
if(CMAKE_SYSTEM_NAME MATCHES "^Android")
add_definitions(-DMNN_BUILD_FOR_ANDROID)
2020-01-17 10:20:15 +08:00
if(CMAKE_SYSTEM_PROCESSOR MATCHES "^arm")
add_definitions(-mfloat-abi=softfp -mfpu=neon)
endif()
2019-12-27 22:16:57 +08:00
endif()
option(MNN_USE_CPP11 "Enable MNN use c++11" ON)
if (NOT MSVC)
2025-02-24 11:44:27 +08:00
if((MNN_CUDA AND MNN_SUPPORT_TRANSFORMER_FUSE) OR (CMAKE_CXX_STANDARD EQUAL 17))
2024-05-11 19:17:02 +08:00
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99")
2024-03-13 14:55:54 +08:00
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")
elseif(MNN_USE_CPP11)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99")
2024-05-11 19:17:02 +08:00
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
else()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
endif()
endif()
if(CMAKE_SYSTEM_NAME MATCHES "^Linux")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__STRICT_ANSI__")
if(CMAKE_SYSTEM_PROCESSOR MATCHES "^armv7")
add_definitions(-mfpu=neon) #please define in project/cross-compile/arm.toolchain.cmake
endif()
if(MNN_BUILD_HARD)
add_definitions(-mfloat-abi=hard) #better define in project/cross-compile/arm.toolchain.cmake
endif()
endif()
2019-12-27 22:16:57 +08:00
2023-04-18 18:54:46 +08:00
IF(MNN_DEBUG_MEMORY)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address")
endif()
2019-04-17 10:49:11 +08:00
2024-11-18 14:37:45 +08:00
set(MNN_DEPS "")
set(MNN_EXTRA_DEPENDS "")
2020-02-26 09:57:17 +08:00
IF(CMAKE_BUILD_TYPE MATCHES Debug)
add_definitions(-DMNN_DEBUG -DDEBUG)
if(MSVC)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /DEBUG")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /DEBUG")
else()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g")
endif()
2019-04-17 10:49:11 +08:00
else()
if (MSVC)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /O2")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /O2")
else()
2019-12-27 22:16:57 +08:00
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
if(CMAKE_SYSTEM_NAME MATCHES "^Android")
if(MNN_BUILD_FOR_ANDROID_COMMAND)
2020-02-26 09:57:17 +08:00
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -s")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pie -fPIE -s")
2019-12-27 22:16:57 +08:00
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--gc-sections")
endif()
endif()
2019-04-17 10:49:11 +08:00
endif()
2020-02-26 09:57:17 +08:00
ENDIF(CMAKE_BUILD_TYPE MATCHES Debug)
2024-11-18 14:37:45 +08:00
if(OHOS)
IF(MNN_USE_LOGCAT)
add_definitions(-DMNN_USE_LOGCAT)
add_definitions(-Wno-format-security)
list(APPEND MNN_EXTRA_DEPENDS libhilog_ndk.z.so)
ENDIF()
endif()
2020-02-26 09:57:17 +08:00
if(CMAKE_SYSTEM_NAME MATCHES "^Android")
IF(MNN_USE_LOGCAT)
add_definitions(-DMNN_USE_LOGCAT)
ENDIF()
IF (NOT MNN_BUILD_FOR_ANDROID_COMMAND)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${NATIVE_LIBRARY_OUTPUT}/${ANDROID_ABI})
ENDIF()
endif()
2019-04-17 10:49:11 +08:00
if(${CMAKE_SYSTEM_NAME} MATCHES "^Linux")
2019-12-27 22:16:57 +08:00
if((CMAKE_SYSTEM_PROCESSOR MATCHES "^arm") OR (CMAKE_SYSTEM_PROCESSOR MATCHES "^aarch64"))
2019-04-17 10:49:11 +08:00
set(aarch64_linux_include
#/usr/include/c++/4.9
#/usr/lib/gcc/x86_64-linux-gnu/4.9
#/usr/lib/gcc/x86_64-linux-gnu/4.9/include
#/usr/include/x86_64-linux-gnu/c++/4.9
)
include_directories(${aarch64_linux_include})
endif()
endif()
2019-12-27 22:16:57 +08:00
include_directories(${CMAKE_CURRENT_LIST_DIR}/include/
${CMAKE_CURRENT_LIST_DIR}/source/
2020-11-05 16:41:56 +08:00
${CMAKE_CURRENT_LIST_DIR}/express/
${CMAKE_CURRENT_LIST_DIR}/tools/
2021-01-06 16:29:37 +08:00
${CMAKE_CURRENT_LIST_DIR}/codegen/
2019-12-27 22:16:57 +08:00
${CMAKE_CURRENT_LIST_DIR}/schema/current/
${CMAKE_CURRENT_LIST_DIR}/3rd_party/
${CMAKE_CURRENT_LIST_DIR}/3rd_party/flatbuffers/include
${CMAKE_CURRENT_LIST_DIR}/3rd_party/half
${CMAKE_CURRENT_LIST_DIR}/3rd_party/imageHelper
${CMAKE_CURRENT_LIST_DIR}/3rd_party/OpenCLHeaders/
2020-01-17 10:20:15 +08:00
)
list(APPEND MNN_INCLUDES
${CMAKE_CURRENT_LIST_DIR}/include/
${CMAKE_CURRENT_LIST_DIR}/source/
${CMAKE_CURRENT_LIST_DIR}/express/
${CMAKE_CURRENT_LIST_DIR}/tools/
${CMAKE_CURRENT_LIST_DIR}/codegen/
${CMAKE_CURRENT_LIST_DIR}/schema/current/
${CMAKE_CURRENT_LIST_DIR}/3rd_party/
${CMAKE_CURRENT_LIST_DIR}/3rd_party/flatbuffers/include
${CMAKE_CURRENT_LIST_DIR}/3rd_party/half
${CMAKE_CURRENT_LIST_DIR}/3rd_party/imageHelper
${CMAKE_CURRENT_LIST_DIR}/3rd_party/OpenCLHeaders/
)
include_directories(${MNN_INCLUDES})
2019-12-27 22:16:57 +08:00
set(MNN_OBJECTS_TO_LINK "")
set(MNN_TARGETS "")
# Core
2020-02-26 09:57:17 +08:00
FILE(GLOB MNN_Core_SRC ${CMAKE_CURRENT_LIST_DIR}/source/core/*)
2020-01-17 10:20:15 +08:00
add_library(MNNCore OBJECT ${MNN_Core_SRC})
2019-12-27 22:16:57 +08:00
list(APPEND MNN_OBJECTS_TO_LINK $<TARGET_OBJECTS:MNNCore>)
list(APPEND MNN_TARGETS MNNCore)
if(MNN_SKIPBUILD_GEOMETRY)
target_compile_options(MNNCore PRIVATE -DMNN_SKIPBUILD_GEOMETRY)
2021-04-08 15:34:23 +08:00
endif()
2019-12-27 22:16:57 +08:00
# CV
2020-02-26 09:57:17 +08:00
FILE(GLOB MNN_CV_SRC ${CMAKE_CURRENT_LIST_DIR}/source/cv/*)
2020-01-17 10:20:15 +08:00
add_library(MNNCV OBJECT ${MNN_CV_SRC})
2019-12-27 22:16:57 +08:00
list(APPEND MNN_OBJECTS_TO_LINK $<TARGET_OBJECTS:MNNCV>)
list(APPEND MNN_TARGETS MNNCV)
if(CMAKE_SYSTEM_PROCESSOR MATCHES "(x86_64)|(X86_64)|(x64)|(X64)|(amd64)|(AMD64)|(i686)")
if (APPLE)
add_definitions(-fno-stack-check) # Workaround a Xcode 11.X bug
endif()
endif()
2019-12-27 22:16:57 +08:00
# Math
2020-02-26 09:57:17 +08:00
FILE(GLOB MNN_Math_SRC ${CMAKE_CURRENT_LIST_DIR}/source/math/*)
2020-01-17 10:20:15 +08:00
add_library(MNNMath OBJECT ${MNN_Math_SRC})
2019-12-27 22:16:57 +08:00
list(APPEND MNN_OBJECTS_TO_LINK $<TARGET_OBJECTS:MNNMath>)
list(APPEND MNN_TARGETS MNNMath)
2020-11-05 16:41:56 +08:00
# Transform
IF (NOT MNN_SKIPBUILD_GEOMETRY)
FILE(GLOB_RECURSE MNN_Transform_SRC ${CMAKE_CURRENT_LIST_DIR}/source/shape/* ${CMAKE_CURRENT_LIST_DIR}/source/geometry/*)
add_library(MNNTransform OBJECT ${MNN_Transform_SRC})
2020-11-05 16:41:56 +08:00
list(APPEND MNN_OBJECTS_TO_LINK $<TARGET_OBJECTS:MNNTransform>)
list(APPEND MNN_TARGETS MNNTransform)
2020-11-05 16:41:56 +08:00
ENDIF()
# Utils
FILE(GLOB MNN_Utils_SRC ${CMAKE_CURRENT_LIST_DIR}/source/utils/*)
add_library(MNNUtils OBJECT ${MNN_Utils_SRC})
list(APPEND MNN_OBJECTS_TO_LINK $<TARGET_OBJECTS:MNNUtils>)
list(APPEND MNN_TARGETS MNNUtils)
2019-12-27 22:16:57 +08:00
2021-04-08 15:34:23 +08:00
include(${CMAKE_CURRENT_LIST_DIR}/source/backend/cpu/CMakeLists.txt)
2019-12-27 22:16:57 +08:00
SET(MNN_PUB_HDRS "")
SET(MNN_EXPR_PUB_HDRS "")
2024-07-22 19:51:53 +08:00
set(MNN_EXTRA_HEADERS "")
2019-12-27 22:16:57 +08:00
list(APPEND MNN_PUB_HDRS "${CMAKE_CURRENT_SOURCE_DIR}/include/MNN/MNNDefine.h")
list(APPEND MNN_PUB_HDRS "${CMAKE_CURRENT_SOURCE_DIR}/include/MNN/Interpreter.hpp")
list(APPEND MNN_PUB_HDRS "${CMAKE_CURRENT_SOURCE_DIR}/include/MNN/HalideRuntime.h")
list(APPEND MNN_PUB_HDRS "${CMAKE_CURRENT_SOURCE_DIR}/include/MNN/Tensor.hpp")
list(APPEND MNN_PUB_HDRS "${CMAKE_CURRENT_SOURCE_DIR}/include/MNN/ErrorCode.hpp")
list(APPEND MNN_PUB_HDRS "${CMAKE_CURRENT_SOURCE_DIR}/include/MNN/ImageProcess.hpp")
list(APPEND MNN_PUB_HDRS "${CMAKE_CURRENT_SOURCE_DIR}/include/MNN/Matrix.h")
list(APPEND MNN_PUB_HDRS "${CMAKE_CURRENT_SOURCE_DIR}/include/MNN/Rect.h")
list(APPEND MNN_PUB_HDRS "${CMAKE_CURRENT_SOURCE_DIR}/include/MNN/MNNForwardType.h")
list(APPEND MNN_PUB_HDRS "${CMAKE_CURRENT_SOURCE_DIR}/include/MNN/AutoTime.hpp")
2022-01-04 10:50:40 +08:00
list(APPEND MNN_PUB_HDRS "${CMAKE_CURRENT_SOURCE_DIR}/include/MNN/MNNSharedContext.h")
2019-12-27 22:16:57 +08:00
list(APPEND MNN_EXPR_PUB_HDRS "${CMAKE_CURRENT_SOURCE_DIR}/include/MNN/expr/Expr.hpp")
list(APPEND MNN_EXPR_PUB_HDRS "${CMAKE_CURRENT_SOURCE_DIR}/include/MNN/expr/ExprCreator.hpp")
list(APPEND MNN_EXPR_PUB_HDRS "${CMAKE_CURRENT_SOURCE_DIR}/include/MNN/expr/MathOp.hpp")
list(APPEND MNN_EXPR_PUB_HDRS "${CMAKE_CURRENT_SOURCE_DIR}/include/MNN/expr/NeuralNetWorkOp.hpp")
list(APPEND MNN_EXPR_PUB_HDRS "${CMAKE_CURRENT_SOURCE_DIR}/include/MNN/expr/Optimizer.hpp")
2020-01-17 10:20:15 +08:00
list(APPEND MNN_EXPR_PUB_HDRS "${CMAKE_CURRENT_SOURCE_DIR}/include/MNN/expr/Executor.hpp")
2020-12-15 14:12:35 +08:00
list(APPEND MNN_EXPR_PUB_HDRS "${CMAKE_CURRENT_SOURCE_DIR}/include/MNN/expr/Module.hpp")
list(APPEND MNN_EXPR_PUB_HDRS "${CMAKE_CURRENT_SOURCE_DIR}/include/MNN/expr/NeuralNetWorkOp.hpp")
2022-01-04 10:50:40 +08:00
list(APPEND MNN_EXPR_PUB_HDRS "${CMAKE_CURRENT_SOURCE_DIR}/include/MNN/expr/ExecutorScope.hpp")
list(APPEND MNN_EXPR_PUB_HDRS "${CMAKE_CURRENT_SOURCE_DIR}/include/MNN/expr/Scope.hpp")
2020-01-17 10:20:15 +08:00
2024-07-22 19:51:53 +08:00
# Add Extra Header
IF(MNN_BUILD_OPENCV)
file(GLOB MNN_CV_HDRS ${CMAKE_CURRENT_SOURCE_DIR}/tools/cv/include/cv/*.hpp PARENT_SCOPE)
file(GLOB MNN_CV_IMGHDRS ${CMAKE_CURRENT_SOURCE_DIR}/tools/cv/include/cv/imgproc/*.hpp PARENT_SCOPE)
list(APPEND MNN_EXTRA_HEADERS ${MNN_CV_HDRS})
list(APPEND MNN_EXTRA_HEADERS ${MNN_CV_IMGHDRS})
ENDIF()
2024-12-19 16:20:00 +08:00
IF(MNN_BUILD_AUDIO)
file(GLOB MNN_AUDIO_HDRS ${CMAKE_CURRENT_SOURCE_DIR}/tools/audio/include/audio/*.hpp PARENT_SCOPE)
list(APPEND MNN_EXTRA_HEADERS ${MNN_AUDIO_HDRS})
ENDIF()
2024-07-22 19:51:53 +08:00
IF(MNN_BUILD_LLM)
file(GLOB MNN_LLM_HDRS ${CMAKE_CURRENT_SOURCE_DIR}/transformers/llm/engine/include/llm/*)
list(APPEND MNN_EXTRA_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/transformers/llm/engine/include/llm/llm.hpp)
2025-09-22 23:05:26 +08:00
list(APPEND MNN_EXTRA_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/transformers/llm/engine/include/llm/reranker.hpp)
2024-07-22 19:51:53 +08:00
ENDIF()
2025-02-12 11:14:19 +08:00
IF(MNN_BUILD_DIFFUSION)
file(GLOB MNN_DIFFUSION_HDRS ${CMAKE_CURRENT_SOURCE_DIR}/transformers/diffusion/engine/include/diffusion/*)
list(APPEND MNN_EXTRA_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/transformers/diffusion/engine/include/diffusion/diffusion.hpp)
ENDIF()
2024-07-22 19:51:53 +08:00
2020-07-04 01:21:30 +08:00
2022-01-04 10:50:40 +08:00
# Add Thread dependency
find_package(Threads)
list(APPEND MNN_EXTRA_DEPENDS ${CMAKE_THREAD_LIBS_INIT})
2024-10-14 19:26:28 +08:00
if(WIN32)
if(NOT MSVC)
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fuse-ld=lld-link -lmsvcrt")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=lld-link -lmsvcrt")
2025-03-27 11:19:34 +08:00
else()
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /STACK:8388608")
2024-10-14 19:26:28 +08:00
endif()
endif()
2022-01-04 10:50:40 +08:00
if (NOT APPLE)
if(MNN_OPENMP)
message(STATUS "[*] Checking OpenMP")
find_package(OpenMP)
# For CMake < 3.9, we need to make the target ourselves
if(NOT TARGET OpenMP::OpenMP_CXX)
add_library(OpenMP::OpenMP_CXX IMPORTED INTERFACE)
set_property(TARGET OpenMP::OpenMP_CXX
PROPERTY INTERFACE_COMPILE_OPTIONS ${OpenMP_CXX_FLAGS})
# Only works if the same flag is passed to the linker; use CMake 3.9+ otherwise (Intel, AppleClang)
set_property(TARGET OpenMP::OpenMP_CXX
PROPERTY INTERFACE_LINK_LIBRARIES ${OpenMP_CXX_FLAGS} Threads::Threads)
endif()
# TODO: Don't pollute global CFLAGS
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${OpenMP_SHARED_LINKER_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
2020-11-05 16:41:56 +08:00
if (MSVC)
set(OpenMP_C_FLAGS "/openmp ${OpenMP_C_FLAGS}")
set(OpenMP_CXX_FLAGS "/openmp ${OpenMP_CXX_FLAGS}")
endif()
2020-07-04 01:21:30 +08:00
list(APPEND MNN_EXTRA_DEPENDS OpenMP::OpenMP_CXX)
endif()
endif()
2020-11-05 16:41:56 +08:00
if ((NOT MSVC) AND MNN_HIDDEN)
2020-01-17 10:20:15 +08:00
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility-inlines-hidden -fvisibility=hidden")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden")
2025-01-22 14:47:50 +08:00
set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -fvisibility=hidden")
if (NOT APPLE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fomit-frame-pointer -funwind-tables")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fomit-frame-pointer -funwind-tables")
endif()
2020-01-17 10:20:15 +08:00
endif()
2020-11-05 16:41:56 +08:00
if (NOT MSVC)
2025-04-28 11:38:44 +08:00
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstrict-aliasing -ffunction-sections -fdata-sections -fno-rtti -fno-exceptions ")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fstrict-aliasing -ffunction-sections -fdata-sections ")
2023-06-16 09:42:45 +08:00
else()
2024-11-18 14:37:45 +08:00
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /fp:precise")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /fp:precise")
endif()
2019-12-27 22:16:57 +08:00
2020-01-17 10:20:15 +08:00
# Metal
2020-03-25 20:48:47 +08:00
list(APPEND MNN_DEPS MNN)
# Plugin
if(MNN_WITH_PLUGIN)
add_definitions(-DMNN_WITH_PLUGIN)
include(${CMAKE_CURRENT_LIST_DIR}/source/plugin/CMakeLists.txt)
endif()
2020-11-05 16:41:56 +08:00
# Metal
if(MNN_METAL AND APPLE)
[MNN:Sync] Sync internal github Commits: 8148ae75c 弗人 bugfix 14cb8ec7f 弗人 [Converter:Bugfix] bugfix for onnx depthwise convtranspose 476fbcd90 雁行 [MNN:Feature] Open AVX cast and bugfix for contentCFG. 5e26b9fd3 雁行 [Test:Feature] Add android test. 37e147b25 雁行 [MNN:Bugfix] Bugfix for floordiv. 144c185f5 tianbu.xsw hangxing fix hiai b4fd429d6 tianbu.xsw updateCacheFile bugfix -- update cache size d4ba572a8 雁行 [MNN:Bugfix] Support int8 in AVX2 and some Bugfix. 43061f07e xiaying [MNN:Bugfix] Fix bug for module mode run part of model 398cc5ab6 tianhang.yth refactor demo 736380600 xiaying [Express:Bugfix] Fix memory leak for copy branch b8dab0a27 tianhang.yth MNNFloat2Int8 sizeQuad=0 crash fix 94b95bfed ghz [BugFix]1.Better method for fast pack valid check 6a921f85e xiaying [Converter:Bugfix] Fix bug for Fuseconsttosubgraph 5f77ae889 tianhang.yth numThread bugfix a807ef879 tianhang.yth add createSession(configs, runtimeinfo) API, add pymnn demo, pymnn logcat bugfix ad05409d3 xiaying [MNN:Bugfix] Fix bug for StaticModule's sizecompute overflow, add error print for module mode 9d81b8299 xiaying [MNN:Bugfix] Fix bug for Unique op for output size = 1 03b15e9af xiaying [Test:Feature] Add MatMulBConst Test, Fix bug for single Convert c944a76ee tianhang.yth add auto backend and getSessionInfo @tianbu 91fa7267b ghz [BugFix]1.fix the error in eP check bf0041f77 ghz [BugFix]1.Fix the logic error in eP check. 2.Fix the sp align error 693871672 雁行 [CPU:Bugfix] rm adrp instruction for clang compiler bug. 1b8f6b3d8 ghz 1.Fix the wronly use of r13 in arm32 version. 2.Fix the missing callee register save and restore process. feb7ecc4c 弗人 modify log of python offline quant 040c04811 ghz [BufFix]1.replace platform-related regs. 2.fix the same problem in arm32 version 609f37db8 弗人 add log for python quant, python convert 5511dd30a ghz [BugFix]1.Add testcases in SparseConv to check all functional code branch. 2. Fix the bug in "MNNPackC4ForMatMul_A.S" in arm64, which is caused by the missing check of eReal parameter. a93ff9280 tianhang.yth add tf.Unique op support 9729ff773 allen.lk [Bugfix] Fix one arm32 instruction syntax that clang works but gcc DOES NOT work. use index instruction instead. 297c1ad14 雁行 [Expr:Bugfix] bugfix for tensor content used by shape compute. ef8c369e3 弗人 catch exception 07c2dd670 弗人 add dependence to setup, base64 encode url, add time log 177e590c1 弗人 [Python:Feature] add aliyun log for python quant tool 40a7928cf allen.lk [Debug:Sparse] 1.Add group parameter in torchscript converter. 2. Stop split running to avoid memory corruption when check failed in TransformGroupConvolution 3. fix Op split issue in TransformGroupConvolution 3bdea84a1 allen.lk [Debug:Sparse] Fix and warning one kind of segmentfault cause by memory corruption when resize ConvolutionWinograd. Avoid to use some registers as arm restriction. c3c6fbdbd allen.lk [Debug:Sparse] Fix and warning one kind of segmentfault cause by memory corruption when resize ConvolutionWinograd. Avoid to use some registers as arm restriction. bc590eee4 雁行 [Converter:Bugfix] bugfix for onnx instancenormalization convert. d8918593f tianhang.yth add auto backend and getSessionInfo @tianbu 83a198ed7 杭行 update d0dd3e09b 杭行 update 99540202e xiaying [Converter:Optimize] Opt the tensor convert insert 333d8db82 allen.lk [Debug:Sparse] Fix All platform-register r9 / x18 issue on arm32 and arm64. db5994672 杭行 merge 6293de7b8 tianbu.xsw fix pymnn updateCacheFile 5c2e11cb1 tianbu.xsw do updateCache in createSession 6e7641ff4 tianbu.xsw do not limit cacheFile for a model 5287a65e4 tianbu.xsw bugfix 52ba53a91 tianbu.xsw revert pymnn api 60284d830 tianbu.xsw bugfix 6d8077490 tianbu.xsw rename updateCacheFile api params 3cb172710 tianhang.yth updateCacheFile API size default value is 0 c5b69aabf tianbu.xsw updateCacheFile python api fix 5d5da7aa5 tianbu.xsw reflector code 5707877a4 雁行 [MNN:Speed] Speedup for softmax in x86 and arm. 2a211825c tianbu.xsw reflector code for updateCacheFile 76db3a835 tianbu.xsw [Cache Feature]: Add updateCacheFile API for increment cache b06b0fd43 allen.lk [Debug:Sparse] Fix and warning one kind of segmentfault cause by memory corruption when resize ConvolutionWinograd. Avoid to use some registers as arm restriction. e68bfa495 雁行 [Converter:Feature] Add UUID when model convert. a9cb935dc xiaying [MNN:Speed] Support c4nhwc for more fastblit 019f40353 xiaying [Converter:Refractor] Reduce memory used by MNNConvert(bert from 5G -> 1G) d2a6d3d05 xiaying [MNN:Bugfix] Fix bug for identity output not find 604d0801b xiaying [Converter:Bugfix] Fix bug for FuseGeLu 4bada2367 xiaying [MNN:Refractor] SegmentMean rewrite as segment 82070e708 xiaying [MNN:Bugfix] Fix bug for GeometryBinary e8ea4266e xiaying Fix bug for ShapeTensorConvert compute for dim = 1 error 1f1cf1991 xiaying [Tools:Bugfix] Fix system compability for fastTestOnnx 6f422efe2 xiaying [Tools:Bugfix] Remove color for checkDir for easy to dump 968f7ec88 xiaying [MNN:Speed] Support turn broadcast binary to loop 3e7aaf46f xiaying [MNN:Refractor] Set Convolution1x1Strassen support variable input/output ptr 1f65ab163 xiaying [MNN:Bugfix] Fix bug for mini mnn can't convert model d65953d47 xiaying [MNN:Bugfix] Fix bug for armv7a - android-14 + ARM82 8b68be45c xiaying [MNN:Feature] Add segment 8a8f264f5 xiaying [Vulkan:Bugfix] Remove unuseful print 025bb0fda xiaying [Converter:Bugfix] Fix bug for oneof don't support 43900251e tianbu.xsw enable setCacheFile python API ebfb05c74 tianbu.xsw [Metal Feature] support metallib obtain from walle transfer task 9665c0a79 弗人 add check for path in json file c66fef224 xiaying [Converter:Bugfix] Fix bug for oneof don't support 42f192852 xiaying [MNN:Bugfix] Fix bug for not set output / saveTensor into origin Schedule's outputs 1b95354ff 雁行 [Feature]: Support shape compute for SetDiff1D, and null input for Prod. 83966d043 xiaying [Test:Feature] Add test for static module 42d1be933 xiaying [Converter:Bugfix] Fix bug for mnn convert and static model add more outputs for origin model 9067531c3 xiaying [Converter:Refractor] formatLicence 99558bed9 xiaying [Converter:Bugfix] Count the op for unuseful and controlflow 4f6da0fa7 allen.lk [Feature:GRUMultiOutput] fix multi output dimension type c6b219bce xiaying [Converter:Feature] Turn torch converter to object dd4e68a37 xiaying [Converter:Feature] Support dump supported ops 80b6a60a3 xiaying [Converter:Info] If has output name, print output name instead of computed 015278fc3 xiaying [MNN:Refractor] Revert IfModule's debug info 23ac967c4 xiaying Don't transform for multi-input convolution/deconvolution b02b0d4de xiaying Fix bug for multi-input for conv1d 254d8b1d4 xiaying Fix bug for Conv1dSqueezeMove for multi input convolution 1d d47d0b9ca xiaying Fix bug for CPURaster's fuse nc4hw4 357c5bd33 xiaying Fix ConvBiasAdd for conv's inputs op > 1 55b1f0c9c xiaying [Converter:Bugfix] Don't transform for multi-input convolution/deconvolution 1902a30f5 xiaying [Converter:Bugfix] Fix bug for Conv1dSqueezeMove for multi input convolution 1d c23fe617b xiaying [MNN:Bugfix] Fix bug for multi-input for conv1d 8ff018426 xiaying [MNN:Bugfix] Fix bug for CPURaster's fuse nc4hw4 d4e8cd602 xiaying [Converter:Bugfix] Fix ConvBiasAdd for conv's inputs op > 1 846266b42 tianbu.xsw return when program and tune both nullptr fd67c76a9 xiaying [Converter:Bugfix] DepthwiseConvWeightMerge only valid for tflite e77a242c4 xiaying [Converter:Feature] Support tflite's half pixel be054c377 tianbu.xsw [OpenCL Bugfix] do not rewrite cache when binary program is produced 51e65aa35 xiaying [Converter:Feature] Support tflite for fp16 and multi-input convolution 1ccdfdeb5 tianbu.xsw redefine svm macro name 31234d372 tianbu.xsw [OpenCL SVM] add macro for only use wrapper d739e35da xiaying [MNN:Bugfix] Fix compile bug for grid op 24ab13c79 Joker feat(arm82): add GridSample op support in arm82 backend, AVX(by xiaying) 7b142978e xiaying [AVX512:Speed] Optimize for e <= 8 5f6febe7b tianbu.xsw code refactor 998d91b57 xiaying [Express:Speed] Merge submodule for speed 22c89146f tianhang.yth fix alpha div by zero bug and arm server compile bug 8f829a170 tianbu.xsw [OpenCL Pad] unify conv/deconv pad computing 4a28f603e xiaying [Express:Speed] Shared Const for All Submodule c74cf28f3 xiaying [MNN:Refractor] Seperate Const init and schedule 2a1eebb7a xiaying [Tools:Bugfix] Fix bug for modelTest.py count size 72f04008c xiaying [MNN:Refractor] Delete unuseful const op 1e735d03c xiaying [Converter:Bugfix] Fix bug for static module gen 4dfadbc6e xiaying [MNN:Refractor] Rewrite const init mode 1fcf0417a xiaying [MNN:Bugfix] Fix bug for deconvolutin multi-input for multi-batch 41d429cfd xiaying [Train:Bugfix] Revert convert NCHW for mnistTrain f947a5f01 xiaying [Test:Feature] Add testTrain dad59b6f6 tianbu.xsw move realize code from Backend.hpp to Tensor.cpp cf4473ad1 xiaying [Train:Bugfix] Support pad for GeometryPoolGrad 91ab13734 xiaying [MNN:Bugfix] Fix compile bug for avx512 742e80f47 xiaying [MNN:Refractor] Opt the logic for checknan judge 12543b841 xiaying [ARM82:Bugfix] Fix compile bug for ios 3a2b0a49f xiaying [ARM82:Speed] Opt Pack / Unpack for armv8 c0f1995cd xiaying [ARM82:Speed] Opt MNNPackC8FP16 and MNNUnpackC8FP16 by asm e0fc77dcf xiaying [MNN:Speed] Fix bug for DeconvolutionWithStride for C4HW4, open it 584bec578 xiaying [MNN:Bugfix] Fix bug for format set error for onnx d5bd4148d xiaying [MNN:Bugfix] Fix bug for format set error for onnx b00265841 xiaying [MNN:Bugfix] Fix bug for SparseConvolutionTiledExecutor bb09188ac xiaying [Test:Bugfix] Fix bug for run into sparse auto 426d1babd xiaying [MNN:Refractor] Small bugfix for Group convolution and pack 7d0ea1c46 tianbu.xsw [testModel Feature] support testModel.out input resize 4169c54ce xiaying [MNN:Bugfix] Fix bug for checkNAN for origin 412a82222 xiaying [Test:Bugfix] Fix bug for CheckNAN's error of matmul 319b1d425 xiaying [MNN:Bugfix] Fix bug for multi-batch for ConvInt8 050b728a6 xiaying [Test:Bugfix] Use NCHW for ConvInt8Test 7db3423a1 xiaying [OpenCL:Bugfix] Fix bug for opencl::image,opencl::buffer for C4HW4 adcec6a7f xiaying [Vulkan:Bugfix] Fix bug for invalid tensor size limit d2a7cf4e9 xiaying [Vulkan:Bugfix] Fix bug for onCopyBuffer of nc4hw4 557bebdd3 xiaying [MNN:Bugfix] Fix bug for BF16-ARM32 bbe186649 tianbu.xsw [Update AUTO mode]: fix MNN_FORWARD_AUTO choose priority 6deb23439 xiaying [MNN:Bugfix] Fix bug for GeometryBinary don't care about NC4HW4 same size b137590e4 xiaying [MNN:Bugfix] Fix bug for GeometryBinary don't care about NC4HW4 same size 7003558ea xiaying [Converter:Bugfix] Fix bug for onnx pad for serveral case b5f8cae5a xiaying [Converter:Bugfix] Fix bug for onnx pad for serveral case 29b09e125 xiaying [MNN:Bugfix] Fix bug for arm64-bf16 42ce00770 xiaying [MNN:Bugfix] Fix bug for ARM64 - float a2d89fc18 雁行 [Converter:Feature] Support Binary Unary for Torch. 7f1c0deb1 xiaying [MNN:Bugfix] Fix bug for Raster for Int8 8335a6f18 tianbu.xsw [OpenCL Shared Memory] modify data_format method b359e031b xiaying [ARM82:Bugfix] Fix bug for arm82 and speed up pack / unpack c8 24bf3fc88 雁行 [Convert:Feature] Support LayerNormFuse without gamma beta. 3e629624b xiaying [MNN:Bugfix] Fix bug for float - armv7a 2b7908ec7 tianbu.xsw modify workItemSize 3cee0d413 xiaying [MNN:Bugfix] test wrong clear 9cbbfb998 xiaying [MNN:Bugfix] fix compile bug for c++ < 14 2d7a44484 xiaying [MNN:Bugfix] fix compile bug for c++ < 14 eb7d0cb53 xiaying [Test:Bugfix] Don't test for NC4HW4 directly 7b40ca8d1 xiaying [MNN:Bugfix] Fix bug for ConvolutionGroup 2694d8a91 xiaying [MNN:Bugfix] Fix bug for CPUGridSample f89af60f6 xiaying [MNN:Bugfix] Fix compile bug for arm a151abcdd xiaying [MNN:Bugfix] Fix bug for convert for int8 / int16 b254dbe61 雁行 [MNN:Bugfix] Bugfix for Conv onClone. d08150631 xiaying [MNN:Bugfix] Fix bug for fast rcnn e5568a0df xiaying [MNN:Bugfix] Fix bug for CPURaster treat NC4HW4 fast blit 128318933 雁行 [Raster:Bugfix] bugfix for Raster merge onResize. 03caacbea xiaying [MNN:Bugfix] fix bug for CPUDeconvolution and Convolution1x1Strassen for iw != ow e1e3c245c xiaying [MNN:Bugfix] Fix bug for ConvolutionWinograd 2524cbc6d xiaying [MNN:Bugfix] Fix bug for CPUSoftmax 44ec79b8f xiaying [MNN:Bugfix] Fix bug for CPUConvolutionDepthwise / Scale / DeconvolutionDW 21ae956ce xiaying [MNN:Bugfix] Fix bug for Multi-Batch-TiledExecutor 09a5069c7 xiaying [MNN:Speed] Add offset for src and dst 6776c6784 xiaying [MNN:Bugfix] Fix bug for trainable model cc83ae30b xiaying [MNN:Bugfix] Fix bug for trainable model
2021-07-29 11:46:59 +08:00
target_compile_options(MNNCore PRIVATE -DMNN_METAL_ENABLED=1)
2020-11-05 16:41:56 +08:00
include(${CMAKE_CURRENT_LIST_DIR}/source/backend/metal/CMakeLists.txt)
list(APPEND MNN_TARGETS MNNMetal)
list(APPEND MNN_OBJECTS_TO_LINK $<TARGET_OBJECTS:MNNMetal>)
endif()
# CoreML
IF(MNN_COREML)
add_definitions(-DMNN_COREML_ENABLED=1)
2024-11-18 14:37:45 +08:00
include(${CMAKE_CURRENT_LIST_DIR}/source/backend/coreml/CMakeLists.txt)
2024-05-11 19:17:02 +08:00
2024-11-18 14:37:45 +08:00
list(APPEND MNN_TARGETS MNNCoreML)
list(APPEND MNN_OBJECTS_TO_LINK $<TARGET_OBJECTS:MNNCoreML>)
find_library(COREML CoreML)
find_library(FOUNDATION Foundation)
find_library(METAL Metal)
find_library(VIDEO CoreVideo)
list(APPEND MNN_EXTRA_DEPENDS ${COREML})
list(APPEND MNN_EXTRA_DEPENDS ${FOUNDATION})
list(APPEND MNN_EXTRA_DEPENDS ${METAL})
list(APPEND MNN_EXTRA_DEPENDS ${VIDEO})
ENDIF()
2022-09-30 10:02:52 +08:00
# NNAPI
IF(MNN_NNAPI)
2022-10-30 08:44:24 +08:00
add_definitions(-DMNN_NNAPI_ENABLED=1)
2022-09-30 10:02:52 +08:00
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/source/backend/nnapi/)
list(APPEND MNN_OBJECTS_TO_LINK $<TARGET_OBJECTS:MNN_NNAPI>)
ENDIF()
# QNN
IF(MNN_QNN)
add_definitions(-DMNN_QNN_ENABLED=1)
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/source/backend/qnn/)
list(APPEND MNN_OBJECTS_TO_LINK $<TARGET_OBJECTS:MNN_QNN>)
ENDIF()
2020-01-17 10:20:15 +08:00
# Vulkan
IF(MNN_VULKAN)
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/source/backend/vulkan/)
2019-12-27 22:16:57 +08:00
IF(MNN_SEP_BUILD)
2020-01-17 10:20:15 +08:00
list(APPEND MNN_DEPS MNN_Vulkan)
ELSE()
list(APPEND MNN_TARGETS MNN_Vulkan)
list(APPEND MNN_OBJECTS_TO_LINK $<TARGET_OBJECTS:MNN_Vulkan>)
list(APPEND MNN_EXTRA_DEPENDS ${MNN_VULKAN_LIBS})
2020-01-17 10:20:15 +08:00
ENDIF()
ENDIF()
2021-01-06 16:29:37 +08:00
# oneDNN
IF(MNN_ONEDNN)
target_compile_definitions(MNNCPU PRIVATE "-DMNN_USE_ONEDNN")
add_dependencies(MNNCPU oneDNN)
include(cmake/oneDNN.cmake)
set(ONEDNN_DIR ${CMAKE_CURRENT_LIST_DIR}/3rd_party/oneDNN)
add_library(ONEDNN_COMMON OBJECT IMPORTED)
file(GLOB_RECURSE OBJECT_FILES ${ONEDNN_DIR}/src/common/CMakeFiles/dnnl_common.dir/*.o)
set_property(TARGET ONEDNN_COMMON PROPERTY IMPORTED_OBJECTS ${OBJECT_FILES})
add_library(ONEDNN_CPU OBJECT IMPORTED)
file(GLOB_RECURSE OBJECT_FILES ${ONEDNN_DIR}/src/cpu/CMakeFiles/dnnl_cpu.dir/*.o)
set_property(TARGET ONEDNN_CPU PROPERTY IMPORTED_OBJECTS ${OBJECT_FILES})
add_library(ONEDNN_CPU_X64 OBJECT IMPORTED)
file(GLOB_RECURSE OBJECT_FILES ${ONEDNN_DIR}/src/cpu/x64/CMakeFiles/dnnl_cpu_x64.dir/*.o)
set_property(TARGET ONEDNN_CPU_X64 PROPERTY IMPORTED_OBJECTS ${OBJECT_FILES})
include_directories(${ONEDNN_DIR}/include)
list(APPEND MNN_TARGETS ${ONEDNN_COMMON})
list(APPEND MNN_TARGETS ${ONEDNN_CPU})
list(APPEND MNN_TARGETS ${ONEDNN_CPU_X64})
list(APPEND MNN_OBJECTS_TO_LINK $<TARGET_OBJECTS:ONEDNN_COMMON>)
list(APPEND MNN_OBJECTS_TO_LINK $<TARGET_OBJECTS:ONEDNN_CPU>)
list(APPEND MNN_OBJECTS_TO_LINK $<TARGET_OBJECTS:ONEDNN_CPU_X64>)
ENDIF()
2020-01-17 10:20:15 +08:00
# OpenCL
IF(MNN_OPENCL)
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/source/backend/opencl/)
IF(MNN_SEP_BUILD)
list(APPEND MNN_DEPS MNN_CL)
ELSE()
2023-12-27 17:26:44 +08:00
add_definitions(-DMNN_OPENCL_ENABLED=1)
2020-01-17 10:20:15 +08:00
list(APPEND MNN_TARGETS MNN_CL)
list(APPEND MNN_OBJECTS_TO_LINK $<TARGET_OBJECTS:MNN_CL>)
list(APPEND MNN_EXTRA_DEPENDS ${MNN_OCL_LIBS})
2019-12-27 22:16:57 +08:00
ENDIF()
2020-01-17 10:20:15 +08:00
ENDIF()
# OpenGL
IF(MNN_OPENGL)
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/source/backend/opengl/)
IF(MNN_SEP_BUILD)
list(APPEND MNN_DEPS MNN_GL)
ELSE()
list(APPEND MNN_TARGETS MNN_GL)
list(APPEND MNN_OBJECTS_TO_LINK $<TARGET_OBJECTS:MNN_GL>)
list(APPEND MNN_EXTRA_DEPENDS GLESv3)
list(APPEND MNN_EXTRA_DEPENDS EGL)
ENDIF()
ENDIF()
2020-11-05 16:41:56 +08:00
# CUDA
IF(MNN_CUDA)
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/source/backend/cuda/)
list(APPEND MNN_TARGETS MNN_CUDA)
2021-09-18 15:52:30 +08:00
if (NOT MSVC)
list(APPEND MNN_OBJECTS_TO_LINK $<TARGET_OBJECTS:MNN_CUDA>)
endif()
2020-11-05 16:41:56 +08:00
list(APPEND MNN_EXTRA_DEPENDS ${MNN_CUDA_LIBS})
ENDIF()
2020-01-17 10:20:15 +08:00
# Express
if(NOT MNN_SKIPBUILD_GEOMETRY)
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/express/)
IF(MNN_SEP_BUILD)
list(APPEND MNN_DEPS MNN_Express)
ELSE()
list(APPEND MNN_TARGETS MNN_Express)
list(APPEND MNN_OBJECTS_TO_LINK $<TARGET_OBJECTS:MNN_Express>)
ENDIF()
endif()
2021-01-06 16:29:37 +08:00
2022-01-04 10:50:40 +08:00
# Model Internal. Enable MNN internal features such as model authentication and metrics logging.
2024-11-18 14:37:45 +08:00
if (MNN_INTERNAL AND NOT OHOS) # TODO: support OHOS logging
2022-01-04 10:50:40 +08:00
target_compile_options(MNNCore PRIVATE -DMNN_INTERNAL_ENABLED)
target_compile_options(MNN_Express PRIVATE -DMNN_INTERNAL_ENABLED)
include(${CMAKE_CURRENT_LIST_DIR}/source/internal/logging/CMakeLists.txt)
2022-02-18 11:30:27 +08:00
if(CMAKE_SYSTEM_NAME MATCHES "^Linux")
list(APPEND MNN_EXTRA_DEPENDS "-lcurl -lssl -lcrypto")
endif()
2022-01-04 10:50:40 +08:00
endif()
2021-01-06 16:29:37 +08:00
# Train
2021-04-28 18:02:10 +08:00
IF(MNN_BUILD_TRAIN OR MNN_BUILD_QUANTOOLS)
2021-01-06 16:29:37 +08:00
add_subdirectory(tools/train)
IF(MNN_SEP_BUILD)
list(APPEND MNN_DEPS MNNTrain)
2023-12-04 11:12:20 +08:00
list(APPEND MNN_DEPS MNNTrainUtils)
2021-01-06 16:29:37 +08:00
ELSE()
list(APPEND MNN_TARGETS MNNTrain)
2023-12-04 11:12:20 +08:00
list(APPEND MNN_TARGETS MNNTrainUtils)
2021-01-06 16:29:37 +08:00
list(APPEND MNN_OBJECTS_TO_LINK $<TARGET_OBJECTS:MNNTrain>)
2023-12-04 11:12:20 +08:00
list(APPEND MNN_OBJECTS_TO_LINK $<TARGET_OBJECTS:MNNTrainUtils>)
2021-01-06 16:29:37 +08:00
ENDIF()
ENDIF()
#CodeGen
IF(MNN_BUILD_CODEGEN)
add_definitions(-DMNN_BUILD_CODEGEN)
include(${CMAKE_CURRENT_LIST_DIR}/codegen/CMakeLists.txt)
ENDIF()
2020-01-17 10:20:15 +08:00
2021-02-07 10:45:07 +08:00
# NPU
IF(MNN_NPU)
if (CMAKE_SYSTEM_NAME MATCHES "^Android")
set(HIAI_PATH ${ANDROID_ABI})
endif()
if (OHOS)
set(HIAI_PATH ${OHOS_ARCH})
endif()
2021-02-07 10:45:07 +08:00
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/source/backend/hiai/)
IF(MNN_SEP_BUILD)
list(APPEND MNN_DEPS MNN_NPU)
ELSE()
list(APPEND MNN_TARGETS MNN_NPU)
list(APPEND MNN_OBJECTS_TO_LINK $<TARGET_OBJECTS:MNN_NPU>)
list(APPEND MNN_EXTRA_DEPENDS ${CMAKE_CURRENT_LIST_DIR}/source/backend/hiai/3rdParty/${HIAI_PATH}/libhiai.so)
list(APPEND MNN_EXTRA_DEPENDS ${CMAKE_CURRENT_LIST_DIR}/source/backend/hiai/3rdParty/${HIAI_PATH}/libhiai_ir_build.so)
list(APPEND MNN_EXTRA_DEPENDS ${CMAKE_CURRENT_LIST_DIR}/source/backend/hiai/3rdParty/${HIAI_PATH}/libhiai_ir.so)
2021-02-07 10:45:07 +08:00
ENDIF()
ENDIF()
2020-11-05 16:41:56 +08:00
# TensorRT
IF(MNN_TENSORRT)
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/source/backend/tensorrt/)
list(APPEND MNN_TARGETS MNN_TRT)
list(APPEND MNN_OBJECTS_TO_LINK $<TARGET_OBJECTS:MNN_TRT>)
list(APPEND MNN_EXTRA_DEPENDS ${MNN_TRT_LIBS})
ENDIF()
2025-01-22 14:47:50 +08:00
IF(MNN_BUILD_OPENCV)
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/tools/cv)
IF(MNN_SEP_BUILD)
list(APPEND MNN_DEPS MNNOpenCV)
ELSE()
list(APPEND MNN_TARGETS MNNOpenCV)
list(APPEND MNN_OBJECTS_TO_LINK $<TARGET_OBJECTS:MNNOpenCV>)
ENDIF()
ENDIF()
2024-08-24 15:46:21 +08:00
IF(MNN_BUILD_LLM)
include(${CMAKE_CURRENT_LIST_DIR}/transformers/llm/engine/CMakeLists.txt)
IF(NOT MNN_SEP_BUILD)
list(APPEND MNN_TARGETS llm)
list(APPEND MNN_OBJECTS_TO_LINK $<TARGET_OBJECTS:llm>)
ENDIF()
ENDIF()
2025-01-22 14:47:50 +08:00
IF(MNN_BUILD_DIFFUSION AND MNN_BUILD_OPENCV AND MNN_IMGCODECS)
include(${CMAKE_CURRENT_LIST_DIR}/transformers/diffusion/engine/CMakeLists.txt)
IF(NOT MNN_SEP_BUILD)
list(APPEND MNN_TARGETS diffusion)
list(APPEND MNN_OBJECTS_TO_LINK $<TARGET_OBJECTS:diffusion>)
ENDIF()
ENDIF()
2024-08-24 15:46:21 +08:00
2020-01-17 10:20:15 +08:00
IF(MNN_SEP_BUILD)
2024-07-22 19:51:53 +08:00
add_library(MNN SHARED ${CMAKE_CURRENT_LIST_DIR}/cmake/dummy.cpp ${MNN_OBJECTS_TO_LINK} ${MNN_PUB_HDRS} ${MNN_EXPR_PUB_HDRS} ${MNN_EXTRA_HEADERS})
2020-01-17 10:20:15 +08:00
target_link_libraries(MNN PUBLIC ${MNN_EXTRA_DEPENDS})
ELSE()
IF(MNN_BUILD_SHARED_LIBS)
2024-07-22 19:51:53 +08:00
add_library(MNN SHARED ${CMAKE_CURRENT_LIST_DIR}/cmake/dummy.cpp ${MNN_OBJECTS_TO_LINK} ${MNN_PUB_HDRS} ${MNN_EXPR_PUB_HDRS} ${MNN_EXTRA_HEADERS})
2020-11-05 16:41:56 +08:00
if (WIN32)
foreach(TARGET ${MNN_TARGETS})
target_compile_definitions(${TARGET} PRIVATE "-DBUILDING_MNN_DLL")
target_compile_definitions(${TARGET} INTERFACE "-DUSING_MNN_DLL")
endforeach()
target_compile_definitions(MNN PRIVATE "-DBUILDING_MNN_DLL")
target_compile_definitions(MNN INTERFACE "-DUSING_MNN_DLL")
endif()
2020-01-17 10:20:15 +08:00
ELSE()
2024-07-22 19:51:53 +08:00
add_library(MNN STATIC ${CMAKE_CURRENT_LIST_DIR}/cmake/dummy.cpp ${MNN_OBJECTS_TO_LINK} ${MNN_PUB_HDRS} ${MNN_EXPR_PUB_HDRS} ${MNN_EXTRA_HEADERS})
2020-01-17 10:20:15 +08:00
ENDIF()
target_link_libraries(MNN PUBLIC ${MNN_EXTRA_DEPENDS})
2019-12-27 22:16:57 +08:00
ENDIF()
2020-11-05 16:41:56 +08:00
if (MSVC)
target_link_options(MNN PRIVATE "/IGNORE:4049,4217")
2021-09-18 15:52:30 +08:00
if (MNN_CUDA)
if (MNN_BUILD_SHARED_LIBS)
target_link_options(MNN PRIVATE "/WHOLEARCHIVE:$<TARGET_FILE:MNN_CUDA>")
else()
add_custom_command(
TARGET MNN
POST_BUILD
COMMAND lib.exe ARGS /OUT:$<TARGET_FILE:MNN> $<TARGET_FILE:MNN> $<TARGET_FILE:MNN_CUDA>
)
endif()
endif()
endif()
2021-01-06 16:29:37 +08:00
if (MNN_ONEDNN)
add_dependencies(MNN ONEDNN_COMMON ONEDNN_CPU ONEDNN_CPU_X64)
endif()
2020-01-06 13:55:54 +08:00
2019-12-27 22:16:57 +08:00
if(APPLE)
IF(MNN_AAPL_FMWK)
2020-01-17 10:20:15 +08:00
set_target_properties(MNN PROPERTIES FRAMEWORK TRUE)
set_target_properties(MNN PROPERTIES
2019-12-27 22:16:57 +08:00
MACOSX_FRAMEWORK_IDENTIFIER com.alibaba.MNN
MACOSX_FRAMEWORK_SHORT_VERSION_STRING ${MNN_VERSION}
MACOSX_FRAMEWORK_BUNDLE_VERSION ${MNN_VERSION}
2019-12-27 22:16:57 +08:00
XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "iPhone Developer"
)
ENDIF()
IF(MNN_METAL)
2020-01-17 10:20:15 +08:00
find_library(FOUNDATION Foundation REQUIRED)
target_link_libraries(MNN PUBLIC ${FOUNDATION})
2019-12-27 22:16:57 +08:00
find_library(METAL Metal REQUIRED)
target_link_libraries(MNN PUBLIC ${METAL})
2020-11-05 16:41:56 +08:00
find_library(GRAPHIC CoreGraphics)
target_link_libraries(MNN PUBLIC ${GRAPHIC})
2019-12-27 22:16:57 +08:00
ENDIF()
2019-04-17 10:49:11 +08:00
endif()
if (NOT MNN_SKIPBUILD_GEOMETRY)
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/tools/converter)
endif()
2022-02-18 11:30:27 +08:00
IF(WIN32 AND MNN_BUILD_CONVERTER AND MNN_BUILD_SHARED_LIBS)
# Because of dllimport/dllexport, we merge MNN and MNNConvertDeps together, which depend protobuf
target_link_libraries(MNN PUBLIC ${Protobuf_LIBRARIES})
ENDIF()
# Merge MNN/MNNExpress/MNNOpenCV and other backends into one .lib/.dll on Windows
2025-01-22 14:47:50 +08:00
2024-12-19 16:20:00 +08:00
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/tools/audio)
IF(MNN_BUILD_AUDIO AND NOT MNN_SEP_BUILD)
IF(MSVC)
target_compile_definitions(MNNAudio PRIVATE "-DBUILDING_MNN_DLL" INTERFACE "-DUSING_MNN_DLL")
ENDIF()
target_sources(MNN PRIVATE $<TARGET_OBJECTS:MNNAudio>)
ENDIF()
2024-08-24 15:46:21 +08:00
2024-07-04 11:53:45 +08:00
2020-01-17 10:20:15 +08:00
if(CMAKE_SYSTEM_NAME MATCHES "^Linux")
# Using -pthread, needed by thread-safe implemention of glibc, is better than only using -lpthread
# https://stackoverflow.com/questions/23250863/difference-between-pthread-and-lpthread-while-compiling
target_link_libraries(MNN PUBLIC -pthread dl)
2020-01-17 10:20:15 +08:00
elseif(CMAKE_SYSTEM_NAME MATCHES "^Android")
2020-12-15 14:12:35 +08:00
target_link_libraries(MNN PUBLIC log m)
2019-04-17 10:49:11 +08:00
else()
endif()
if (NOT MNN_BUILD_SHARED_LIBS)
2024-08-24 15:46:21 +08:00
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
# Static-link will not replace thread-related weak symbol in glibc with strong symbol
# in pthread library, so we need use --whole-archive to pthread
# https://stackoverflow.com/questions/35116327/when-g-static-link-pthread-cause-segmentation-fault-why
if(CMAKE_SYSTEM_NAME MATCHES "^Linux")
set(MNN_DEPS -Wl,--whole-archive ${MNN_DEPS} -lpthread -Wl,--no-whole-archive)
else()
2024-08-31 00:12:57 +08:00
if(APPLE)
set(MNN_DEPS -Wl,-force_load ${MNN_DEPS})
else()
set(MNN_DEPS -Wl,--whole-archive ${MNN_DEPS} -Wl,--no-whole-archive)
2024-08-31 00:12:57 +08:00
endif()
endif()
endif()
endif()
2019-12-27 22:16:57 +08:00
list(APPEND MNN_TARGETS MNN)
list(REMOVE_ITEM MNN_TARGETS MNN)
IF(MNN_BUILD_DEMO)
2019-12-27 22:16:57 +08:00
include(${CMAKE_CURRENT_LIST_DIR}/demo/exec/CMakeLists.txt)
ENDIF()
2025-01-22 14:47:50 +08:00
IF(MNN_BUILD_TOOLS)
2019-12-27 22:16:57 +08:00
include(${CMAKE_CURRENT_LIST_DIR}/tools/cpp/CMakeLists.txt)
ENDIF()
IF(MNN_BUILD_TEST)
2019-12-27 22:16:57 +08:00
include(${CMAKE_CURRENT_LIST_DIR}/test/CMakeLists.txt)
ENDIF()
IF(MNN_BUILD_BENCHMARK)
2019-12-27 22:16:57 +08:00
include(${CMAKE_CURRENT_LIST_DIR}/benchmark/CMakeLists.txt)
ENDIF()
IF(MNN_BUILD_QUANTOOLS)
2019-12-27 22:16:57 +08:00
include(${CMAKE_CURRENT_LIST_DIR}/tools/quantization/CMakeLists.txt)
ENDIF()
IF(MNN_EVALUATION)
2019-12-27 22:16:57 +08:00
include(${CMAKE_CURRENT_LIST_DIR}/tools/evaluation/CMakeLists.txt)
ENDIF()
2019-12-27 22:16:57 +08:00
# Install headers
IF(CMAKE_SYSTEM_NAME MATCHES "^Android" AND NOT MNN_BUILD_FOR_ANDROID_COMMAND)
IF(NOT NATIVE_INCLUDE_OUTPUT)
set(NATIVE_INCLUDE_OUTPUT ".")
ENDIF()
2019-04-17 10:49:11 +08:00
set(MNN_INCLUDE_OUTPUT ${NATIVE_INCLUDE_OUTPUT}/MNN)
add_custom_command(
2019-12-27 22:16:57 +08:00
TARGET MNN
POST_BUILD
COMMAND ${CMAKE_COMMAND}
-E make_directory "${MNN_INCLUDE_OUTPUT}/"
)
2019-12-27 22:16:57 +08:00
add_custom_command(
TARGET MNN
POST_BUILD
COMMAND ${CMAKE_COMMAND}
-E make_directory "${MNN_INCLUDE_OUTPUT}/expr/"
)
2019-12-27 22:16:57 +08:00
FOREACH(header ${MNN_PUB_HDRS})
add_custom_command(
TARGET MNN
POST_BUILD
COMMAND ${CMAKE_COMMAND}
ARGS -E copy ${header} "${MNN_INCLUDE_OUTPUT}/"
)
ENDFOREACH()
FOREACH(header ${MNN_EXPR_PUB_HDRS})
add_custom_command(
TARGET MNN
POST_BUILD
COMMAND ${CMAKE_COMMAND}
ARGS -E copy ${header} "${MNN_INCLUDE_OUTPUT}/expr/"
)
ENDFOREACH()
ELSEIF(NOT APPLE)
INSTALL(FILES ${MNN_PUB_HDRS} DESTINATION include/MNN/)
INSTALL(FILES ${MNN_EXPR_PUB_HDRS} DESTINATION include/MNN/expr/)
install(TARGETS MNN
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
RUNTIME DESTINATION bin
2019-12-27 22:16:57 +08:00
)
ELSE()
install(TARGETS MNN
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
FRAMEWORK DESTINATION /Library/Frameworks/
)
2024-07-22 19:51:53 +08:00
IF(MNN_BUILD_OPENCV)
if (NOT MNN_AAPL_FMWK)
INSTALL(FILES ${MNN_CV_HDRS} DESTINATION include/MNN/cv)
INSTALL(FILES ${MNN_CV_IMGHDRS} DESTINATION include/MNN/cv/imgproc)
endif()
FOREACH(HDR ${MNN_CV_HDRS})
SET_SOURCE_FILES_PROPERTIES(${HDR} PROPERTIES MACOSX_PACKAGE_LOCATION Headers/cv/ )
ENDFOREACH()
FOREACH(HDR ${MNN_CV_IMGHDRS})
SET_SOURCE_FILES_PROPERTIES(${HDR} PROPERTIES MACOSX_PACKAGE_LOCATION Headers/cv/imgproc )
ENDFOREACH()
ENDIF()
2024-12-19 16:20:00 +08:00
IF(MNN_BUILD_AUDIO)
if (NOT MNN_AAPL_FMWK)
INSTALL(FILES ${MNN_AUDIO_HDRS} DESTINATION include/MNN/audio)
endif()
FOREACH(HDR ${MNN_AUDIO_HDRS})
SET_SOURCE_FILES_PROPERTIES(${HDR} PROPERTIES MACOSX_PACKAGE_LOCATION Headers/audio/ )
ENDFOREACH()
ENDIF()
2024-07-22 19:51:53 +08:00
IF(MNN_BUILD_LLM)
if (NOT MNN_AAPL_FMWK)
INSTALL(FILES ${MNN_LLM_HDRS} DESTINATION include/MNN/llm)
endif()
FOREACH(HDR ${MNN_LLM_HDRS})
SET_SOURCE_FILES_PROPERTIES(${HDR} PROPERTIES MACOSX_PACKAGE_LOCATION Headers/llm )
ENDFOREACH()
ENDIF()
2025-02-12 11:14:19 +08:00
IF(MNN_BUILD_DIFFUSION)
if (NOT MNN_AAPL_FMWK)
INSTALL(FILES ${MNN_DIFFUSION_HDRS} DESTINATION include/MNN/diffusion)
endif()
FOREACH(HDR ${MNN_DIFFUSION_HDRS})
SET_SOURCE_FILES_PROPERTIES(${HDR} PROPERTIES MACOSX_PACKAGE_LOCATION Headers/diffusion )
ENDFOREACH()
ENDIF()
2022-02-18 11:30:27 +08:00
if (NOT MNN_AAPL_FMWK)
INSTALL(FILES ${MNN_PUB_HDRS} DESTINATION include/MNN/)
INSTALL(FILES ${MNN_EXPR_PUB_HDRS} DESTINATION include/MNN/expr/)
endif()
2019-12-27 22:16:57 +08:00
FOREACH(HDR ${MNN_EXPR_PUB_HDRS})
SET_SOURCE_FILES_PROPERTIES(${HDR} PROPERTIES MACOSX_PACKAGE_LOCATION Headers/expr/ )
ENDFOREACH()
FOREACH(HDR ${MNN_PUB_HDRS})
SET_SOURCE_FILES_PROPERTIES(${HDR} PROPERTIES MACOSX_PACKAGE_LOCATION Headers/ )
ENDFOREACH()
2020-01-17 10:20:15 +08:00
IF(MNN_METAL)
SET_SOURCE_FILES_PROPERTIES(${CMAKE_CURRENT_BINARY_DIR}/mnn.metallib PROPERTIES MACOSX_PACKAGE_LOCATION Resources/)
ENDIF()
2019-12-27 22:16:57 +08:00
ENDIF()
2022-06-10 10:39:50 +08:00
if (MNN_JNI)
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/source/jni/)
endif()