| 1 | if(CMAKE_TOOLCHAIN_FILE) |
| 2 | set(LIBRARY_OUTPUT_PATH_ROOT ${CMAKE_BINARY_DIR} CACHE PATH "root for library output, set this to change where android libs are compiled to") |
| 3 | # get absolute path, but get_filename_component ABSOLUTE only refer with source dir, so find_file here :( |
| 4 | get_filename_component(CMAKE_TOOLCHAIN_FILE_NAME ${CMAKE_TOOLCHAIN_FILE} NAME) |
| 5 | find_file(CMAKE_TOOLCHAIN_FILE ${CMAKE_TOOLCHAIN_FILE_NAME} PATHS ${CMAKE_SOURCE_DIR} NO_DEFAULT_PATH) |
| 6 | message(STATUS "CMAKE_TOOLCHAIN_FILE = ${CMAKE_TOOLCHAIN_FILE}") |
| 7 | endif() |
| 8 | |
| 9 | if(NOT DEFINED CMAKE_INSTALL_PREFIX) |
| 10 | set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install" CACHE PATH "Installation Directory") |
| 11 | endif() |
| 12 | message(STATUS "CMAKE_INSTALL_PREFIX = ${CMAKE_INSTALL_PREFIX}") |
| 13 | |
| 14 | if(NOT DEFINED NCNN_VERSION) |
| 15 | string(TIMESTAMP NCNN_VERSION "%Y%m%d") |
| 16 | endif() |
| 17 | |
| 18 | set(NCNN_VERSION_MAJOR 1) |
| 19 | set(NCNN_VERSION_MINOR 0) |
| 20 | set(NCNN_VERSION_PATCH ${NCNN_VERSION}) |
| 21 | set(NCNN_VERSION_STRING ${NCNN_VERSION_MAJOR}.${NCNN_VERSION_MINOR}.${NCNN_VERSION_PATCH}) |
| 22 | message(STATUS "NCNN_VERSION_STRING = ${NCNN_VERSION_STRING}") |
| 23 | |
| 24 | cmake_minimum_required(VERSION 2.8.12) |
| 25 | |
| 26 | if(NOT CMAKE_BUILD_TYPE) |
| 27 | set(CMAKE_BUILD_TYPE release CACHE STRING "Choose the type of build" FORCE) |
| 28 | endif() |
| 29 | |
| 30 | if(NOT CMAKE_VERSION VERSION_LESS "3.15") |
| 31 | # enable CMAKE_MSVC_RUNTIME_LIBRARY |
| 32 | cmake_policy(SET CMP0091 NEW) |
| 33 | endif() |
| 34 | |
| 35 | if(POLICY CMP0025) |
| 36 | # reference from https://cmake.org/cmake/help/latest/policy/CMP0025.html |
| 37 | cmake_policy(SET CMP0025 NEW) |
| 38 | endif() |
| 39 | |
| 40 | if(POLICY CMP0057) |
| 41 | # reference from https://cmake.org/cmake/help/latest/policy/CMP0057.html |
| 42 | cmake_policy(SET CMP0057 NEW) |
| 43 | endif() |
| 44 | |
| 45 | project(ncnn) |
| 46 | |
| 47 | if(MSVC AND NOT CMAKE_VERSION VERSION_LESS "3.15") |
| 48 | option(NCNN_BUILD_WITH_STATIC_CRT "Enables use of statically linked CRT for statically linked ncnn" OFF) |
| 49 | if(NCNN_BUILD_WITH_STATIC_CRT) |
| 50 | # cmake before version 3.15 not work |
| 51 | set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>") |
| 52 | endif() |
| 53 | endif() |
| 54 | |
| 55 | option(NCNN_SHARED_LIB "shared library support" OFF) |
| 56 | option(NCNN_ENABLE_LTO "enable link-time optimization" OFF) |
| 57 | option(NCNN_OPENMP "openmp support" ON) |
| 58 | option(NCNN_STDIO "load model from external file" ON) |
| 59 | option(NCNN_STRING "plain and verbose string" ON) |
| 60 | option(NCNN_INSTALL_SDK "install ncnn library and headers" ON) |
| 61 | option(NCNN_SIMPLEOCV "minimal opencv structure emulation" OFF) |
| 62 | option(NCNN_SIMPLEOMP "minimal openmp runtime emulation" OFF) |
| 63 | option(NCNN_SIMPLESTL "minimal cpp stl structure emulation" OFF) |
| 64 | option(NCNN_SIMPLEMATH "minimal cmath" OFF) |
| 65 | option(NCNN_THREADS "build with threads" ON) |
| 66 | option(NCNN_BENCHMARK "print benchmark information for every layer" OFF) |
| 67 | option(NCNN_C_API "build with C api" ON) |
| 68 | option(NCNN_PLATFORM_API "build with platform api candy" ON) |
| 69 | option(NCNN_PIXEL "convert and resize from/to image pixel" ON) |
| 70 | option(NCNN_PIXEL_ROTATE "rotate image pixel orientation" ON) |
| 71 | option(NCNN_PIXEL_AFFINE "warp affine image pixel" ON) |
| 72 | option(NCNN_PIXEL_DRAWING "draw basic figure and text" ON) |
| 73 | option(NCNN_CMAKE_VERBOSE "print verbose cmake messages" OFF) |
| 74 | option(NCNN_VULKAN "vulkan compute support" OFF) |
| 75 | option(NCNN_SIMPLEVK "minimal in-house vulkan loader" ON) |
| 76 | option(NCNN_SYSTEM_GLSLANG "use system glslang library" OFF) |
| 77 | option(NCNN_RUNTIME_CPU "runtime dispatch cpu routines" ON) |
| 78 | option(NCNN_DISABLE_PIC "disable position-independent code" OFF) |
| 79 | option(NCNN_BUILD_TESTS "build tests" OFF) |
| 80 | option(NCNN_COVERAGE "build for coverage" OFF) |
| 81 | option(NCNN_ASAN "build for address sanitizer" OFF) |
| 82 | option(NCNN_BUILD_BENCHMARK "build benchmark" ON) |
| 83 | option(NCNN_PYTHON "build python api" OFF) |
| 84 | option(NCNN_INT8 "int8 inference" ON) |
| 85 | option(NCNN_BF16 "bf16 inference" ON) |
| 86 | option(NCNN_FORCE_INLINE "force inline some function" ON) |
| 87 | |
| 88 | if(ANDROID OR IOS OR NCNN_SIMPLESTL) |
| 89 | option(NCNN_DISABLE_RTTI "disable rtti" ON) |
| 90 | option(NCNN_DISABLE_EXCEPTION "disable exception" ON) |
| 91 | else() |
| 92 | option(NCNN_DISABLE_RTTI "disable rtti" OFF) |
| 93 | option(NCNN_DISABLE_EXCEPTION "disable exception" OFF) |
| 94 | endif() |
| 95 | |
| 96 | if(ANDROID OR IOS OR NCNN_SIMPLESTL OR CMAKE_CROSSCOMPILING) |
| 97 | option(NCNN_BUILD_TOOLS "build tools" OFF) |
| 98 | option(NCNN_BUILD_EXAMPLES "build examples" OFF) |
| 99 | else() |
| 100 | option(NCNN_BUILD_TOOLS "build tools" ON) |
| 101 | option(NCNN_BUILD_EXAMPLES "build examples" ON) |
| 102 | endif() |
| 103 | |
| 104 | if(NCNN_SHARED_LIB) |
| 105 | if(NCNN_ENABLE_LTO) |
| 106 | # enable global link time optimization |
| 107 | cmake_policy(SET CMP0069 NEW) |
| 108 | set(CMAKE_POLICY_DEFAULT_CMP0069 NEW) |
| 109 | include(CheckIPOSupported) |
| 110 | check_ipo_supported(RESULT ipo_supported OUTPUT ipo_supported_output) |
| 111 | if(ipo_supported) |
| 112 | set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE) |
| 113 | else() |
| 114 | message(WARNING "IPO is not supported: ${ipo_supported_output}") |
| 115 | set(NCNN_ENABLE_LTO OFF) |
| 116 | endif() |
| 117 | endif() |
| 118 | endif() |
| 119 | |
| 120 | if(NOT NCNN_STDIO OR NOT NCNN_STRING) |
| 121 | if(NCNN_BUILD_TOOLS) |
| 122 | message(WARNING "NCNN_STDIO or NCNN_STRING disabled, NCNN_BUILD_TOOLS will be turned off.") |
| 123 | set(NCNN_BUILD_TOOLS OFF) |
| 124 | endif() |
| 125 | if(NCNN_BUILD_EXAMPLES) |
| 126 | message(WARNING "NCNN_STDIO or NCNN_STRING disabled, NCNN_BUILD_EXAMPLES will be turned off.") |
| 127 | set(NCNN_BUILD_EXAMPLES OFF) |
| 128 | endif() |
| 129 | if(NCNN_BUILD_BENCHMARK) |
| 130 | message(WARNING "NCNN_STDIO or NCNN_STRING disabled, NCNN_BUILD_BENCHMARK will be turned off.") |
| 131 | set(NCNN_BUILD_BENCHMARK OFF) |
| 132 | endif() |
| 133 | if(NCNN_BUILD_TESTS) |
| 134 | message(WARNING "NCNN_STDIO or NCNN_STRING disabled, NCNN_BUILD_TESTS will be turned off.") |
| 135 | set(NCNN_BUILD_TESTS OFF) |
| 136 | endif() |
| 137 | endif() |
| 138 | |
| 139 | ############################################## |
| 140 | |
| 141 | include(CheckCXXCompilerFlag) |
| 142 | |
| 143 | # gnu inline assembly in clang msvc does not work actually |
| 144 | if(NOT (CMAKE_CXX_COMPILER_ID MATCHES "MSVC" OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND CMAKE_CXX_SIMULATE_ID MATCHES "MSVC" AND CMAKE_CXX_COMPILER_FRONTEND_VARIANT MATCHES "MSVC"))) |
| 145 | check_cxx_source_compiles("int main() { int a = 0; asm volatile(\"\" : \"=r\"(a) : \"0\"(a) : \"memory\"); return 0; }" NCNN_COMPILER_SUPPORT_GNU_INLINE_ASM) |
| 146 | if(NCNN_COMPILER_SUPPORT_GNU_INLINE_ASM) |
| 147 | option(NCNN_GNU_INLINE_ASM "optimize platform with gnu style inline assembly" ON) |
| 148 | else() |
| 149 | message(WARNING "The compiler does not support gnu style inline assembly. NCNN_GNU_INLINE_ASM will be OFF.") |
| 150 | endif() |
| 151 | endif() |
| 152 | |
| 153 | if((IOS AND CMAKE_OSX_ARCHITECTURES MATCHES "arm") |
| 154 | OR (APPLE AND CMAKE_OSX_ARCHITECTURES MATCHES "arm64") |
| 155 | OR (CMAKE_SYSTEM_PROCESSOR MATCHES "^(arm|aarch64)") |
| 156 | OR (CMAKE_CXX_COMPILER_ARCHITECTURE_ID MATCHES "(ARMV7|ARM64)") |
| 157 | OR ((CMAKE_CXX_COMPILER_ID MATCHES "MSVC" OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND CMAKE_CXX_SIMULATE_ID MATCHES "MSVC" AND CMAKE_CXX_COMPILER_FRONTEND_VARIANT MATCHES "MSVC")) AND (${CMAKE_GENERATOR_PLATFORM} MATCHES "^(arm|arm64)"))) |
| 158 | set(NCNN_TARGET_ARCH arm) |
| 159 | |
| 160 | if(APPLE AND CMAKE_OSX_ARCHITECTURES STREQUAL "arm64_32") |
| 161 | set(NCNN_TARGET_ILP32 TRUE) |
| 162 | endif() |
| 163 | |
| 164 | if(CMAKE_SIZEOF_VOID_P EQUAL 4 AND NOT NCNN_TARGET_ILP32) |
| 165 | check_cxx_source_compiles("#include <arm_neon.h>\nint main() { float32x4_t _s, _a, _b; _s = vmlaq_f32(_s, _a, _b); return 0; }" NCNN_COMPILER_SUPPORT_ARM_NEON) |
| 166 | |
| 167 | if(NCNN_COMPILER_SUPPORT_ARM_NEON) |
| 168 | if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC" OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND CMAKE_CXX_SIMULATE_ID MATCHES "MSVC" AND CMAKE_CXX_COMPILER_FRONTEND_VARIANT MATCHES "MSVC")) |
| 169 | set(CMAKE_REQUIRED_FLAGS "/arch:VFPv4") |
| 170 | check_cxx_source_compiles("#include <arm_neon.h>\nint main() { float32x4_t _a; float16x4_t _s = vcvt_f16_f32(_a); return 0; }" NCNN_COMPILER_SUPPORT_ARM_VFPV4) |
| 171 | |
| 172 | unset(CMAKE_REQUIRED_FLAGS) |
| 173 | else() |
| 174 | set(CMAKE_REQUIRED_FLAGS "-mfpu=neon-vfpv4") |
| 175 | check_cxx_source_compiles("#include <arm_neon.h>\nint main() { float32x4_t _a; float16x4_t _s = vcvt_f16_f32(_a); return 0; }" NCNN_COMPILER_SUPPORT_ARM_VFPV4) |
| 176 | |
| 177 | if(NOT NCNN_COMPILER_SUPPORT_ARM_VFPV4) |
| 178 | set(CMAKE_REQUIRED_FLAGS "-mfpu=neon-vfpv4 -mfp16-format=ieee") |
| 179 | check_cxx_source_compiles("#include <arm_neon.h>\nint main() { float32x4_t _a; float16x4_t _s = vcvt_f16_f32(_a); return 0; }" NCNN_COMPILER_SUPPORT_ARM_VFPV4_FP16) |
| 180 | endif() |
| 181 | |
| 182 | unset(CMAKE_REQUIRED_FLAGS) |
| 183 | endif() |
| 184 | endif() |
| 185 | |
| 186 | if(NCNN_COMPILER_SUPPORT_ARM_VFPV4 OR NCNN_COMPILER_SUPPORT_ARM_VFPV4_FP16) |
| 187 | option(NCNN_VFPV4 "optimize armv7 platform with vfpv4" ON) |
| 188 | else() |
| 189 | message(WARNING "The compiler does not support arm vfpv4. NCNN_VFPV4 will be OFF.") |
| 190 | endif() |
| 191 | endif() |
| 192 | |
| 193 | if(CMAKE_SIZEOF_VOID_P EQUAL 8 OR NCNN_TARGET_ILP32) |
| 194 | if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC") |
| 195 | set(CMAKE_REQUIRED_FLAGS "/arch:armv8.0") |
| 196 | check_cxx_source_compiles("#include <arm_neon.h>\nint main() { float32x4_t _a; float16x4_t _s = vcvt_f16_f32(_a); return 0; }" NCNN_COMPILER_SUPPORT_ARM_VFPV4) |
| 197 | |
| 198 | set(CMAKE_REQUIRED_FLAGS "/arch:armv8.2") |
| 199 | check_cxx_source_compiles("#include <arm_neon.h>\nint main() { float16x8_t _s, _a, _b; _s = vfmaq_f16(_s, _a, _b); return 0; }" NCNN_COMPILER_SUPPORT_ARM82_FP16) |
| 200 | |
| 201 | set(CMAKE_REQUIRED_FLAGS "/arch:armv8.2") |
| 202 | check_cxx_source_compiles("#include <arm_neon.h>\nint main() { int32x4_t _s; int8x16_t _a, _b; _s = vdotq_s32(_s, _a, _b); return 0; }" NCNN_COMPILER_SUPPORT_ARM82_DOTPROD) |
| 203 | |
| 204 | set(CMAKE_REQUIRED_FLAGS "/arch:armv8.2") |
| 205 | check_cxx_source_compiles("#include <arm_neon.h>\nint main() { float32x4_t _s; float16x8_t _a, _b; _s = vfmlalq_low_f16(_s, _a, _b); return 0; }" NCNN_COMPILER_SUPPORT_ARM82_FP16FML) |
| 206 | |
| 207 | set(CMAKE_REQUIRED_FLAGS "/arch:armv8.4") |
| 208 | check_cxx_source_compiles("#include <arm_neon.h>\nint main() { float32x4_t _s; bfloat16x8_t _a, _b; _s = vcvt_f32_bf16(vcvt_bf16_f32(vbfmmlaq_f32(_s, _a, _b))); return 0; }" NCNN_COMPILER_SUPPORT_ARM84_BF16) |
| 209 | |
| 210 | set(CMAKE_REQUIRED_FLAGS "/arch:armv8.4") |
| 211 | check_cxx_source_compiles("#include <arm_neon.h>\nint main() { int32x4_t _s; int8x16_t _a, _b; _s = vmmlaq_s32(_s, _a, _b); return 0; }" NCNN_COMPILER_SUPPORT_ARM84_I8MM) |
| 212 | |
| 213 | set(CMAKE_REQUIRED_FLAGS "/arch:armv8.6") |
| 214 | check_cxx_source_compiles("#include <arm_sve.h>\nint main() { svfloat16_t _s, _a, _b; svbool_t bp; _s = svmla_f16_z(bp, _s, _a, _b); return 0; }" NCNN_COMPILER_SUPPORT_ARM86_SVE) |
| 215 | |
| 216 | set(CMAKE_REQUIRED_FLAGS "/arch:armv8.6") |
| 217 | check_cxx_source_compiles("#include <arm_sve.h>\nint main() { svint16_t _s; svint8_t _a, _b; _s = svmlslb_s16(_s, _a, _b); return 0; }" NCNN_COMPILER_SUPPORT_ARM86_SVE2) |
| 218 | |
| 219 | set(CMAKE_REQUIRED_FLAGS "/arch:armv8.6") |
| 220 | check_cxx_source_compiles("#include <arm_sve.h>\nint main() { svfloat32_t _s; svbfloat16_t _a, _b; _s = svbfmmla_f32(_s, _a, _b); return 0; }" NCNN_COMPILER_SUPPORT_ARM86_SVEBF16) |
| 221 | |
| 222 | set(CMAKE_REQUIRED_FLAGS "/arch:armv8.6") |
| 223 | check_cxx_source_compiles("#include <arm_sve.h>\nint main() { svint32_t _s; svint8_t _a, _b; _s = svmmla_s32(_s, _a, _b); return 0; }" NCNN_COMPILER_SUPPORT_ARM86_SVEI8MM) |
| 224 | |
| 225 | set(CMAKE_REQUIRED_FLAGS "/arch:armv8.6") |
| 226 | check_cxx_source_compiles("#include <arm_sve.h>\nint main() { svfloat32_t _s, _a, _b; _s = svmmla_f32(_s, _a, _b); return 0; }" NCNN_COMPILER_SUPPORT_ARM86_SVEF32MM) |
| 227 | |
| 228 | unset(CMAKE_REQUIRED_FLAGS) |
| 229 | elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND CMAKE_CXX_SIMULATE_ID MATCHES "MSVC" AND CMAKE_CXX_COMPILER_FRONTEND_VARIANT MATCHES "MSVC") |
| 230 | set(CMAKE_REQUIRED_FLAGS "/arch:armv8.0") |
| 231 | check_cxx_source_compiles("#include <arm_neon.h>\nint main() { float32x4_t _a; float16x4_t _s = vcvt_f16_f32(_a); return 0; }" NCNN_COMPILER_SUPPORT_ARM_VFPV4) |
| 232 | |
| 233 | set(CMAKE_REQUIRED_FLAGS "/arch:armv8.2 -march=armv8.2-a+fp16") |
| 234 | check_cxx_source_compiles("#include <arm_neon.h>\nint main() { float16x8_t _s, _a, _b; _s = vfmaq_f16(_s, _a, _b); return 0; }" NCNN_COMPILER_SUPPORT_ARM82_FP16) |
| 235 | |
| 236 | set(CMAKE_REQUIRED_FLAGS "/arch:armv8.2 -march=armv8.2-a+dotprod") |
| 237 | check_cxx_source_compiles("#include <arm_neon.h>\nint main() { int32x4_t _s; int8x16_t _a, _b; _s = vdotq_s32(_s, _a, _b); return 0; }" NCNN_COMPILER_SUPPORT_ARM82_DOTPROD) |
| 238 | |
| 239 | set(CMAKE_REQUIRED_FLAGS "/arch:armv8.2 -march=armv8.2-a+fp16fml") |
| 240 | check_cxx_source_compiles("#include <arm_neon.h>\nint main() { float32x4_t _s; float16x8_t _a, _b; _s = vfmlalq_low_f16(_s, _a, _b); return 0; }" NCNN_COMPILER_SUPPORT_ARM82_FP16FML) |
| 241 | |
| 242 | set(CMAKE_REQUIRED_FLAGS "/arch:armv8.4 -march=armv8.4-a+bf16") |
| 243 | check_cxx_source_compiles("#include <arm_neon.h>\nint main() { float32x4_t _s; bfloat16x8_t _a, _b; _s = vcvt_f32_bf16(vcvt_bf16_f32(vbfmmlaq_f32(_s, _a, _b))); return 0; }" NCNN_COMPILER_SUPPORT_ARM84_BF16) |
| 244 | |
| 245 | set(CMAKE_REQUIRED_FLAGS "/arch:armv8.4 -march=armv8.4-a+i8mm") |
| 246 | check_cxx_source_compiles("#include <arm_neon.h>\nint main() { int32x4_t _s; int8x16_t _a, _b; _s = vmmlaq_s32(_s, _a, _b); return 0; }" NCNN_COMPILER_SUPPORT_ARM84_I8MM) |
| 247 | |
| 248 | set(CMAKE_REQUIRED_FLAGS "/arch:armv8.6 -march=armv8.6-a+sve") |
| 249 | check_cxx_source_compiles("#include <arm_sve.h>\nint main() { svfloat16_t _s, _a, _b; svbool_t bp; _s = svmla_f16_z(bp, _s, _a, _b); return 0; }" NCNN_COMPILER_SUPPORT_ARM86_SVE) |
| 250 | |
| 251 | set(CMAKE_REQUIRED_FLAGS "/arch:armv8.6 -march=armv8.6-a+sve2") |
| 252 | check_cxx_source_compiles("#include <arm_sve.h>\nint main() { svint16_t _s; svint8_t _a, _b; _s = svmlslb_s16(_s, _a, _b); return 0; }" NCNN_COMPILER_SUPPORT_ARM86_SVE2) |
| 253 | |
| 254 | set(CMAKE_REQUIRED_FLAGS "/arch:armv8.6 -march=armv8.6-a+sve+bf16") |
| 255 | check_cxx_source_compiles("#include <arm_sve.h>\nint main() { svfloat32_t _s; svbfloat16_t _a, _b; _s = svbfmmla_f32(_s, _a, _b); return 0; }" NCNN_COMPILER_SUPPORT_ARM86_SVEBF16) |
| 256 | |
| 257 | set(CMAKE_REQUIRED_FLAGS "/arch:armv8.6 -march=armv8.6-a+sve+i8mm") |
| 258 | check_cxx_source_compiles("#include <arm_sve.h>\nint main() { svint32_t _s; svint8_t _a, _b; _s = svmmla_s32(_s, _a, _b); return 0; }" NCNN_COMPILER_SUPPORT_ARM86_SVEI8MM) |
| 259 | |
| 260 | set(CMAKE_REQUIRED_FLAGS "/arch:armv8.6 -march=armv8.6-a+sve+f32mm") |
| 261 | check_cxx_source_compiles("#include <arm_sve.h>\nint main() { svfloat32_t _s, _a, _b; _s = svmmla_f32(_s, _a, _b); return 0; }" NCNN_COMPILER_SUPPORT_ARM86_SVEF32MM) |
| 262 | |
| 263 | unset(CMAKE_REQUIRED_FLAGS) |
| 264 | else() |
| 265 | set(CMAKE_REQUIRED_FLAGS "-march=armv8-a") |
| 266 | check_cxx_source_compiles("#include <arm_neon.h>\nint main() { float32x4_t _a; float16x4_t _s = vcvt_f16_f32(_a); return 0; }" NCNN_COMPILER_SUPPORT_ARM_VFPV4) |
| 267 | |
| 268 | set(CMAKE_REQUIRED_FLAGS "-march=armv8.2-a+fp16") |
| 269 | check_cxx_source_compiles("#include <arm_neon.h>\nint main() { float16x8_t _s, _a, _b; _s = vfmaq_f16(_s, _a, _b); return 0; }" NCNN_COMPILER_SUPPORT_ARM82_FP16) |
| 270 | |
| 271 | set(CMAKE_REQUIRED_FLAGS "-march=armv8.2-a+dotprod") |
| 272 | check_cxx_source_compiles("#include <arm_neon.h>\nint main() { int32x4_t _s; int8x16_t _a, _b; _s = vdotq_s32(_s, _a, _b); return 0; }" NCNN_COMPILER_SUPPORT_ARM82_DOTPROD) |
| 273 | |
| 274 | set(CMAKE_REQUIRED_FLAGS "-march=armv8.2-a+fp16fml") |
| 275 | check_cxx_source_compiles("#include <arm_neon.h>\nint main() { float32x4_t _s; float16x8_t _a, _b; _s = vfmlalq_low_f16(_s, _a, _b); return 0; }" NCNN_COMPILER_SUPPORT_ARM82_FP16FML) |
| 276 | |
| 277 | set(CMAKE_REQUIRED_FLAGS "-march=armv8.4-a+bf16") |
| 278 | check_cxx_source_compiles("#include <arm_neon.h>\nint main() { float32x4_t _s; bfloat16x8_t _a, _b; _s = vcvt_f32_bf16(vcvt_bf16_f32(vbfmmlaq_f32(_s, _a, _b))); return 0; }" NCNN_COMPILER_SUPPORT_ARM84_BF16) |
| 279 | |
| 280 | set(CMAKE_REQUIRED_FLAGS "-march=armv8.4-a+i8mm") |
| 281 | check_cxx_source_compiles("#include <arm_neon.h>\nint main() { int32x4_t _s; int8x16_t _a, _b; _s = vmmlaq_s32(_s, _a, _b); return 0; }" NCNN_COMPILER_SUPPORT_ARM84_I8MM) |
| 282 | |
| 283 | set(CMAKE_REQUIRED_FLAGS "-march=armv8.6-a+sve") |
| 284 | check_cxx_source_compiles("#include <arm_sve.h>\nint main() { svfloat16_t _s, _a, _b; svbool_t bp; _s = svmla_f16_z(bp, _s, _a, _b); return 0; }" NCNN_COMPILER_SUPPORT_ARM86_SVE) |
| 285 | |
| 286 | set(CMAKE_REQUIRED_FLAGS "-march=armv8.6-a+sve2") |
| 287 | check_cxx_source_compiles("#include <arm_sve.h>\nint main() { svint16_t _s; svint8_t _a, _b; _s = svmlslb_s16(_s, _a, _b); return 0; }" NCNN_COMPILER_SUPPORT_ARM86_SVE2) |
| 288 | |
| 289 | set(CMAKE_REQUIRED_FLAGS "-march=armv8.6-a+sve+bf16") |
| 290 | check_cxx_source_compiles("#include <arm_sve.h>\nint main() { svfloat32_t _s; svbfloat16_t _a, _b; _s = svbfmmla_f32(_s, _a, _b); return 0; }" NCNN_COMPILER_SUPPORT_ARM86_SVEBF16) |
| 291 | |
| 292 | set(CMAKE_REQUIRED_FLAGS "-march=armv8.6-a+sve+i8mm") |
| 293 | check_cxx_source_compiles("#include <arm_sve.h>\nint main() { svint32_t _s; svint8_t _a, _b; _s = svmmla_s32(_s, _a, _b); return 0; }" NCNN_COMPILER_SUPPORT_ARM86_SVEI8MM) |
| 294 | |
| 295 | set(CMAKE_REQUIRED_FLAGS "-march=armv8.6-a+sve+f32mm") |
| 296 | check_cxx_source_compiles("#include <arm_sve.h>\nint main() { svfloat32_t _s, _a, _b; _s = svmmla_f32(_s, _a, _b); return 0; }" NCNN_COMPILER_SUPPORT_ARM86_SVEF32MM) |
| 297 | |
| 298 | unset(CMAKE_REQUIRED_FLAGS) |
| 299 | endif() |
| 300 | |
| 301 | if(NCNN_COMPILER_SUPPORT_ARM_VFPV4) |
| 302 | option(NCNN_VFPV4 "optimize aarch64 platform with vfpv4" ON) |
| 303 | else() |
| 304 | message(WARNING "The compiler does not support arm vfpv4. NCNN_VFPV4 will be OFF.") |
| 305 | endif() |
| 306 | |
| 307 | if(NCNN_COMPILER_SUPPORT_ARM82_FP16) |
| 308 | option(NCNN_ARM82 "optimize aarch64 platform with armv8.2 fp16" ON) |
| 309 | if(NCNN_COMPILER_SUPPORT_ARM82_DOTPROD) |
| 310 | if(NCNN_ARM82) |
| 311 | option(NCNN_ARM82DOT "optimize aarch64 platform with armv8.2 dotprod" ON) |
| 312 | endif() |
| 313 | else() |
| 314 | message(WARNING "The compiler does not support armv8.2 dotprod. NCNN_ARM82DOT will be OFF.") |
| 315 | endif() |
| 316 | if(NCNN_COMPILER_SUPPORT_ARM82_FP16FML) |
| 317 | if(NCNN_ARM82) |
| 318 | option(NCNN_ARM82FP16FML "optimize aarch64 platform with armv8.2 fp16fml" ON) |
| 319 | endif() |
| 320 | else() |
| 321 | message(WARNING "The compiler does not support armv8.2 fp16fml. NCNN_ARM82FP16FML will be OFF.") |
| 322 | endif() |
| 323 | if(NCNN_COMPILER_SUPPORT_ARM84_BF16) |
| 324 | if(NCNN_ARM82DOT AND NCNN_ARM82FP16FML) |
| 325 | option(NCNN_ARM84BF16 "optimize aarch64 platform with armv8.4 bf16" ON) |
| 326 | endif() |
| 327 | else() |
| 328 | message(WARNING "The compiler does not support armv8.4 bf16. NCNN_ARM86BF16 will be OFF.") |
| 329 | endif() |
| 330 | if(NCNN_COMPILER_SUPPORT_ARM84_I8MM) |
| 331 | if(NCNN_ARM82DOT AND NCNN_ARM82FP16FML) |
| 332 | option(NCNN_ARM84I8MM "optimize aarch64 platform with armv8.4 i8mm" ON) |
| 333 | endif() |
| 334 | else() |
| 335 | message(WARNING "The compiler does not support armv8.4 i8mm. NCNN_ARM84I8MM will be OFF.") |
| 336 | endif() |
| 337 | if(NCNN_COMPILER_SUPPORT_ARM86_SVE) |
| 338 | if(NCNN_ARM84BF16 AND NCNN_ARM84I8MM) |
| 339 | option(NCNN_ARM86SVE "optimize aarch64 platform with armv8.6 sve" ON) |
| 340 | if(NCNN_COMPILER_SUPPORT_ARM86_SVE2) |
| 341 | if(NCNN_ARM86SVE) |
| 342 | option(NCNN_ARM86SVE2 "optimize aarch64 platform with armv8.6 sve2" ON) |
| 343 | endif() |
| 344 | else() |
| 345 | message(WARNING "The compiler does not support armv8.6 sve2. NCNN_ARM86SVE2 will be OFF.") |
| 346 | endif() |
| 347 | if(NCNN_COMPILER_SUPPORT_ARM86_SVEBF16) |
| 348 | if(NCNN_ARM86SVE) |
| 349 | option(NCNN_ARM86SVEBF16 "optimize aarch64 platform with armv8.6 sve bf16" ON) |
| 350 | endif() |
| 351 | else() |
| 352 | message(WARNING "The compiler does not support armv8.6 sve bf16. NCNN_ARM86SVEBF16 will be OFF.") |
| 353 | endif() |
| 354 | if(NCNN_COMPILER_SUPPORT_ARM86_SVEI8MM) |
| 355 | if(NCNN_ARM86SVE) |
| 356 | option(NCNN_ARM86SVEI8MM "optimize aarch64 platform with armv8.6 sve i8mm" ON) |
| 357 | endif() |
| 358 | else() |
| 359 | message(WARNING "The compiler does not support armv8.6 sve i8mm. NCNN_ARM86SVEI8MM will be OFF.") |
| 360 | endif() |
| 361 | if(NCNN_COMPILER_SUPPORT_ARM86_SVEF32MM) |
| 362 | if(NCNN_ARM86SVE) |
| 363 | option(NCNN_ARM86SVEF32MM "optimize aarch64 platform with armv8.6 sve f32mm" ON) |
| 364 | endif() |
| 365 | else() |
| 366 | message(WARNING "The compiler does not support armv8.6 sve f32mm. NCNN_ARM86SVEF32MM will be OFF.") |
| 367 | endif() |
| 368 | endif() |
| 369 | else() |
| 370 | message(WARNING "The compiler does not support armv8.6 sve. NCNN_ARM86SVE will be OFF.") |
| 371 | endif() |
| 372 | else() |
| 373 | message(WARNING "The compiler does not support armv8.2 fp16. NCNN_ARM82 will be OFF.") |
| 374 | endif() |
| 375 | endif() |
| 376 | elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(mips)") |
| 377 | set(NCNN_TARGET_ARCH mips) |
| 378 | |
| 379 | check_cxx_compiler_flag("-mmsa" NCNN_COMPILER_SUPPORT_MIPS_MSA) |
| 380 | |
| 381 | set(CMAKE_REQUIRED_FLAGS "-mloongson-mmi -I${CMAKE_CURRENT_SOURCE_DIR}/src/layer/mips") |
| 382 | check_cxx_source_compiles("#include \"loongson_mmi.h\"\nint main() { int16x4_t _a, _b; int32x2_t _s = __mmi_pmaddhw(_a, _b); return 0; }" NCNN_COMPILER_SUPPORT_LOONGSON_MMI) |
| 383 | |
| 384 | unset(CMAKE_REQUIRED_FLAGS) |
| 385 | |
| 386 | if(NCNN_COMPILER_SUPPORT_MIPS_MSA) |
| 387 | option(NCNN_MSA "optimize mips platform with msa extension" ON) |
| 388 | else() |
| 389 | message(WARNING "The compiler does not support msa extension. NCNN_MSA will be OFF.") |
| 390 | endif() |
| 391 | if(NCNN_COMPILER_SUPPORT_LOONGSON_MMI) |
| 392 | option(NCNN_MMI "optimize mips platform with loongson mmi extension" ON) |
| 393 | else() |
| 394 | message(WARNING "The compiler does not support loongson mmi extension. NCNN_MMI will be OFF.") |
| 395 | endif() |
| 396 | elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(loongarch64|loongarch32)") |
| 397 | set(NCNN_TARGET_ARCH loongarch) |
| 398 | |
| 399 | set(CMAKE_REQUIRED_FLAGS "-mlsx") |
| 400 | check_cxx_source_compiles("#include <lsxintrin.h>\nint main() { __m128 _s, _a, _b, _c; _s = __lsx_vfmadd_s(_a, _b, _c); return 0; }" NCNN_COMPILER_SUPPORT_LOONGARCH_LSX) |
| 401 | |
| 402 | set(CMAKE_REQUIRED_FLAGS "-mlasx") |
| 403 | check_cxx_source_compiles("#include <lasxintrin.h>\nint main() { __m256 _s, _a, _b, _c; _s = __lasx_xvfmadd_s(_a, _b, _c); return 0; }" NCNN_COMPILER_SUPPORT_LOONGARCH_LASX) |
| 404 | |
| 405 | unset(CMAKE_REQUIRED_FLAGS) |
| 406 | |
| 407 | if(NCNN_COMPILER_SUPPORT_LOONGARCH_LSX) |
| 408 | option(NCNN_LSX "optimize loongarch platform with lsx extension" ON) |
| 409 | if(NCNN_COMPILER_SUPPORT_LOONGARCH_LASX) |
| 410 | option(NCNN_LASX "optimize loongarch platform with lasx extension" ON) |
| 411 | else() |
| 412 | message(WARNING "The compiler does not support lasx extension. NCNN_LASX will be OFF.") |
| 413 | endif() |
| 414 | else() |
| 415 | message(WARNING "The compiler does not support lsx extension. NCNN_LSX will be OFF.") |
| 416 | endif() |
| 417 | |
| 418 | elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(riscv)") |
| 419 | set(NCNN_TARGET_ARCH riscv) |
| 420 | |
| 421 | if(CMAKE_SIZEOF_VOID_P EQUAL 8) |
| 422 | set(CMAKE_REQUIRED_FLAGS "-march=rv64gcv") |
| 423 | check_cxx_source_compiles("#include <riscv_vector.h>\nint main() { vfloat32m1_t _s, _w; float _v; size_t vl; _s = vfmacc_vf_f32m1(_s, _v, _w, vl); return 0; }" NCNN_COMPILER_SUPPORT_RVV) |
| 424 | |
| 425 | set(CMAKE_REQUIRED_FLAGS "-march=rv64gcv_zfh") |
| 426 | check_cxx_source_compiles("#include <riscv_vector.h>\nint main() { vfloat16m1_t _s, _w; __fp16 _v; size_t vl; _s = vfmacc_vf_f16m1(_s, _v, _w, vl); return 0; }" NCNN_COMPILER_SUPPORT_RVV_ZFH) |
| 427 | |
| 428 | if(NOT NCNN_COMPILER_SUPPORT_RVV_ZFH) |
| 429 | set(CMAKE_REQUIRED_FLAGS "-march=rv64gcv_zfh_zvfh0p1 -menable-experimental-extensions -D__fp16=_Float16") |
| 430 | check_cxx_source_compiles("#include <riscv_vector.h>\nint main() { vfloat16m1_t _s, _w; __fp16 _v; size_t vl; _s = vfmacc_vf_f16m1(_s, _v, _w, vl); return 0; }" NCNN_COMPILER_SUPPORT_RVV_ZVFH) |
| 431 | endif() |
| 432 | |
| 433 | unset(CMAKE_REQUIRED_FLAGS) |
| 434 | |
| 435 | if(NCNN_COMPILER_SUPPORT_RVV) |
| 436 | option(NCNN_RVV "optimize risc-v platform with v extension" ON) |
| 437 | option(NCNN_RVV_CHECK_VFREDSUM "check compilter about support rvv-intrinsic" ON) |
| 438 | if(NCNN_RVV_CHECK_VFREDSUM) |
| 439 | include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/ncnn_check_rvv_vfredusum.cmake) |
| 440 | endif() |
| 441 | if(NOT (NCNN_COMPILER_SUPPORT_RVV_ZFH OR NCNN_COMPILER_SUPPORT_RVV_ZVFH)) |
| 442 | message(WARNING "The compiler does not support risc-v zfh extension. Upgrading your toolchain is strongly recommended.") |
| 443 | endif() |
| 444 | option(NCNN_RVV_CHECK_PLAIN_SEGMENT "check compilter about rvv segment load/store interface" ON) |
| 445 | if(NCNN_RVV_CHECK_PLAIN_SEGMENT) |
| 446 | set(CMAKE_REQUIRED_FLAGS "-march=rv64gcv") |
| 447 | check_cxx_source_compiles("#include <riscv_vector.h>\nint main() { vfloat32m1_t _s, _w; size_t vl; float src[32]={.0f}; vlseg2e32_v_f32m1(&_s, &_w, src, vl); return 0; }" NCNN_COMPILER_USE_RVV_PLAIN_SEG) |
| 448 | unset(CMAKE_REQUIRED_FLAGS) |
| 449 | endif() |
| 450 | if(NOT NCNN_COMPILER_USE_RVV_PLAIN_SEG) |
| 451 | message(WARNING "The compiler uses tuple types for segment load/store. Upgrading your toolchain is strongly recommended.") |
| 452 | add_definitions(-D__rvv_tuple) |
| 453 | endif() |
| 454 | else() |
| 455 | message(WARNING "The compiler does not support risc-v v extension. NCNN_RVV will be OFF.") |
| 456 | endif() |
| 457 | endif() |
| 458 | elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(powerpc|ppc)") |
| 459 | set(NCNN_TARGET_ARCH powerpc) |
| 460 | |
| 461 | if(NCNN_PPC64LE_VSX) |
| 462 | set(NCNN_TARGET_ARCH x86) |
| 463 | |
| 464 | set(CMAKE_REQUIRED_FLAGS "-DNO_WARN_X86_INTRINSICS -D__SSE2__") |
| 465 | check_cxx_source_compiles("#include <emmintrin.h>\nint main() { return 0; }" NCNN_COMPILER_SUPPORT_PPC64LE_SSE2) |
| 466 | unset(CMAKE_REQUIRED_FLAGS) |
| 467 | |
| 468 | set(CMAKE_REQUIRED_FLAGS "-DNO_WARN_X86_INTRINSICS -D__SSE4_1__") |
| 469 | check_cxx_source_compiles("#include <smmintrin.h>\nint main() { __m128i _v, _a, _b; _v = _mm_packus_epi32(_a, _b); return 0; }" NCNN_COMPILER_SUPPORT_PPC64LE_SSE41) |
| 470 | unset(CMAKE_REQUIRED_FLAGS) |
| 471 | |
| 472 | if(NCNN_COMPILER_SUPPORT_PPC64LE_SSE2) |
| 473 | option(NCNN_VSX_SSE2 "optimize ppc64le platform with sse2 extension" ON) |
| 474 | else() |
| 475 | message(WARNING "The compiler does not support sse2 extension. NCNN_VSX_SSE2 will be OFF.") |
| 476 | endif() |
| 477 | |
| 478 | if(NCNN_COMPILER_SUPPORT_PPC64LE_SSE41) |
| 479 | option(NCNN_VSX_SSE41 "optimize ppc64le platform with sse4.1 extension" ON) |
| 480 | else() |
| 481 | message(WARNING "The compiler does not support sse4.1 extension. NCNN_VSX_SSE41 will be OFF.") |
| 482 | endif() |
| 483 | endif() |
| 484 | elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(xtensa)") |
| 485 | set(NCNN_TARGET_ARCH xtensa) |
| 486 | elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(s390x)") |
| 487 | set(NCNN_TARGET_ARCH s390x) |
| 488 | elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(sw_64)") |
| 489 | set(NCNN_TARGET_ARCH sw_64) |
| 490 | #sw_64 is alpha-like platform |
| 491 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mieee") |
| 492 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mieee") |
| 493 | else() |
| 494 | set(NCNN_TARGET_ARCH x86) |
| 495 | |
| 496 | option(NCNN_SSE2 "optimize x86 platform with sse2 extension" ON) |
| 497 | |
| 498 | if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC") |
| 499 | check_cxx_compiler_flag("/arch:AVX" NCNN_COMPILER_SUPPORT_X86_AVX) |
| 500 | check_cxx_compiler_flag("/arch:AVX" NCNN_COMPILER_SUPPORT_X86_FMA) |
| 501 | check_cxx_compiler_flag("/arch:AVX" NCNN_COMPILER_SUPPORT_X86_XOP) |
| 502 | check_cxx_compiler_flag("/arch:AVX" NCNN_COMPILER_SUPPORT_X86_F16C) |
| 503 | check_cxx_compiler_flag("/arch:AVX2" NCNN_COMPILER_SUPPORT_X86_AVX2) |
| 504 | check_cxx_compiler_flag("/arch:AVX512" NCNN_COMPILER_SUPPORT_X86_AVX512) |
| 505 | |
| 506 | set(CMAKE_REQUIRED_FLAGS "/arch:AVX2") |
| 507 | check_cxx_source_compiles("#include <immintrin.h>\nint main() { __m256i _s, _a, _b; _s = _mm256_dpwssd_epi32(_s, _a, _b); return 0; }" NCNN_COMPILER_SUPPORT_X86_AVX_VNNI) |
| 508 | |
| 509 | set(CMAKE_REQUIRED_FLAGS "/arch:AVX512") |
| 510 | check_cxx_source_compiles("#include <immintrin.h>\nint main() { __m512i _s, _a, _b; _s = _mm512_dpwssd_epi32(_s, _a, _b); return 0; }" NCNN_COMPILER_SUPPORT_X86_AVX512_VNNI) |
| 511 | |
| 512 | set(CMAKE_REQUIRED_FLAGS "/arch:AVX512") |
| 513 | check_cxx_source_compiles("#include <immintrin.h>\nint main() { __m256bh _s; __m512bh _a, _b; _s = _mm512_cvtneps_pbh(_mm512_dpbf16_ps(_mm512_cvtpbh_ps(_s), _a, _b)); return 0; }" NCNN_COMPILER_SUPPORT_X86_AVX512_BF16) |
| 514 | |
| 515 | set(CMAKE_REQUIRED_FLAGS "/arch:AVX512") |
| 516 | check_cxx_source_compiles("#include <immintrin.h>\nint main() { __m512h _s, _a, _b; _s = _mm512_fmadd_ph(_s, _a, _b); __m512 _s2; _s2 = _mm512_cvtxph_ps(_mm512_cvtxps_ph(_s2)); return 0; }" NCNN_COMPILER_SUPPORT_X86_AVX512_FP16) |
| 517 | |
| 518 | unset(CMAKE_REQUIRED_FLAGS) |
| 519 | elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND CMAKE_CXX_SIMULATE_ID MATCHES "MSVC" AND CMAKE_CXX_COMPILER_FRONTEND_VARIANT MATCHES "MSVC") |
| 520 | check_cxx_compiler_flag("/arch:AVX" NCNN_COMPILER_SUPPORT_X86_AVX) |
| 521 | |
| 522 | set(CMAKE_REQUIRED_FLAGS "/arch:AVX -mfma -mf16c") |
| 523 | check_cxx_source_compiles("#include <immintrin.h>\nint main() { __m256 _s, _a, _b; _s = _mm256_fmadd_ps(_a, _b, _s); return 0; }" NCNN_COMPILER_SUPPORT_X86_FMA) |
| 524 | |
| 525 | set(CMAKE_REQUIRED_FLAGS "/arch:AVX -mxop") |
| 526 | check_cxx_source_compiles("#include <x86intrin.h>\nint main() { __m128 _s, _a, _b; _s = _mm_maddd_epi16(_a, _b, _s); return 0; }" NCNN_COMPILER_SUPPORT_X86_XOP) |
| 527 | |
| 528 | check_cxx_compiler_flag("/arch:AVX -mf16c" NCNN_COMPILER_SUPPORT_X86_F16C) |
| 529 | check_cxx_compiler_flag("/arch:AVX2 -mfma -mf16c" NCNN_COMPILER_SUPPORT_X86_AVX2) |
| 530 | check_cxx_compiler_flag("/arch:AVX512 -mfma -mf16c -mavx512cd -mavx512bw -mavx512dq -mavx512vl" NCNN_COMPILER_SUPPORT_X86_AVX512) |
| 531 | |
| 532 | set(CMAKE_REQUIRED_FLAGS "/arch:AVX2 -mfma -mf16c -mavxvnni") |
| 533 | check_cxx_source_compiles("#include <immintrin.h>\nint main() { __m256i _s, _a, _b; _s = _mm256_dpwssd_epi32(_s, _a, _b); return 0; }" NCNN_COMPILER_SUPPORT_X86_AVX_VNNI) |
| 534 | |
| 535 | set(CMAKE_REQUIRED_FLAGS "/arch:AVX512 -mfma -mf16c -mavx512cd -mavx512bw -mavx512dq -mavx512vl -mavx512vnni") |
| 536 | check_cxx_source_compiles("#include <immintrin.h>\nint main() { __m512i _s, _a, _b; _s = _mm512_dpwssd_epi32(_s, _a, _b); return 0; }" NCNN_COMPILER_SUPPORT_X86_AVX512_VNNI) |
| 537 | |
| 538 | set(CMAKE_REQUIRED_FLAGS "/arch:AVX512 -mfma -mf16c -mavx512cd -mavx512bw -mavx512dq -mavx512vl -mavx512bf16") |
| 539 | check_cxx_source_compiles("#include <immintrin.h>\nint main() { __m256bh _s; __m512bh _a, _b; _s = _mm512_cvtneps_pbh(_mm512_dpbf16_ps(_mm512_cvtpbh_ps(_s), _a, _b)); return 0; }" NCNN_COMPILER_SUPPORT_X86_AVX512_BF16) |
| 540 | |
| 541 | set(CMAKE_REQUIRED_FLAGS "/arch:AVX512 -mfma -mf16c -mavx512cd -mavx512bw -mavx512dq -mavx512vl -mavx512fp16") |
| 542 | check_cxx_source_compiles("#include <immintrin.h>\nint main() { __m512h _s, _a, _b; _s = _mm512_fmadd_ph(_s, _a, _b); __m512 _s2; _s2 = _mm512_cvtxph_ps(_mm512_cvtxps_ph(_s2)); return 0; }" NCNN_COMPILER_SUPPORT_X86_AVX512_FP16) |
| 543 | |
| 544 | unset(CMAKE_REQUIRED_FLAGS) |
| 545 | else() |
| 546 | check_cxx_compiler_flag("-mavx" NCNN_COMPILER_SUPPORT_X86_AVX) |
| 547 | |
| 548 | set(CMAKE_REQUIRED_FLAGS "-mfma -mf16c") |
| 549 | check_cxx_source_compiles("#include <immintrin.h>\nint main() { __m256 _s, _a, _b; _s = _mm256_fmadd_ps(_a, _b, _s); return 0; }" NCNN_COMPILER_SUPPORT_X86_FMA) |
| 550 | |
| 551 | check_cxx_compiler_flag("-mxop" NCNN_COMPILER_SUPPORT_X86_XOP) |
| 552 | check_cxx_compiler_flag("-mf16c" NCNN_COMPILER_SUPPORT_X86_F16C) |
| 553 | check_cxx_compiler_flag("-mfma -mf16c -mavx2" NCNN_COMPILER_SUPPORT_X86_AVX2) |
| 554 | check_cxx_compiler_flag("-mfma -mf16c -mavx512f -mavx512cd -mavx512bw -mavx512dq -mavx512vl" NCNN_COMPILER_SUPPORT_X86_AVX512) |
| 555 | |
| 556 | set(CMAKE_REQUIRED_FLAGS "-mfma -mf16c -mavx2 -mavxvnni") |
| 557 | check_cxx_source_compiles("#include <immintrin.h>\nint main() { __m256i _s, _a, _b; _s = _mm256_dpwssd_epi32(_s, _a, _b); return 0; }" NCNN_COMPILER_SUPPORT_X86_AVX_VNNI) |
| 558 | |
| 559 | set(CMAKE_REQUIRED_FLAGS "-mfma -mf16c -mavx512f -mavx512cd -mavx512bw -mavx512dq -mavx512vl -mavx512vnni") |
| 560 | check_cxx_source_compiles("#include <immintrin.h>\nint main() { __m512i _s, _a, _b; _s = _mm512_dpwssd_epi32(_s, _a, _b); return 0; }" NCNN_COMPILER_SUPPORT_X86_AVX512_VNNI) |
| 561 | |
| 562 | set(CMAKE_REQUIRED_FLAGS "-mfma -mf16c -mavx512f -mavx512cd -mavx512bw -mavx512dq -mavx512vl -mavx512bf16") |
| 563 | check_cxx_source_compiles("#include <immintrin.h>\nint main() { __m256bh _s; __m512bh _a, _b; _s = _mm512_cvtneps_pbh(_mm512_dpbf16_ps(_mm512_cvtpbh_ps(_s), _a, _b)); return 0; }" NCNN_COMPILER_SUPPORT_X86_AVX512_BF16) |
| 564 | |
| 565 | set(CMAKE_REQUIRED_FLAGS "-mfma -mf16c -mavx512f -mavx512cd -mavx512bw -mavx512dq -mavx512vl -mavx512fp16") |
| 566 | check_cxx_source_compiles("#include <immintrin.h>\nint main() { __m512h _s, _a, _b; _s = _mm512_fmadd_ph(_s, _a, _b); __m512 _s2; _s2 = _mm512_cvtxph_ps(_mm512_cvtxps_ph(_s2)); return 0; }" NCNN_COMPILER_SUPPORT_X86_AVX512_FP16) |
| 567 | |
| 568 | unset(CMAKE_REQUIRED_FLAGS) |
| 569 | endif() |
| 570 | |
| 571 | if(NOT CMAKE_SYSTEM_NAME MATCHES "Emscripten|WASI" AND NCNN_COMPILER_SUPPORT_X86_AVX) |
| 572 | option(NCNN_AVX "optimize x86 platform with avx extension" ON) |
| 573 | if(NCNN_COMPILER_SUPPORT_X86_FMA) |
| 574 | if(NCNN_AVX) |
| 575 | option(NCNN_FMA "optimize x86 platform with fma extension" ON) |
| 576 | endif() |
| 577 | else() |
| 578 | message(WARNING "The compiler does not support fma extension. NCNN_FMA will be OFF.") |
| 579 | endif() |
| 580 | if(NCNN_COMPILER_SUPPORT_X86_XOP) |
| 581 | if(NCNN_AVX) |
| 582 | option(NCNN_XOP "optimize x86 platform with xop extension" ON) |
| 583 | endif() |
| 584 | else() |
| 585 | message(WARNING "The compiler does not support xop extension. NCNN_XOP will be OFF.") |
| 586 | endif() |
| 587 | if(NCNN_COMPILER_SUPPORT_X86_F16C) |
| 588 | if(NCNN_AVX) |
| 589 | option(NCNN_F16C "optimize x86 platform with f16c extension" ON) |
| 590 | endif() |
| 591 | else() |
| 592 | message(WARNING "The compiler does not support f16c extension. NCNN_F16C will be OFF.") |
| 593 | endif() |
| 594 | if(NCNN_COMPILER_SUPPORT_X86_AVX2) |
| 595 | if(NCNN_AVX) |
| 596 | option(NCNN_AVX2 "optimize x86 platform with avx2 extension" ON) |
| 597 | endif() |
| 598 | if(NCNN_COMPILER_SUPPORT_X86_AVX_VNNI) |
| 599 | if(NCNN_AVX2) |
| 600 | option(NCNN_AVXVNNI "optimize x86 platform with avx vnni extension" ON) |
| 601 | endif() |
| 602 | else() |
| 603 | message(WARNING "The compiler does not support avx vnni extension. NCNN_AVXVNNI will be OFF.") |
| 604 | endif() |
| 605 | if(NCNN_COMPILER_SUPPORT_X86_AVX512) |
| 606 | if(NCNN_AVX2) |
| 607 | option(NCNN_AVX512 "optimize x86 platform with avx512 extension" ON) |
| 608 | endif() |
| 609 | if(NCNN_COMPILER_SUPPORT_X86_AVX512_VNNI) |
| 610 | if(NCNN_AVX512) |
| 611 | option(NCNN_AVX512VNNI "optimize x86 platform with avx512 vnni extension" ON) |
| 612 | endif() |
| 613 | else() |
| 614 | message(WARNING "The compiler does not support avx512 vnni extension. NCNN_AVX512VNNI will be OFF.") |
| 615 | endif() |
| 616 | if(NCNN_COMPILER_SUPPORT_X86_AVX512_BF16) |
| 617 | if(NCNN_AVX512) |
| 618 | option(NCNN_AVX512BF16 "optimize x86 platform with avx512 bf16 extension" ON) |
| 619 | endif() |
| 620 | else() |
| 621 | message(WARNING "The compiler does not support avx512 bf16 extension. NCNN_AVX512BF16 will be OFF.") |
| 622 | endif() |
| 623 | if(NCNN_COMPILER_SUPPORT_X86_AVX512_FP16) |
| 624 | if(NCNN_AVX512) |
| 625 | option(NCNN_AVX512FP16 "optimize x86 platform with avx512 fp16 extension" ON) |
| 626 | endif() |
| 627 | else() |
| 628 | message(WARNING "The compiler does not support avx512 fp16 extension. NCNN_AVX512FP16 will be OFF.") |
| 629 | endif() |
| 630 | else() |
| 631 | message(WARNING "The compiler does not support avx512 extension. NCNN_AVX512 will be OFF.") |
| 632 | endif() |
| 633 | else() |
| 634 | message(WARNING "The compiler does not support avx2 extension. NCNN_AVX2 will be OFF.") |
| 635 | endif() |
| 636 | else() |
| 637 | message(WARNING "The compiler does not support avx extension. NCNN_AVX will be OFF.") |
| 638 | endif() |
| 639 | endif() |
| 640 | |
| 641 | if(NCNN_TARGET_ILP32) |
| 642 | message(STATUS "Target arch: ${NCNN_TARGET_ARCH} 64bit ilp32") |
| 643 | elseif(CMAKE_SIZEOF_VOID_P EQUAL 8) |
| 644 | message(STATUS "Target arch: ${NCNN_TARGET_ARCH} 64bit") |
| 645 | else() |
| 646 | message(STATUS "Target arch: ${NCNN_TARGET_ARCH} 32bit") |
| 647 | endif() |
| 648 | |
| 649 | ############################################## |
| 650 | |
| 651 | # set cmake default folder name |
| 652 | set_property(GLOBAL PROPERTY USE_FOLDERS ON) |
| 653 | set_property(GLOBAL PROPERTY PREDEFINED_TARGETS_FOLDER "cmake") |
| 654 | |
| 655 | if(CMAKE_SYSTEM_NAME STREQUAL "Emscripten") |
| 656 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -s FORCE_FILESYSTEM=1 -s INITIAL_MEMORY=256MB -s EXIT_RUNTIME=1") |
| 657 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s FORCE_FILESYSTEM=1 -s INITIAL_MEMORY=256MB -s EXIT_RUNTIME=1") |
| 658 | set(CMAKE_EXECUTBLE_LINKER_FLAGS "${CMAKE_EXECUTBLE_LINKER_FLAGS} -s FORCE_FILESYSTEM=1 -s INITIAL_MEMORY=256MB -s EXIT_RUNTIME=1") |
| 659 | |
| 660 | if(NCNN_OPENMP AND NCNN_SIMPLEOMP) |
| 661 | # TODO better flags for emscripten |
| 662 | # node --experimental-wasm-threads xxx.js |
| 663 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -s USE_PTHREADS=1 -s PTHREAD_POOL_SIZE=15") |
| 664 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s USE_PTHREADS=1 -s PTHREAD_POOL_SIZE=15") |
| 665 | set(CMAKE_EXECUTBLE_LINKER_FLAGS "${CMAKE_EXECUTBLE_LINKER_FLAGS} -s USE_PTHREADS=1 -s PTHREAD_POOL_SIZE=15") |
| 666 | endif() |
| 667 | endif() |
| 668 | |
| 669 | if(NCNN_VULKAN) |
| 670 | if(NCNN_SYSTEM_GLSLANG) |
| 671 | find_package(Threads) |
| 672 | find_package(glslang QUIET) |
| 673 | if(glslang_FOUND) |
| 674 | add_library(glslang ALIAS glslang::glslang) |
| 675 | add_library(SPIRV ALIAS glslang::SPIRV) |
| 676 | else() |
| 677 | set(GLSLANG_TARGET_DIR "GLSLANG-NOTFOUND" CACHE PATH "Absolute path to glslangTargets.cmake directory") |
| 678 | if(NOT GLSLANG_TARGET_DIR AND NOT DEFINED ENV{GLSLANG_TARGET_DIR}) |
| 679 | message(WARNING "set glslang_DIR to glslang-config.cmake directory for using system glslang.") |
| 680 | message(WARNING "GLSLANG_TARGET_DIR must be defined! NCNN_SYSTEM_GLSLANG will be turned off.") |
| 681 | set(NCNN_SYSTEM_GLSLANG OFF) |
| 682 | else() |
| 683 | include("${GLSLANG_TARGET_DIR}/OSDependentTargets.cmake") |
| 684 | include("${GLSLANG_TARGET_DIR}/OGLCompilerTargets.cmake") |
| 685 | if(EXISTS "${GLSLANG_TARGET_DIR}/HLSLTargets.cmake") |
| 686 | # hlsl support can be optional |
| 687 | include("${GLSLANG_TARGET_DIR}/HLSLTargets.cmake") |
| 688 | endif() |
| 689 | include("${GLSLANG_TARGET_DIR}/glslangTargets.cmake") |
| 690 | include("${GLSLANG_TARGET_DIR}/SPIRVTargets.cmake") |
| 691 | endif() |
| 692 | endif() |
| 693 | |
| 694 | if (TARGET glslang AND TARGET SPIRV) |
| 695 | get_property(glslang_location TARGET glslang PROPERTY LOCATION) |
| 696 | get_property(SPIRV_location TARGET SPIRV PROPERTY LOCATION) |
| 697 | message(STATUS "Found glslang: ${glslang_location} (found version \"${glslang_VERSION}\")") |
| 698 | message(STATUS "Found SPIRV: ${SPIRV_location} (found version \"${glslang_VERSION}\")") |
| 699 | else() |
| 700 | message(WARNING "glslang or SPIRV target not found! NCNN_SYSTEM_GLSLANG will be turned off.") |
| 701 | set(NCNN_SYSTEM_GLSLANG OFF) |
| 702 | endif() |
| 703 | endif() |
| 704 | |
| 705 | if(NOT NCNN_SYSTEM_GLSLANG) |
| 706 | if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/glslang/CMakeLists.txt") |
| 707 | message(FATAL_ERROR "The submodules were not downloaded! Please update submodules with \"git submodule update --init\" and try again.") |
| 708 | else() |
| 709 | # glslang requires c++11 |
| 710 | set(CMAKE_CXX_STANDARD 11) |
| 711 | |
| 712 | option(BUILD_EXTERNAL "" OFF) |
| 713 | option(ENABLE_SPVREMAPPER "" OFF) |
| 714 | option(ENABLE_GLSLANG_BINARIES "" OFF) |
| 715 | option(ENABLE_HLSL "" OFF) |
| 716 | option(ENABLE_RTTI "" OFF) |
| 717 | option(ENABLE_EXCEPTIONS "" OFF) |
| 718 | option(ENABLE_OPT "" OFF) |
| 719 | option(ENABLE_PCH "" OFF) |
| 720 | option(ENABLE_CTEST "" OFF) |
| 721 | if(NCNN_SHARED_LIB) |
| 722 | option(SKIP_GLSLANG_INSTALL "" ON) |
| 723 | endif() |
| 724 | add_subdirectory(glslang) |
| 725 | if(NCNN_SHARED_LIB) |
| 726 | if(CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND NOT CMAKE_CXX_COMPILER_FRONTEND_VARIANT MATCHES "MSVC")) |
| 727 | target_compile_options(glslang PRIVATE -fvisibility=hidden -fvisibility-inlines-hidden) |
| 728 | target_compile_options(OGLCompiler PRIVATE -fvisibility=hidden -fvisibility-inlines-hidden) |
| 729 | target_compile_options(OSDependent PRIVATE -fvisibility=hidden -fvisibility-inlines-hidden) |
| 730 | target_compile_options(SPIRV PRIVATE -fvisibility=hidden -fvisibility-inlines-hidden) |
| 731 | endif() |
| 732 | if(NCNN_ENABLE_LTO) |
| 733 | set_target_properties(glslang PROPERTIES INTERPROCEDURAL_OPTIMIZATION ON) |
| 734 | set_target_properties(OGLCompiler PROPERTIES INTERPROCEDURAL_OPTIMIZATION ON) |
| 735 | set_target_properties(OSDependent PROPERTIES INTERPROCEDURAL_OPTIMIZATION ON) |
| 736 | set_target_properties(SPIRV PROPERTIES INTERPROCEDURAL_OPTIMIZATION ON) |
| 737 | endif() |
| 738 | endif() |
| 739 | endif() |
| 740 | endif() |
| 741 | endif() |
| 742 | |
| 743 | add_subdirectory(src) |
| 744 | if(NCNN_BUILD_BENCHMARK) |
| 745 | add_subdirectory(benchmark) |
| 746 | endif() |
| 747 | if(NCNN_BUILD_EXAMPLES) |
| 748 | add_subdirectory(examples) |
| 749 | endif() |
| 750 | if(NCNN_BUILD_TOOLS) |
| 751 | add_subdirectory(tools) |
| 752 | endif() |
| 753 | if(NCNN_BUILD_TESTS) |
| 754 | enable_testing() |
| 755 | add_subdirectory(tests) |
| 756 | endif() |
| 757 | if(NCNN_PYTHON) |
| 758 | add_subdirectory(python) |
| 759 | endif() |