Skip to content

Commit

Permalink
Merge pull request #474 from georges-arm/geoste01/fastFwdCore_2D-sve
Browse files Browse the repository at this point in the history
Add AArch64 SVE implementation for TCoeffOps fastFwdCore_2D
  • Loading branch information
adamjw24 authored Nov 29, 2024
2 parents 7d00d03 + 4c8bfef commit dcd4758
Show file tree
Hide file tree
Showing 5 changed files with 372 additions and 19 deletions.
29 changes: 15 additions & 14 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,12 @@ if( VVENC_TARGET_ARCH MATCHES "ARM\|AARCH64" )
set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-lax-vector-conversions" )
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-lax-vector-conversions" )
endif()

# Check if SVE/SVE2 flags are supported by the compiler.
set_if_compiler_supports_arm_extensions( FLAG_sve FLAG_sve2 )
endif()

# we enable x86 intrinsics for all target architectures, because they are implemented through simd-everywhere on non-x86
# We enable x86 intrinsics for all target architectures, because they are implemented through SIMD-everywhere on non-x86.
set( VVENC_ENABLE_X86_SIMD TRUE CACHE BOOL "Enable x86 intrinsics" )
set( VVENC_ENABLE_ARM_SIMD ${VVENC_ARM_SIMD_DEFAULT} CACHE BOOL "Enable Arm Neon intrinsics" )
set( VVENC_ENABLE_ARM_SIMD_SVE FALSE CACHE BOOL "Enable Arm SVE intrinsics" )
Expand Down Expand Up @@ -81,27 +84,25 @@ if( VVENC_TARGET_ARCH STREQUAL "AARCH64" )
if( VVENC_ENABLE_ARM_SIMD )
message( STATUS "AArch64 Neon intrinsics enabled" )
add_compile_definitions( TARGET_SIMD_ARM=1 )
else()
message( STATUS "AArch64 Neon intrinsics disabled, disabling AArch64 SVE/SVE2 intrinsics" )
# If Neon is disabled make sure that SVE/SVE2 are also disabled.
set( VVENC_ENABLE_ARM_SIMD_SVE FALSE )
set( VVENC_ENABLE_ARM_SIMD_SVE2 FALSE )
endif()

if( VVENC_ENABLE_ARM_SIMD_SVE )
# If Neon is disabled or SVE is not supported, make sure that SVE is disabled.
if ( NOT VVENC_ENABLE_ARM_SIMD OR NOT FLAG_sve )
message( STATUS "Disabling AArch64 SVE/SVE2 intrinsics" )
set( VVENC_ENABLE_ARM_SIMD_SVE FALSE )
elseif( VVENC_ENABLE_ARM_SIMD_SVE )
message( STATUS "AArch64 SVE intrinsics enabled" )
add_compile_definitions( TARGET_SIMD_ARM_SVE=1 )
else()
message( STATUS "AArch64 SVE intrinsics disabled, disabling AArch64 SVE2 intrinsics" )
# If SVE is disabled make sure that SVE2 are also disabled.
set( VVENC_ENABLE_ARM_SIMD_SVE2 FALSE )
endif()

if( VVENC_ENABLE_ARM_SIMD_SVE2 )
# If SVE is disabled or SVE2 is not supported, make sure that SVE2 is disabled.
if ( NOT VVENC_ENABLE_ARM_SIMD_SVE OR NOT FLAG_sve2 )
message( STATUS "Disabling AArch64 SVE2 intrinsics" )
# If SVE is disabled make sure that SVE2 are also disabled.
set( VVENC_ENABLE_ARM_SIMD_SVE2 FALSE )
elseif( VVENC_ENABLE_ARM_SIMD_SVE2 )
message( STATUS "AArch64 SVE2 intrinsics enabled" )
add_compile_definitions( TARGET_SIMD_ARM_SVE2=1 )
else()
message( STATUS "AArch64 SVE2 intrinsics disabled" )
endif()
endif()

Expand Down
66 changes: 66 additions & 0 deletions cmake/modules/vvencCompilerSupport.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
include( CheckCCompilerFlag )
include( CheckCSourceCompiles )
include( CheckCXXSourceCompiles )

function( set_if_compiler_supports_flag output_var flag )
string( REGEX REPLACE "[-.]" "_" SUPPORTED_flag_var "SUPPORTED${flag}" )
Expand Down Expand Up @@ -84,6 +85,71 @@ function( _emscripten_enable_wasm_simd128 )
endif()
endfunction()

function( _set_if_compiler_supports_sve_flag output_var sve_flag )
set_if_compiler_supports_flag( tmp_var "${sve_flag}" )
if( NOT tmp_var )
return()
endif()

set( OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS} )
set( OLD_CMAKE_TRY_COMPILE_TARGET_TYPE ${CMAKE_TRY_COMPILE_TARGET_TYPE} )
set( CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${sve_flag}" )
set( CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY )

# Check whether the compiler can compile SVE functions that require
# backup/restore of SVE registers according to AAPCS.
# https://github.com/llvm/llvm-project/issues/80009.
set( SVE_COMPILATION_TEST "
#include <arm_sve.h>
void other();
svfloat32_t func(svfloat32_t a) {
other();
return a;
}
int main() { return 0; }" )

check_c_source_compiles( "${SVE_COMPILATION_TEST}" SVE_COMPILATION_C_TEST_COMPILED )
check_cxx_source_compiles( "${SVE_COMPILATION_TEST}" SVE_COMPILATION_CXX_TEST_COMPILED )

# Check if arm_neon_sve_bridge.h is available.
set( SVE_HEADER_TEST "
#ifndef __ARM_NEON_SVE_BRIDGE
#error 1
#endif
#include <arm_sve.h>
#include <arm_neon_sve_bridge.h>
int main() { return 0; }")
check_c_source_compiles( "${SVE_HEADER_TEST}" SVE_HEADER_C_TEST_COMPILED )
check_cxx_source_compiles( "${SVE_HEADER_TEST}" SVE_HEADER_CXX_TEST_COMPILED )

set( CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS} )
set( CMAKE_TRY_COMPILE_TARGET_TYPE ${OLD_CMAKE_TRY_COMPILE_TARGET_TYPE} )

if( SVE_COMPILATION_C_TEST_COMPILED AND SVE_COMPILATION_CXX_TEST_COMPILED AND
SVE_HEADER_C_TEST_COMPILED AND SVE_HEADER_CXX_TEST_COMPILED )
set( ${output_var} "${tmp_var}" PARENT_SCOPE )
endif()
endfunction()

# Check if the compiler supports the AArch64 SVE and SVE2 extensions, and set
# variables for flags used to enable them to avoid duplication.
function( set_if_compiler_supports_arm_extensions output_flag_sve output_flag_sve2 )
if( NOT(( ${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm64" ) OR
( ${CMAKE_SYSTEM_PROCESSOR} MATCHES "aarch64" )))
return()
endif()
if( UNIX OR MINGW )
# SVE is an optional feature from Armv8.2-A.
set( _flag_sve "-march=armv8.2-a+sve" )
_set_if_compiler_supports_sve_flag( _sve_supported "${_flag_sve}" )
set( ${output_flag_sve} "${_sve_supported}" PARENT_SCOPE )

# SVE2 is an optional feature from Armv9.0-A.
set( _flag_sve2 "-march=armv9-a+sve2" )
_set_if_compiler_supports_sve_flag( _sve2_supported "${_flag_sve2}" )
set( ${output_flag_sve2} "${_sve2_supported}" PARENT_SCOPE )
endif()
endfunction()

function( check_problematic_compiler output_var compiler_id first_bad_version first_fixed_version )
if( CMAKE_CXX_COMPILER_ID STREQUAL "${compiler_id}"
Expand Down
12 changes: 8 additions & 4 deletions source/Lib/CommonLib/arm/InitARM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,14 @@ void TCoeffOps::initTCoeffOpsARM()
{
_initTCoeffOpsARM<NEON>();
}
#if TARGET_SIMD_ARM_SVE
if( vext >= SVE )
{
_initTCoeffOpsARM<SVE>();
}
#endif // TARGET_SIMD_ARM_SVE
}
#endif
#endif // ENABLE_SIMD_TRAFO

#if ENABLE_SIMD_OPT_BDOF
void InterPredInterpolation::initInterPredictionARM()
Expand All @@ -135,8 +141,6 @@ void InterPredInterpolation::initInterPredictionARM()
}
#endif



#endif // TARGET_SIMD_ARM
#endif // TARGET_SIMD_ARM

} // namespace
Loading

0 comments on commit dcd4758

Please sign in to comment.