Skip to content

Commit

Permalink
Fix AVX detection with clang-cl (pytorch#35653)
Browse files Browse the repository at this point in the history
Summary:
Defining macros `/D__F16C__` or sth similar won't work on clang-cl.
Pull Request resolved: pytorch#35653

Differential Revision: D20735878

Pulled By: ezyang

fbshipit-source-id: 392a664b0a9e74222b1a03b8c3f6ebb2c61d867e
  • Loading branch information
peterjc123 authored and facebook-github-bot committed Mar 30, 2020
1 parent 340048b commit e3daf70
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions caffe2/perfkernels/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ if(CAFFE2_COMPILER_SUPPORTS_AVX2_EXTENSIONS)
add_dependencies(Caffe2_perfkernels_avx2 Caffe2_PROTO)
target_link_libraries(Caffe2_perfkernels_avx PRIVATE c10)
target_link_libraries(Caffe2_perfkernels_avx2 PRIVATE c10)
if(MSVC)
if(MSVC AND NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
target_compile_options(Caffe2_perfkernels_avx
PRIVATE "/arch:AVX"
PRIVATE "/D__F16C__")
Expand Down Expand Up @@ -61,7 +61,7 @@ if(CAFFE2_COMPILER_SUPPORTS_AVX2_EXTENSIONS)
add_library(Caffe2_perfkernels_avx512 STATIC ${avx512_srcs})
add_dependencies(Caffe2_perfkernels_avx512 Caffe2_PROTO)
target_link_libraries(Caffe2_perfkernels_avx512 PRIVATE c10)
if(MSVC)
if(MSVC AND NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
target_compile_options(Caffe2_perfkernels_avx512
PRIVATE "/D__AVX512F__"
PRIVATE "/D__AVX512DQ__"
Expand Down
4 changes: 2 additions & 2 deletions cmake/MiscCheck.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ cmake_pop_check_state()
# ---[ Check if the compiler has AVX/AVX2 support. We only check AVX2.
if(NOT INTERN_BUILD_MOBILE)
cmake_push_check_state(RESET)
if(MSVC)
if(MSVC AND NOT CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
set(CMAKE_REQUIRED_FLAGS "/arch:AVX2")
else()
set(CMAKE_REQUIRED_FLAGS "-mavx2")
Expand All @@ -160,7 +160,7 @@ if(NOT INTERN_BUILD_MOBILE)
endif()
# ---[ Check if the compiler has AVX512 support.
cmake_push_check_state(RESET)
if(MSVC)
if(MSVC AND NOT CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
# We could've used MSVC's hidden option /arch:AVX512 that defines __AVX512F__,
# __AVX512DQ__, and __AVX512VL__, and /arch:AVX512F that defines __AVX512F__.
# But, we chose not to do that not to rely on hidden options.
Expand Down

0 comments on commit e3daf70

Please sign in to comment.