Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
OpenXG-RAN
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
zzha zzha
OpenXG-RAN
Commits
612e9636
Commit
612e9636
authored
Oct 14, 2022
by
Robert Schmidt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Autodetect CPU architecture and AVX2/512 in cmake
parent
392040a8
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
52 additions
and
49 deletions
+52
-49
CMakeLists.txt
CMakeLists.txt
+40
-29
cmake_targets/build_oai
cmake_targets/build_oai
+4
-20
cmake_targets/macros.cmake
cmake_targets/macros.cmake
+8
-0
No files found.
CMakeLists.txt
View file @
612e9636
...
...
@@ -193,45 +193,56 @@ endif ()
if (CMAKE_BUILD_TYPE STREQUAL "")
set(CMAKE_BUILD_TYPE "RelWithDebInfo")
endif()
message
(
"CMAKE_BUILD_TYPE is
${
CMAKE_BUILD_TYPE
}
"
)
message(
STATUS
"CMAKE_BUILD_TYPE is ${CMAKE_BUILD_TYPE}")
add_list_string_option(CMAKE_BUILD_TYPE "RelWithDebInfo" "Choose the type of build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel." Debug Release RelWithDebInfo MinSizeRel)
Message
(
"Architecture is
${
CMAKE_SYSTEM_PROCESSOR
}
"
)
# in case /proc/cpuinfo exists we want to inspect available Intrinsics
# -so not to go always through SIMDE emulation
# -so to avoid AVX512 instructions generation by gcc
if
(
EXISTS
"/proc/cpuinfo"
)
file
(
STRINGS
"/proc/cpuinfo"
CPUINFO REGEX flags LIMIT_COUNT 1
)
message
(
"AVX512 is
${
AVX512
}
"
)
message
(
"AVX2 is
${
AVX2
}
"
)
# The following intrinsics are assumed to be available on any x86 system used to build the software (avx, f16c, fma, gnfi, mmx, pclmul, sse, sse2, sse3, xop)
set
(
C_FLAGS_PROCESSOR
"
${
C_FLAGS_PROCESSOR
}
-DSIMDE_X86_AVX_NATIVE -DSIMDE_X86_AVX_NATIVE -DSIMDE_X86_F16C_NATIVE -DSIMDE_X86_FMA_NATIVE -DSIMDE_X86_GFNI_NATIVE -DSIMDE_X86_MMX_NATIVE -DSIMDE_X86_PCLMUL_NATIVE -DSIMDE_X86_SSE2_NATIVE -DSIMDE_X86_SSE3_NATIVE -DSIMDE_X86_SSE_NATIVE -DSIMDE_X86_XOP_HAVE_COM_ -DSIMDE_X86_XOP_NATIVE"
)
if
(
"
${
AVX512
}
"
STREQUAL
"False"
)
set
(
C_FLAGS_PROCESSOR
"
${
C_FLAGS_PROCESSOR
}
-mno-avx512f -march=native"
)
else
()
set
(
C_FLAGS_PROCESSOR
"
${
C_FLAGS_PROCESSOR
}
-DSIMDE_X86_AVX512BW_NATIVE -DSIMDE_X86_AVX512F_NATIVE -DSIMDE_X86_AVX512VL_NATIVE -mavx512bw -march=skylake-avx512 -mtune=skylake-avx512"
)
endif
()
if
(
CPUINFO MATCHES
"avx2"
AND
"
${
AVX2
}
"
STREQUAL
"True"
)
set
(
C_FLAGS_PROCESSOR
"
${
C_FLAGS_PROCESSOR
}
-DSIMDE_X86_AVX2_NATIVE -DSIMDE_X86_VPCLMULQDQ_NATIVE"
)
endif
()
if
(
CPUINFO MATCHES
"sse4_1"
)
set
(
C_FLAGS_PROCESSOR
"
${
C_FLAGS_PROCESSOR
}
-DSIMDE_X86_SSE4_1_NATIVE"
)
endif
()
if
(
CPUINFO MATCHES
"sse4_2"
)
set
(
C_FLAGS_PROCESSOR
"
${
C_FLAGS_PROCESSOR
}
-DSIMDE_X86_SSE4_2_NATIVE"
)
endif
()
if
(
CPUINFO MATCHES
"ssse3"
)
set
(
C_FLAGS_PROCESSOR
"
${
C_FLAGS_PROCESSOR
}
-DSIMDE_X86_SSSE3_NATIVE"
)
endif
()
execute_process(COMMAND uname -m OUTPUT_VARIABLE CPUARCH OUTPUT_STRIP_TRAILING_WHITESPACE)
message(STATUS "CPUARCH ${CPUARCH}")
if(EXISTS "/proc/cpuinfo")
file(STRINGS "/proc/cpuinfo" CPUFLAGS REGEX flags LIMIT_COUNT 1)
else()
message(WARNING "did not find /proc/cpuinfo -- not setting any x86-specific compilation variables")
endif()
set
(
C_FLAGS_PROCESSOR
"
${
C_FLAGS_PROCESSOR
}
-fno-var-tracking-assignments -march=native"
)
eval_boolean(AUTODETECT_AVX512 DEFINED CPUFLAGS AND CPUFLAGS MATCHES "avx512")
add_boolean_option(AVX512 ${AUTODETECT_AVX512} "Whether AVX512 intrinsics is available on the host processor")
Message
(
"C_FLAGS_PROCESSOR is
${
C_FLAGS_PROCESSOR
}
"
)
eval_boolean(AUTODETECT_AVX2 DEFINED CPUFLAGS AND CPUFLAGS MATCHES "avx2")
add_boolean_option(AVX2 ${AUTODETECT_AVX2} "Whether AVX2 intrinsics is available on the host processor")
#
# add autotools definitions that were maybe used!
if(${CPUARCH} STREQUAL "x86_64" AND DEFINED CPUFLAGS)
# The following intrinsics are assumed to be available on any x86 system
# (avx, f16c, fma, gnfi, mmx, pclmul, sse, sse2, sse3, xop)
set(C_FLAGS_PROCESSOR "${C_FLAGS_PROCESSOR} -DSIMDE_X86_AVX_NATIVE -DSIMDE_X86_AVX_NATIVE -DSIMDE_X86_F16C_NATIVE -DSIMDE_X86_FMA_NATIVE -DSIMDE_X86_GFNI_NATIVE -DSIMDE_X86_MMX_NATIVE -DSIMDE_X86_PCLMUL_NATIVE -DSIMDE_X86_SSE2_NATIVE -DSIMDE_X86_SSE3_NATIVE -DSIMDE_X86_SSE_NATIVE -DSIMDE_X86_XOP_HAVE_COM_ -DSIMDE_X86_XOP_NATIVE")
message(STATUS "AVX512 intrinsics are ${AVX512}")
if(${AVX512})
set(C_FLAGS_PROCESSOR "${C_FLAGS_PROCESSOR} -DSIMDE_X86_AVX512BW_NATIVE -DSIMDE_X86_AVX512F_NATIVE -DSIMDE_X86_AVX512VL_NATIVE -mavx512bw -march=skylake-avx512 -mtune=skylake-avx512")
else()
set(C_FLAGS_PROCESSOR "${C_FLAGS_PROCESSOR} -mno-avx512f -march=native")
endif()
message(STATUS "AVX2 intrinsics are ${AVX2}")
if(${AVX2})
set(C_FLAGS_PROCESSOR "${C_FLAGS_PROCESSOR} -DSIMDE_X86_AVX2_NATIVE -DSIMDE_X86_VPCLMULQDQ_NATIVE")
endif()
if (CPUINFO MATCHES "sse4_1")
set(C_FLAGS_PROCESSOR "${C_FLAGS_PROCESSOR} -DSIMDE_X86_SSE4_1_NATIVE")
endif()
if(CPUINFO MATCHES "sse4_2")
set(C_FLAGS_PROCESSOR "${C_FLAGS_PROCESSOR} -DSIMDE_X86_SSE4_2_NATIVE")
endif()
if(CPUINFO MATCHES "ssse3")
set(C_FLAGS_PROCESSOR "${C_FLAGS_PROCESSOR} -DSIMDE_X86_SSSE3_NATIVE")
endif()
elseif(${CPUARCH} NOT STREQUAL "x86_64")
message(FATAL_ERROR "Cannot compile for CPU architecture ${CPUARCH}")
endif()
set(C_FLAGS_PROCESSOR "${C_FLAGS_PROCESSOR} -fno-var-tracking-assignments -march=native")
# add autotools definitions that were maybe used!
add_definitions("-DSTDC_HEADERS=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1 -DHAVE_FCNTL_H=1 -DHAVE_ARPA_INET_H=1 -DHAVE_SYS_TIME_H=1 -DHAVE_SYS_SOCKET_H=1 -DHAVE_STRERROR=1 -DHAVE_SOCKET=1 -DHAVE_MEMSET=1 -DHAVE_GETTIMEOFDAY=1 -DHAVE_STDLIB_H=1 -DHAVE_MALLOC=1 -DHAVE_LIBSCTP")
set(commonOpts "-pipe -Wno-packed-bitfield-compat -fPIC -Wall -fno-strict-aliasing -rdynamic")
...
...
cmake_targets/build_oai
View file @
612e9636
...
...
@@ -53,8 +53,6 @@ BUILD_COVERITY_SCAN=0
DISABLE_HARDWARE_DEPENDENCY
=
"False"
CMAKE_BUILD_TYPE
=
"RelWithDebInfo"
CMAKE_CMD
=
"
$CMAKE
"
AVX512
=
"True"
AVX2
=
"True"
BUILD_ECLIPSE
=
0
NR
=
"False"
OPTIONAL_LIBRARIES
=
"telnetsrv enbscope uescope nrscope"
...
...
@@ -159,7 +157,7 @@ Options:
--noavx512
Disable AVX512 intrinsics whatever processor capability is
--noavx2
Disable AVX2 intrinsics
if processor supports it or use SIMDE emulation
Disable AVX2 intrinsics
whatever processor capability is
-k | --skip-shared-libraries
Skip build for shared libraries to reduce compilation time when building frequently for debugging purposes
--ninja
...
...
@@ -394,11 +392,11 @@ function main() {
fi
shift
2
;;
--noavx512
)
AVX512
=
"False
"
CMAKE_CMD
=
"
$CMAKE_CMD
-DAVX512=OFF
"
echo_info
"Disabling AVX512 instructions"
shift
1
;;
--noavx2
)
AVX2
=
"False
"
CMAKE_CMD
=
"
$CMAKE_CMD
-DAVX2=OFF
"
echo_info
"Disabling AVX2 instructions"
shift
1
;;
-k
|
--skip-shared-libraries
)
...
...
@@ -559,23 +557,9 @@ function main() {
if
[[
${#
CMAKE_C_FLAGS
[@]
}
>
0
]]
;
then
CMAKE_CMD
=
"
$CMAKE_CMD
-DCMAKE_C_FLAGS=
\"
${
CMAKE_C_FLAGS
[*]
}
\"
"
;
fi
if
[[
${#
CMAKE_CXX_FLAGS
[@]
}
>
0
]]
;
then
CMAKE_CMD
=
"
$CMAKE_CMD
-DCMAKE_CXX_FLAGS=
\"
${
CMAKE_CXX_FLAGS
[*]
}
\"
"
;
fi
# if --noavx512 is not specified the AVX512 equals "True" by default
# override AVX512 to "False" if processor does not have avx512
# this avoids having to specify --noavx512 systematically
if
[
-f
/proc/cpuinfo
]
;
then
if
grep
-q
avx512 /proc/cpuinfo
then
echo_info
"Processor has avx512 intrinsics"
else
echo_info
"Processor does not have avx512 intrinsics"
echo_info
"Forcing AVX512 to False"
AVX512
=
"False"
fi
fi
# for historical reasons we build in a subdirectory cmake_targets/XYZ/build,
# e.g., cmake_targets/ran_build/build, hence the ../../..
CMAKE_CMD
=
"
$CMAKE_CMD
-DAVX512=
\"
${
AVX512
[*]
}
\"
-DAVX2=
\"
${
AVX2
[*]
}
\"
../../.."
CMAKE_CMD
=
"
$CMAKE_CMD
../../.."
echo_info
"running
$CMAKE_CMD
"
eval
$CMAKE_CMD
...
...
cmake_targets/macros.cmake
View file @
612e9636
...
...
@@ -96,3 +96,11 @@ macro(compile_asn1 asn1Source asn1cCmd ResultFlag)
DEPENDS
${
asn1Source
}
)
endmacro
(
compile_asn1
)
macro
(
eval_boolean VARIABLE
)
if
(
${
ARGN
}
)
set
(
${
VARIABLE
}
ON
)
else
()
set
(
${
VARIABLE
}
OFF
)
endif
()
endmacro
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment