From eecf55d1a935e9d786a19081b41c797ae74b2d2b Mon Sep 17 00:00:00 2001 From: Mooneer Salem Date: Wed, 16 Aug 2023 00:27:56 -0700 Subject: [PATCH 1/5] Per PLT discussion, implement #57 with less impact. --- CMakeLists.txt | 21 ++++++++++++++------- README.md | 2 ++ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1600871..92cfd88 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,7 @@ # flags manually on cmd line # 2/ Should we standardise on just AVX? As machine we run on # may be different to machine we build on -set(CMAKE_OSX_DEPLOYMENT_TARGET "10.9" CACHE STRING "Minimum OS X deployment version") +set(CMAKE_OSX_DEPLOYMENT_TARGET "10.5" CACHE STRING "Minimum OS X deployment version") cmake_minimum_required(VERSION 3.0) @@ -26,10 +26,11 @@ mark_as_advanced(CLEAR CMAKE_INSTALL_LIBDIR ) -# Build universal ARM64 and x86_64 binaries on Mac. -if(BUILD_OSX_UNIVERSAL) +# Build universal ARM64 and x86_64 binaries on Mac if not explicitly +# told otherwise (i.e. if building for PPC). +if(BUILD_OSX_UNIVERSAL AND NOT CMAKE_OSX_ARCHITECTURES) set(CMAKE_OSX_ARCHITECTURES "x86_64;arm64") -endif(BUILD_OSX_UNIVERSAL) +endif(BUILD_OSX_UNIVERSAL AND NOT CMAKE_OSX_ARCHITECTURES) # # Prevent in-source builds @@ -104,11 +105,17 @@ if(NOT DISABLE_CPU_OPTIMIZATION) OUTPUT_VARIABLE NEON_PRESENT) elseif(APPLE) if(BUILD_OSX_UNIVERSAL) + message(STATUS "Performing universal macOS build using architectures ${CMAKE_OSX_ARCHITECTURES}") + # Presume AVX and SSE are enabled on the x86 side. (AVX2 is not guaranteed depending # on model.) The ARM side will auto-enable NEON optimizations by virtue of being aarch64. - set(AVX_PRESENT TRUE) - set(SSE_PRESENT TRUE) - set(NEON_PRESENT TRUE) + if(CMAKE_OSX_ARCHITECTURES MATCHES "[xX]86") + set(AVX_PRESENT TRUE) + set(SSE_PRESENT TRUE) + endif(CMAKE_OSX_ARCHITECTURES MATCHES "[xX]86") + if(CMAKE_OSX_ARCHITECTURES MATCHES "[Aa][Rr][Mm]") + set(NEON_PRESENT TRUE) + endif(CMAKE_OSX_ARCHITECTURES MATCHES "[Aa][Rr][Mm]") else() # Under OSX we need to look through a few sysctl entries to determine what our CPU supports. message(STATUS "Looking for available CPU optimizations on an OSX system...") diff --git a/README.md b/README.md index 96cf402..8113a9a 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,8 @@ Experimental version of LPCNet that has been used to develop FreeDV 2020 - a HF radio Digital Voice mode for over the air experimentation with Neural Net speech coding. Possibly the first use of Neural Net speech coding in real world operation. +*Note: while this should be able to compile on any architecutre with a modern C compiler, this package only supports Intel and ARM architectures. Usage on others will likely exhibit extremely low performance and possibly have bugs.* + ## Quickstart ``` From 0f239baf89d94e5559182879f1f4be0630fb5c6e Mon Sep 17 00:00:00 2001 From: drowe67 <45574645+drowe67@users.noreply.github.com> Date: Sat, 19 Aug 2023 05:34:46 +0930 Subject: [PATCH 2/5] typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8113a9a..7d0fc1e 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Experimental version of LPCNet that has been used to develop FreeDV 2020 - a HF radio Digital Voice mode for over the air experimentation with Neural Net speech coding. Possibly the first use of Neural Net speech coding in real world operation. -*Note: while this should be able to compile on any architecutre with a modern C compiler, this package only supports Intel and ARM architectures. Usage on others will likely exhibit extremely low performance and possibly have bugs.* +*Note: while this should be able to compile on any architecture with a modern C compiler, this package only supports Intel and ARM architectures. Usage on others will likely exhibit extremely low performance and possibly have bugs.* ## Quickstart From 9f251e8e612ca766644cff91f15c83c6b3fcce6e Mon Sep 17 00:00:00 2001 From: Mooneer Salem Date: Sat, 19 Aug 2023 11:29:24 -0700 Subject: [PATCH 3/5] Suppress compiler warnings for ARM Macs. --- CMakeLists.txt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 92cfd88..bae81ba 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -128,7 +128,8 @@ if(NOT DISABLE_CPU_OPTIMIZATION) # Unlike with the above, NEON *is* guaranteed if on ARM as there were never any ARM32 Macs # available. We don't need any specific compiler flags for this, though. - set(NEON_PRESENT TRUE) + execute_process(COMMAND sysctl -a COMMAND grep -c hw.optional.neon + OUTPUT_VARIABLE NEON_PRESENT) endif(BUILD_OSX_UNIVERSAL) elseif(WIN32) message(STATUS "No detection capability on Windows, assuming AVX is available.") @@ -165,7 +166,7 @@ elseif(${SSE} AND (${SSE_PRESENT} OR ${SSE_PRESENT} GREATER 0)) # AVX and AVX2 machines will also match on SSE message(STATUS "sse processor flags found or enabled.") set(LPCNET_C_PROC_FLAGS -msse4.1) -elseif(${NEON} AND (${NEON_PRESENT} OR ${NEON_PRESENT} GREATER 0)) +elseif(${NEON} AND (${NEON_PRESENT} OR ${NEON_PRESENT} GREATER 0) AND NOT APPLE) # RPi / ARM 32bit message(STATUS "neon processor flags found or enabled.") set(LPCNET_C_PROC_FLAGS -mfpu=neon -march=armv8-a -mtune=cortex-a53) From a8c2d48603bb38daf4a1038d8bc4de5cd566bf83 Mon Sep 17 00:00:00 2001 From: Mooneer Salem Date: Sun, 3 Sep 2023 14:04:33 -0700 Subject: [PATCH 4/5] Assume universal build if architectures are being overridden. --- CMakeLists.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index bae81ba..c849a85 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,6 +28,11 @@ mark_as_advanced(CLEAR # Build universal ARM64 and x86_64 binaries on Mac if not explicitly # told otherwise (i.e. if building for PPC). +if(CMAKE_OSX_ARCHITECTURES) + # Assume universal build if architectures are being overridden. + set(BUILD_OSX_UNIVERSAL 1) +endif(CMAKE_OSX_ARCHITECTURES) + if(BUILD_OSX_UNIVERSAL AND NOT CMAKE_OSX_ARCHITECTURES) set(CMAKE_OSX_ARCHITECTURES "x86_64;arm64") endif(BUILD_OSX_UNIVERSAL AND NOT CMAKE_OSX_ARCHITECTURES) From 8000ebde6113528e09b3fccbb8118a02f226304d Mon Sep 17 00:00:00 2001 From: Mooneer Salem Date: Sun, 10 Sep 2023 21:35:14 -0700 Subject: [PATCH 5/5] Back out forcing of universal builds. --- CMakeLists.txt | 52 +++++++++++++++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 20 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c849a85..7787be0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,17 +26,28 @@ mark_as_advanced(CLEAR CMAKE_INSTALL_LIBDIR ) -# Build universal ARM64 and x86_64 binaries on Mac if not explicitly -# told otherwise (i.e. if building for PPC). -if(CMAKE_OSX_ARCHITECTURES) - # Assume universal build if architectures are being overridden. - set(BUILD_OSX_UNIVERSAL 1) -endif(CMAKE_OSX_ARCHITECTURES) - if(BUILD_OSX_UNIVERSAL AND NOT CMAKE_OSX_ARCHITECTURES) set(CMAKE_OSX_ARCHITECTURES "x86_64;arm64") endif(BUILD_OSX_UNIVERSAL AND NOT CMAKE_OSX_ARCHITECTURES) +if(APPLE) + function(can_enable_for_architecture ARCH RET) + if(BUILD_OSX_UNIVERSAL) + if(CMAKE_OSX_ARCHITECTURES MATCHES ${ARCH}) + set(${RET} TRUE PARENT_SCOPE) + else() + set(${RET} FALSE PARENT_SCOPE) + endif() + else() + if(CMAKE_SYSTEM_PROCESSOR MATCHES ${ARCH}) + set(${RET} TRUE PARENT_SCOPE) + else() + set(${RET} FALSE PARENT_SCOPE) + endif() + endif() + endfunction() +endif(APPLE) + # # Prevent in-source builds # If an in-source build is attempted, you will still need to clean up a few @@ -114,27 +125,28 @@ if(NOT DISABLE_CPU_OPTIMIZATION) # Presume AVX and SSE are enabled on the x86 side. (AVX2 is not guaranteed depending # on model.) The ARM side will auto-enable NEON optimizations by virtue of being aarch64. - if(CMAKE_OSX_ARCHITECTURES MATCHES "[xX]86") + can_enable_for_architecture("[xX]86" IS_X86) + if(IS_X86) set(AVX_PRESENT TRUE) set(SSE_PRESENT TRUE) - endif(CMAKE_OSX_ARCHITECTURES MATCHES "[xX]86") - if(CMAKE_OSX_ARCHITECTURES MATCHES "[Aa][Rr][Mm]") - set(NEON_PRESENT TRUE) - endif(CMAKE_OSX_ARCHITECTURES MATCHES "[Aa][Rr][Mm]") + endif() + can_enable_for_architecture("[Aa][Rr][Mm]" NEON_PRESENT) else() # Under OSX we need to look through a few sysctl entries to determine what our CPU supports. message(STATUS "Looking for available CPU optimizations on an OSX system...") - execute_process(COMMAND sysctl -a COMMAND grep machdep.cpu.leaf7_features COMMAND grep -c AVX2 - OUTPUT_VARIABLE AVX2_PRESENT) - execute_process(COMMAND sysctl -a COMMAND grep machdep.cpu.features COMMAND grep -c AVX - OUTPUT_VARIABLE AVX_PRESENT) - execute_process(COMMAND sysctl -a COMMAND grep machdep.cpu.features COMMAND grep -c SSE4.1 - OUTPUT_VARIABLE SSE_PRESENT) + can_enable_for_architecture("[xX]86" IS_X86) + if(IS_X86) + execute_process(COMMAND sysctl -a COMMAND grep machdep.cpu.leaf7_features COMMAND grep -c AVX2 + OUTPUT_VARIABLE AVX2_PRESENT) + execute_process(COMMAND sysctl -a COMMAND grep machdep.cpu.features COMMAND grep -c AVX + OUTPUT_VARIABLE AVX_PRESENT) + execute_process(COMMAND sysctl -a COMMAND grep machdep.cpu.features COMMAND grep -c SSE4.1 + OUTPUT_VARIABLE SSE_PRESENT) + endif() # Unlike with the above, NEON *is* guaranteed if on ARM as there were never any ARM32 Macs # available. We don't need any specific compiler flags for this, though. - execute_process(COMMAND sysctl -a COMMAND grep -c hw.optional.neon - OUTPUT_VARIABLE NEON_PRESENT) + can_enable_for_architecture("[Aa][Rr][Mm]" NEON_PRESENT) endif(BUILD_OSX_UNIVERSAL) elseif(WIN32) message(STATUS "No detection capability on Windows, assuming AVX is available.")