Skip to content

Commit

Permalink
Add option to conditionally enable SIMD (#39)
Browse files Browse the repository at this point in the history
Summary:
`-march=native` doesn't work for cross-compiling. Change to use `-march=armv8-a` for cross-compiling for mac ARM on mac Intel and add a CMake option to control whether to enable SIMD.

Pull Request resolved: #39

Test Plan: CI

Reviewed By: yutingye

Differential Revision: D59495638

Pulled By: jeongseok-meta

fbshipit-source-id: 17ea1cc647c2d8f69be12f0af352f513dcfa2658
  • Loading branch information
jeongseok-meta authored and facebook-github-bot committed Jul 8, 2024
1 parent 5a742d9 commit 0d60cde
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ include(cmake/mt_defs.cmake)
#===============================================================================

option(BUILD_SHARED_LIBS "Build as shared libraries" ON)
option(MOMENTUM_ENABLE_SIMD "Enable building with SIMD instructions" ON)
option(MOMENTUM_BUILD_IO_FBX "Build with IO FBX" OFF)
option(MOMENTUM_BUILD_PYMOMENTUM "Build Python binding" OFF)
option(MOMENTUM_BUILD_TESTING "Enable building tests" OFF)
Expand Down
20 changes: 14 additions & 6 deletions cmake/mt_defs.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,20 @@ function(mt_library)
${type} ${_ARG_PUBLIC_COMPILE_DEFINITIONS}
PRIVATE ${_ARG_PRIVATE_COMPILE_DEFINITIONS}
)
if(MSVC)
target_compile_options(${_ARG_NAME} ${type} "/arch:SSE2")
target_compile_options(${_ARG_NAME} ${type} "/arch:AVX")
target_compile_options(${_ARG_NAME} ${type} "/arch:AVX2")
else()
target_compile_options(${_ARG_NAME} ${type} -march=native)
if(MOMENTUM_ENABLE_SIMD)
if(MSVC)
target_compile_options(${_ARG_NAME} ${type} "/arch:SSE2")
target_compile_options(${_ARG_NAME} ${type} "/arch:AVX")
target_compile_options(${_ARG_NAME} ${type} "/arch:AVX2")
elseif(APPLE)
if(CMAKE_OSX_ARCHITECTURES MATCHES "arm64")
target_compile_options(${_ARG_NAME} ${type} -march=armv8-a)
else()
target_compile_options(${_ARG_NAME} ${type} -march=native)
endif()
else()
target_compile_options(${_ARG_NAME} ${type} -march=native)
endif()
endif()
target_compile_options(${_ARG_NAME}
${type} ${_ARG_PUBLIC_COMPILE_OPTIONS}
Expand Down

0 comments on commit 0d60cde

Please sign in to comment.