diff --git a/CMakeLists.txt b/CMakeLists.txt index a765d7b2f2da00565f5f5b329f5b0f433c43ebd3..354e1bdf223e8bd16a1c3eb7938dd57332e75c6a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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") @@ -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 diff --git a/cmake/CompilerOptions.cmake b/cmake/CompilerOptions.cmake index 65d4d84453c4415c232549e95e90b54ba4e8f37f..e9ff5b6ec656db66194aa2a4970d4bc1c5bd1ff9 100644 --- a/cmake/CompilerOptions.cmake +++ b/cmake/CompilerOptions.cmake @@ -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. @@ -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() @@ -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. @@ -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") diff --git a/cmake/vls_sve_bits.hpp.in b/cmake/vls_sve_bits.hpp.in index 7a8664ba4fdf1449c30ed96278d7b0ffe88783f1..506f5156e2e77629979b6e1301635a6469a5086e 100644 --- a/cmake/vls_sve_bits.hpp.in +++ b/cmake/vls_sve_bits.hpp.in @@ -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