Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix auto detect of sve length #2257

Merged
merged 3 commits into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,18 @@ set(arbor_supported_components)
# Target microarchitecture for building arbor libraries, tests and examples
#---------------------------------------------------------------------------

# Set the full set of target flags in ARB_CXX_FLAGS_TARGET_FULL, which
# will include target-specific -march flags if ARB_ARCH is not "none".
if(ARB_ARCH STREQUAL "none")
set(ARB_CXX_FLAGS_TARGET_FULL ${ARB_CXX_FLAGS_TARGET})
set(ARB_CXX_FLAGS_TARGET_FULL_CPU ${ARB_CXX_FLAGS_TARGET})
else()
set_arch_target(ARB_CXXOPT_ARCH_CPU ARB_CXXOPT_ARCH ${ARB_ARCH})
set(ARB_CXX_FLAGS_TARGET_FULL ${ARB_CXX_FLAGS_TARGET} ${ARB_CXXOPT_ARCH})
set(ARB_CXX_FLAGS_TARGET_FULL_CPU ${ARB_CXX_FLAGS_TARGET} ${ARB_CXXOPT_ARCH_CPU})
endif()

# Add SVE compiler flags if detected/desired
set(ARB_SVE_WIDTH "auto" CACHE STRING "Default SVE vector length in bits. Default: auto (detection during configure time).")
mark_as_advanced(ARB_SVE_WIDTH)
if (ARB_SVE_WIDTH STREQUAL "auto")
Expand All @@ -337,15 +349,8 @@ else()
set(ARB_SVE_BITS ${ARB_SVE_WIDTH})
set(ARB_CXX_SVE_FLAGS " -msve-vector-bits=${ARB_SVE_BITS}")
endif()

# Set the full set of target flags in ARB_CXX_FLAGS_TARGET_FULL, which
# will include target-specific -march flags if ARB_ARCH is not "none".
if(ARB_ARCH STREQUAL "none")
set(ARB_CXX_FLAGS_TARGET_FULL ${ARB_CXX_FLAGS_TARGET} ${ARB_CXX_SVE_FLAGS})
else()
set_arch_target(ARB_CXXOPT_ARCH ${ARB_ARCH})
set(ARB_CXX_FLAGS_TARGET_FULL ${ARB_CXX_FLAGS_TARGET} ${ARB_CXXOPT_ARCH} ${ARB_CXX_SVE_FLAGS})
endif()
list(APPEND ARB_CXX_FLAGS_TARGET_FULL
"$<$<BUILD_INTERFACE:$<COMPILE_LANGUAGE:CXX>>:${ARB_CXX_SVE_FLAGS}>")

# Compile with `-fvisibility=hidden` to ensure that the symbols of the generated
# arbor static libraries are hidden from the dynamic symbol tables of any shared
Expand Down
14 changes: 9 additions & 5 deletions cmake/CompilerOptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ set(CXXOPT_WALL
# Architectures are given by the same names that GCC uses for its
# -mcpu or -march options.

function(set_arch_target optvar arch)
function(set_arch_target optvar optvar_cuda_guarded arch)
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU")
# Correct compiler option unfortunately depends upon the target architecture family.
# Extract this information from running the configured compiler with --verbose.
Expand All @@ -111,7 +111,7 @@ function(set_arch_target optvar arch)
string(REGEX REPLACE "-.*" "" target_model "${target}")

# Use -mcpu for all supported targets _except_ for x86 and Apple arm64, where it should be -march.

if (CMAKE_CXX_COMPILER_ID MATCHES "AppleClang" AND CMAKE_CXX_COMPILER_VERSION LESS 15)
set(arch_opt "")
else()
Expand All @@ -125,6 +125,7 @@ function(set_arch_target optvar arch)
endif()
endif()

set("${optvar}" "${arch_opt}" PARENT_SCOPE)
get_property(enabled_languages GLOBAL PROPERTY ENABLED_LANGUAGES)
if ("CUDA" IN_LIST enabled_languages)
# Prefix architecture options with `-Xcompiler=` when compiling CUDA sources, i.e.
Expand All @@ -134,16 +135,19 @@ function(set_arch_target optvar arch)
list(APPEND arch_opt_cuda_guarded "$<$<COMPILE_LANGUAGE:CUDA>:-Xcompiler=>${opt}")
endforeach()

set("${optvar}" "${arch_opt_cuda_guarded}" PARENT_SCOPE)
set("${optvar_cuda_guarded}" "${arch_opt_cuda_guarded}" PARENT_SCOPE)
else()
set("${optvar}" "${arch_opt}" PARENT_SCOPE)
set("${optvar_cuda_guarded}" "${arch_opt}" PARENT_SCOPE)
endif()

endfunction()

# Set ${has_sve} and ${sve_length} in parent scope according to auto detection.
function(get_sve_length has_sve sve_length)
try_run(run_var cc_var ${CMAKE_BINARY_DIR} ${PROJECT_SOURCE_DIR}/cmake/sve_length.cpp RUN_OUTPUT_VARIABLE out_var)
try_run(run_var cc_var
${CMAKE_BINARY_DIR} ${PROJECT_SOURCE_DIR}/cmake/sve_length.cpp
COMPILE_DEFINITIONS ${ARB_CXX_FLAGS_TARGET_FULL_CPU}
RUN_OUTPUT_VARIABLE out_var)

if(NOT cc_var)
message(FATAL_ERROR "compilation of ${PROJECT_SOURCE_DIR}/cmake/sve_length.cpp failed")
Expand Down
2 changes: 1 addition & 1 deletion cmake/vls_sve_bits.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ static constexpr unsigned vls_sve_width = @ARB_SVE_BITS@/64;

// Check required compiler features for VLS_SVE
#if (!defined(__ARM_FEATURE_SVE_BITS) || __ARM_FEATURE_SVE_BITS != @ARB_SVE_BITS@)
#error "Vector length specific scalable vector extension (VLS_SVE) not enabled - did you compile with -msve-vector-bits=@ARB_SVE_BITS@?"
#error "Vector length specific scalable vector extension (VLS_SVE) not enabled - consider setting ARB_SVE_LENGTH=@ARB_SVE_BITS@"
#endif

// We currently do not rely on GNU vector extension, __attribute__((vector_size(vls_sve_width)). If defined, we could
Expand Down