Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ARROW-14361: [C++] Add default simd level #11456

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
Comment on lines +106 to +110
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ARROW_SIMD_LEVEL variable is empty if we don't set it here explicitly, same as passing -DARROW_SIMD_LEVEL=. It disables simd silently when building cpp files under python dir.

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