Skip to content

Commit

Permalink
split avx from avx2
Browse files Browse the repository at this point in the history
- refactor all simd functions, just like FP32
- add openblas for ubuntu-aarch deps

Signed-off-by: LHT129 <tianlan.lht@antgroup.com>
  • Loading branch information
LHT129 committed Dec 24, 2024
1 parent 2698dcb commit 59a72c4
Show file tree
Hide file tree
Showing 32 changed files with 1,193 additions and 1,106 deletions.
2 changes: 1 addition & 1 deletion scripts/deps/install_deps_ubuntu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ if [[ "$arch" == "x86_64" ]]; then
apt update && apt install -y gfortran python3-dev libomp-15-dev lcov intel-mkl gcc make cmake g++
elif [[ "$arch" == "aarch64" ]]; then
echo "Executing apt install for aarch64"
apt update && apt install -y gfortran python3-dev libomp-15-dev gcc make cmake g++ lcov
apt update && apt install -y gfortran python3-dev libomp-15-dev gcc make cmake g++ lcov libopenblas-dev
else
echo "Unknown architecture: $arch"
fi
65 changes: 33 additions & 32 deletions src/simd/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,63 +1,64 @@
set (SIMD_SRCS
set(SIMD_SRCS
generic.cpp
sse.cpp
avx.cpp
avx2.cpp
avx512.cpp
simd.cpp
basic_func.cpp
fp32_simd.cpp
sq8_simd.cpp
sq4_simd.cpp
sq4_uniform_simd.cpp
sq8_uniform_simd.cpp
sse.cpp
avx.cpp
avx512.cpp
normalize.cpp
)
if (DIST_CONTAINS_SSE)
set (SIMD_SRCS ${SIMD_SRCS} sse.cpp)
set_source_files_properties (
set(SIMD_SRCS ${SIMD_SRCS} sse.cpp)
set_source_files_properties(
sse.cpp
PROPERTIES COMPILE_FLAGS
"-msse -msse2 -msse3 -mssse3 -msse4 -msse4a -msse4.1 -msse4.2")
endif ()
if (DIST_CONTAINS_AVX)
set (SIMD_SRCS ${SIMD_SRCS} avx.cpp)
set_source_files_properties (avx.cpp PROPERTIES COMPILE_FLAGS "-mavx")
set(SIMD_SRCS ${SIMD_SRCS} avx.cpp)
set_source_files_properties(avx.cpp PROPERTIES COMPILE_FLAGS "-mavx")
endif ()
if (DIST_CONTAINS_AVX2)
set_source_files_properties(avx2.cpp PROPERTIES COMPILE_FLAGS "-mavx2 -mfma")
endif ()
# FIXME(LHT): cause illegal instruction on platform which has avx only
#if (DIST_CONTAINS_AVX2)
# set_source_files_properties (avx.cpp PROPERTIES COMPILE_FLAGS "-mavx2 -mfma")
#endif ()
if (DIST_CONTAINS_AVX512)
set (SIMD_SRCS ${SIMD_SRCS} avx512.cpp
set(SIMD_SRCS ${SIMD_SRCS} avx512.cpp
normalize.cpp)
set_source_files_properties (
set_source_files_properties(
avx512.cpp
PROPERTIES
COMPILE_FLAGS
"-mavx512f -mavx512pf -mavx512er -mavx512cd -mavx512vl -mavx512bw -mavx512dq -mavx512ifma -mavx512vbmi"
)
endif ()

set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ftree-vectorize")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-builtin-malloc")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-builtin-calloc")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-builtin-realloc")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-builtin-free")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp -fopenmp-simd")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -funroll-loops")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ftree-vectorize")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-builtin-malloc")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-builtin-calloc")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-builtin-realloc")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-builtin-free")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp -fopenmp-simd")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -funroll-loops")

add_library (simd ${SIMD_SRCS})
add_library(simd ${SIMD_SRCS})

macro (simd_add_definitions flag1 flag2)
macro(simd_add_definitions flag1 flag2)
if (${flag1})
target_compile_definitions (simd PUBLIC ${flag2})
target_compile_definitions(simd PUBLIC ${flag2})
endif ()
endmacro ()
endmacro()

simd_add_definitions (DIST_CONTAINS_SSE -DENABLE_SSE=1)
simd_add_definitions (DIST_CONTAINS_AVX -DENABLE_AVX=1)
#simd_add_definitions (DIST_CONTAINS_AVX2 -DENABLE_AVX2=1)
simd_add_definitions (DIST_CONTAINS_AVX512 -DENABLE_AVX512=1)
simd_add_definitions(DIST_CONTAINS_SSE -DENABLE_SSE=1)
simd_add_definitions(DIST_CONTAINS_AVX -DENABLE_AVX=1)
simd_add_definitions(DIST_CONTAINS_AVX2 -DENABLE_AVX2=1)
simd_add_definitions(DIST_CONTAINS_AVX512 -DENABLE_AVX512=1)

target_link_libraries (simd PRIVATE cpuinfo)
install (TARGETS simd ARCHIVE DESTINATION lib)
target_link_libraries(simd PRIVATE cpuinfo)
install(TARGETS simd ARCHIVE DESTINATION lib)
Loading

0 comments on commit 59a72c4

Please sign in to comment.