Skip to content

Commit

Permalink
build
Browse files Browse the repository at this point in the history
  • Loading branch information
nihui committed May 23, 2024
1 parent 94b1fc8 commit b2da715
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 12 deletions.
45 changes: 38 additions & 7 deletions cmake/ncnn_add_layer.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ macro(ncnn_add_layer class)
endif()

if(NCNN_TARGET_ARCH STREQUAL "x86")
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"))
if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
if(NCNN_RUNTIME_CPU AND NCNN_AVX512)
ncnn_add_arch_opt_layer(${class} avx512 "/arch:AVX512 /D__SSSE3__ /D__SSE4_1__ /D__FMA__ /D__F16C__")
endif()
Expand Down Expand Up @@ -165,9 +165,40 @@ macro(ncnn_add_layer class)
if(NCNN_F16C)
ncnn_add_arch_opt_source(${class} f16c "/arch:AVX /D__SSSE3__ /D__SSE4_1__ /D__F16C__")
endif()
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND CMAKE_CXX_SIMULATE_ID MATCHES "MSVC" AND CMAKE_CXX_COMPILER_FRONTEND_VARIANT MATCHES "MSVC")
if(NCNN_RUNTIME_CPU AND NCNN_AVX512)
ncnn_add_arch_opt_layer(${class} avx512 "/arch:AVX512 -mavx512cd -mavx512bw -mavx512dq -mavx512vl")
endif()
if(NCNN_RUNTIME_CPU AND NCNN_FMA)
ncnn_add_arch_opt_layer(${class} fma "/arch:AVX -mfma -mf16c")
endif()
if(NCNN_RUNTIME_CPU AND NCNN_AVX)
ncnn_add_arch_opt_layer(${class} avx "/arch:AVX")
endif()
if(NCNN_AVX512VNNI)
ncnn_add_arch_opt_source(${class} avx512vnni "/arch:AVX512 -mavx512cd -mavx512bw -mavx512dq -mavx512vl -mavx512vnni")
endif()
if(NCNN_AVX512BF16)
ncnn_add_arch_opt_source(${class} avx512bf16 "/arch:AVX512 -mavx512cd -mavx512bw -mavx512dq -mavx512vl -mavx512bf16")
endif()
if(NCNN_AVX512FP16)
ncnn_add_arch_opt_source(${class} avx512fp16 "/arch:AVX512 -mavx512cd -mavx512bw -mavx512dq -mavx512vl -mavx512fp16")
endif()
if(NCNN_AVXVNNI)
ncnn_add_arch_opt_source(${class} avxvnni "/arch:AVX2 -mavxvnni")
endif()
if(NCNN_AVX2)
ncnn_add_arch_opt_source(${class} avx2 "/arch:AVX2")
endif()
if(NCNN_XOP)
ncnn_add_arch_opt_source(${class} xop "/arch:AVX -mxop")
endif()
if(NCNN_F16C)
ncnn_add_arch_opt_source(${class} f16c "/arch:AVX -mf16c")
endif()
else()
if(NCNN_RUNTIME_CPU AND NCNN_AVX512)
ncnn_add_arch_opt_layer(${class} avx512 "-mavx512f -mavx512cd -mavx512bw -mavx512dq -mavx512vl -mfma -mf16c")
ncnn_add_arch_opt_layer(${class} avx512 "-mavx512f -mavx512cd -mavx512bw -mavx512dq -mavx512vl")
endif()
if(NCNN_RUNTIME_CPU AND NCNN_FMA)
ncnn_add_arch_opt_layer(${class} fma "-mavx -mfma -mf16c")
Expand All @@ -176,19 +207,19 @@ macro(ncnn_add_layer class)
ncnn_add_arch_opt_layer(${class} avx "-mavx")
endif()
if(NCNN_AVX512VNNI)
ncnn_add_arch_opt_source(${class} avx512vnni "-mavx512f -mavx512cd -mavx512bw -mavx512dq -mavx512vl -mfma -mf16c -mavx512vnni")
ncnn_add_arch_opt_source(${class} avx512vnni "-mavx512f -mavx512cd -mavx512bw -mavx512dq -mavx512vl -mavx512vnni")
endif()
if(NCNN_AVX512BF16)
ncnn_add_arch_opt_source(${class} avx512bf16 "-mavx512f -mavx512cd -mavx512bw -mavx512dq -mavx512vl -mfma -mf16c -mavx512bf16")
ncnn_add_arch_opt_source(${class} avx512bf16 "-mavx512f -mavx512cd -mavx512bw -mavx512dq -mavx512vl -mavx512bf16")
endif()
if(NCNN_AVX512FP16)
ncnn_add_arch_opt_source(${class} avx512fp16 "-mavx512f -mavx512cd -mavx512bw -mavx512dq -mavx512vl -mfma -mf16c -mavx512fp16")
ncnn_add_arch_opt_source(${class} avx512fp16 "-mavx512f -mavx512cd -mavx512bw -mavx512dq -mavx512vl -mavx512fp16")
endif()
if(NCNN_AVXVNNI)
ncnn_add_arch_opt_source(${class} avxvnni "-mavx2 -mfma -mf16c -mavxvnni")
ncnn_add_arch_opt_source(${class} avxvnni "-mavx2 -mavxvnni")
endif()
if(NCNN_AVX2)
ncnn_add_arch_opt_source(${class} avx2 "-mavx2 -mfma -mf16c")
ncnn_add_arch_opt_source(${class} avx2 "-mavx2")
endif()
if(NCNN_XOP)
ncnn_add_arch_opt_source(${class} xop "-mavx -mxop")
Expand Down
43 changes: 38 additions & 5 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -403,13 +403,24 @@ if(NCNN_TARGET_ARCH STREQUAL "x86")
endif()

if(NOT NCNN_RUNTIME_CPU AND NCNN_AVX512)
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"))
if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
target_compile_options(ncnn PRIVATE /arch:AVX512 /D__SSSE3__ /D__SSE4_1__ /D__FMA__ /D__F16C__)
if(NCNN_AVX512VNNI)
target_compile_options(ncnn PRIVATE /D__AVX512VNNI__)
endif()
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND CMAKE_CXX_SIMULATE_ID MATCHES "MSVC" AND CMAKE_CXX_COMPILER_FRONTEND_VARIANT MATCHES "MSVC")
target_compile_options(ncnn PRIVATE /arch:AVX512 -mavx512cd -mavx512bw -mavx512dq -mavx512vl)
if(NCNN_AVX512VNNI)
target_compile_options(ncnn PRIVATE -mavx512vnni)
endif()
if(NCNN_AVX512BF16)
target_compile_options(ncnn PRIVATE -mavx512bf16)
endif()
if(NCNN_AVX512FP16)
target_compile_options(ncnn PRIVATE -mavx512fp16)
endif()
else()
target_compile_options(ncnn PRIVATE -mavx512f -mavx512cd -mavx512bw -mavx512dq -mavx512vl -mfma -mf16c)
target_compile_options(ncnn PRIVATE -mavx512f -mavx512cd -mavx512bw -mavx512dq -mavx512vl)
if(NCNN_AVX512VNNI)
target_compile_options(ncnn PRIVATE -mavx512vnni)
endif()
Expand All @@ -421,7 +432,7 @@ if(NCNN_TARGET_ARCH STREQUAL "x86")
endif()
endif()
elseif(NOT NCNN_RUNTIME_CPU AND NCNN_FMA)
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"))
if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
if(NCNN_AVX2)
target_compile_options(ncnn PRIVATE /arch:AVX2 /D__SSSE3__ /D__SSE4_1__ /D__FMA__)
else()
Expand All @@ -435,9 +446,23 @@ if(NCNN_TARGET_ARCH STREQUAL "x86")
if(NCNN_F16C)
target_compile_options(ncnn PRIVATE /D__F16C__)
endif()
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND CMAKE_CXX_SIMULATE_ID MATCHES "MSVC" AND CMAKE_CXX_COMPILER_FRONTEND_VARIANT MATCHES "MSVC")
if(NCNN_AVX2)
target_compile_options(ncnn PRIVATE /arch:AVX2)
else()
target_compile_options(ncnn PRIVATE /arch:AVX -mfma)
endif()
if(NCNN_AVXVNNI)
target_compile_options(ncnn PRIVATE -mavxvnni)
elseif(NCNN_XOP)
target_compile_options(ncnn PRIVATE -mxop)
endif()
if(NCNN_F16C)
target_compile_options(ncnn PRIVATE -mf16c)
endif()
else()
if(NCNN_AVX2)
target_compile_options(ncnn PRIVATE -mavx2 -mfma)
target_compile_options(ncnn PRIVATE -mavx2)
else()
target_compile_options(ncnn PRIVATE -mavx -mfma)
endif()
Expand All @@ -451,14 +476,22 @@ if(NCNN_TARGET_ARCH STREQUAL "x86")
endif()
endif()
elseif(NOT NCNN_RUNTIME_CPU AND NCNN_AVX)
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"))
if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
target_compile_options(ncnn PRIVATE /arch:AVX /D__SSSE3__ /D__SSE4_1__)
if(NCNN_XOP)
target_compile_options(ncnn PRIVATE /D__XOP__)
endif()
if(NCNN_F16C)
target_compile_options(ncnn PRIVATE /D__F16C__)
endif()
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND CMAKE_CXX_SIMULATE_ID MATCHES "MSVC" AND CMAKE_CXX_COMPILER_FRONTEND_VARIANT MATCHES "MSVC")
target_compile_options(ncnn PRIVATE /arch:AVX)
if(NCNN_XOP)
target_compile_options(ncnn PRIVATE -mxop)
endif()
if(NCNN_F16C)
target_compile_options(ncnn PRIVATE -mf16c)
endif()
else()
target_compile_options(ncnn PRIVATE -mavx)
if(NCNN_XOP)
Expand Down

0 comments on commit b2da715

Please sign in to comment.