Skip to content

Commit

Permalink
ARROW-14361: [C++] Add default simd level
Browse files Browse the repository at this point in the history
  • Loading branch information
cyb70289 committed Oct 19, 2021
1 parent d9ef519 commit 9e51f11
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 10 deletions.
6 changes: 4 additions & 2 deletions cpp/cmake_modules/DefineOptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,13 @@ if("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}")

define_option_string(ARROW_SIMD_LEVEL
"Compile-time SIMD optimization level"
"SSE4_2" # default to SSE4.2
"DEFAULT" # default to SSE4_2 on x86, NEON on Arm, NONE otherwise
"NONE"
"SSE4_2"
"AVX2"
"AVX512")
"AVX512"
"NEON"
"DEFAULT")

define_option_string(ARROW_RUNTIME_SIMD_LEVEL
"Max runtime SIMD optimization level"
Expand Down
15 changes: 14 additions & 1 deletion cpp/cmake_modules/SetupCxxFlags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,23 @@ if(ARROW_CPU_FLAG STREQUAL "x86")
set(ARROW_HAVE_RUNTIME_AVX512 ON)
add_definitions(-DARROW_HAVE_RUNTIME_AVX512 -DARROW_HAVE_RUNTIME_BMI2)
endif()
if(ARROW_SIMD_LEVEL STREQUAL "DEFAULT")
set(ARROW_SIMD_LEVEL "SSE4_2")
endif()
elseif(ARROW_CPU_FLAG STREQUAL "ppc")
# power compiler flags, gcc/clang only
set(ARROW_ALTIVEC_FLAG "-maltivec")
check_cxx_compiler_flag(${ARROW_ALTIVEC_FLAG} CXX_SUPPORTS_ALTIVEC)
if(ARROW_SIMD_LEVEL STREQUAL "DEFAULT")
set(ARROW_SIMD_LEVEL "NONE")
endif()
elseif(ARROW_CPU_FLAG STREQUAL "armv8")
# Arm64 compiler flags, gcc/clang only
set(ARROW_ARMV8_ARCH_FLAG "-march=${ARROW_ARMV8_ARCH}")
check_cxx_compiler_flag(${ARROW_ARMV8_ARCH_FLAG} CXX_SUPPORTS_ARMV8_ARCH)
if(ARROW_SIMD_LEVEL STREQUAL "DEFAULT")
set(ARROW_SIMD_LEVEL "NEON")
endif()
endif()

# Support C11
Expand Down Expand Up @@ -431,6 +440,8 @@ if(ARROW_CPU_FLAG STREQUAL "x86")
endif()
set(CXX_COMMON_FLAGS "${CXX_COMMON_FLAGS} ${ARROW_SSE4_2_FLAG}")
add_definitions(-DARROW_HAVE_SSE4_2)
elseif(NOT ARROW_SIMD_LEVEL STREQUAL "NONE")
message(WARNING "ARROW_SIMD_LEVEL=${ARROW_SIMD_LEVEL} not supported by x86.")
endif()
endif()

Expand All @@ -441,7 +452,7 @@ if(ARROW_CPU_FLAG STREQUAL "ppc")
endif()

if(ARROW_CPU_FLAG STREQUAL "armv8")
if(NOT ARROW_SIMD_LEVEL STREQUAL "NONE")
if(ARROW_SIMD_LEVEL STREQUAL "NEON")
set(ARROW_HAVE_NEON ON)

if(NOT CXX_SUPPORTS_ARMV8_ARCH)
Expand All @@ -467,6 +478,8 @@ if(ARROW_CPU_FLAG STREQUAL "armv8")
add_definitions(-DARROW_HAVE_ARMV8_CRC)
endif()
endif()
elseif(NOT ARROW_SIMD_LEVEL STREQUAL "NONE")
message(WARNING "ARROW_SIMD_LEVEL=${ARROW_SIMD_LEVEL} not supported by Arm.")
endif()
endif()

Expand Down
6 changes: 2 additions & 4 deletions dev/tasks/tasks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -397,8 +397,7 @@ tasks:
template: python-wheels/github.osx.arm64.yml
params:
arch: arm64
# SSE4_2 is the default but cmake will use NEON instead
arrow_simd_level: "SSE4_2"
arrow_simd_level: "DEFAULT"
vcpkg_version: "2021.04.30"
python_version: "3.8"
macos_deployment_target: "11.0"
Expand All @@ -412,8 +411,7 @@ tasks:
template: python-wheels/github.osx.arm64.yml
params:
arch: arm64
# SSE4_2 is the default but cmake will use NEON instead
arrow_simd_level: "SSE4_2"
arrow_simd_level: "DEFAULT"
vcpkg_version: "2021.04.30"
python_version: "{{ python_version }}"
macos_deployment_target: "11.0"
Expand Down
18 changes: 15 additions & 3 deletions python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,21 @@ set(BUILD_WARNING_LEVEL "PRODUCTION")

# This must be synchronized with the definition in
# cpp/cmake_modules/DefineOptions.cmake.
set(ARROW_ARMV8_ARCH
"armv8-a"
CACHE STRING "Arm64 arch and extensions: armv8-a, armv8-a or armv8-a+crc+crypto")
if(NOT DEFINED ARROW_SIMD_LEVEL)
set(ARROW_SIMD_LEVEL
"DEFAULT"
CACHE STRING "Compile time SIMD optimization level")
endif()
if(NOT DEFINED ARROW_RUNTIME_SIMD_LEVEL)
set(ARROW_RUNTIME_SIMD_LEVEL
"MAX"
CACHE STRING "Max runtime SIMD optimization level")
endif()
if(NOT DEFINED ARROW_ARMV8_ARCH)
set(ARROW_ARMV8_ARCH
"armv8-a"
CACHE STRING "Arm64 arch and extensions: armv8-a, armv8-a or armv8-a+crc+crypto")
endif()
include(SetupCxxFlags)

# Add common flags
Expand Down

0 comments on commit 9e51f11

Please sign in to comment.