Skip to content

avx512 changes require -mavx512vl compile flags #1109

@pbadari

Description

@pbadari

Describe the bug

While trying to optimize aws-checksums (AVX512 branch) with avx512 instructions, found that compiling them requires -mavx512vl compile flags.

Expected Behavior

aws-c-common to add -mavx512vl to compile flags if its available.

Current Behavior

Compile failures in aws-checksums AVX512 branch.

In file included from /usr/lib/gcc/x86_64-linux-gnu/11/include/immintrin.h:57,
from /home/badari/aws-checksums/source/intel/intrin/crc32c_sse42_avx512.c:12:
/home/badari/aws-checksums/source/intel/intrin/crc32c_sse42_avx512.c: In function ‘aws_checksums_crc32c_avx512’:
/usr/lib/gcc/x86_64-linux-gnu/11/include/avx512vlintrin.h:7558:1: error: inlining failed in call to ‘always_inline’ ‘_mm_xor_epi64’: target specific option mismatch
7558 | _mm_xor_epi64 (__m128i __A, __m128i __B)
| ^~~~~~~~~~~~~
/home/badari/aws-checksums/source/intel/intrin/crc32c_sse42_avx512.c:144:10: note: called from here
144 | a1 = _mm_xor_epi64(a1, _mm512_castsi512_si128(x0));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Reproduction Steps

Try to build AVX512 branch of aws-checksums project

Possible Solution

diff --git a/cmake/AwsSIMD.cmake b/cmake/AwsSIMD.cmake
index 65fce96c..22126a62 100644
--- a/cmake/AwsSIMD.cmake
+++ b/cmake/AwsSIMD.cmake
@@ -35,6 +35,11 @@ if (USE_CPU_EXTENSIONS)
         set(AVX_CFLAGS "${AWS_AVX512_FLAG} ${AWS_CLMUL_FLAG} ${AVX_CFLAGS}")
     endif()
 
+    check_c_compiler_flag("${AWS_AVX512vL_FLAG}" HAVE_M_AVX512_FLAG)
+    if (HAVE_M_AVX512_FLAG)
+       set(AVX_CFLAGS "${AWS_AVX512vL_FLAG} ${AVX_CFLAGS}")
+    endif()
+
     set(old_flags "${CMAKE_REQUIRED_FLAGS}")
     set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${AVX_CFLAGS} ${WERROR_FLAG}")

Additional Information/Context

No response

aws-c-common version used

latest git

Compiler and version used

gcc version 11.4.0

Operating System and version

Ubuntu 22.04

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature-requestA feature should be added or improved.p3This is a minor priority issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions