Updates to the build systems(CMake and Make) for LPGEMM compilation (#303)

- The current build systems have the following behaviour
  with regards to building "aocl_gemm" addon codebase(LPGEMM)
  when giving "amdzen" as the target architecture(fat-binary)
  - Make:  Attempts to compile LPGEMM kernels using the same
                compiler flags that the makefile fragments set for BLIS
                kernels, based on the compiler version.
  - CMake: With presets, it always enables the addon compilation
                 unless explicitly specified with the ENABLE_ADDON variable.

- This poses a bug with older compilers, owing to them not supporting
  BF16 or INT8 intrinsic compilation.

- This patch adds the functionality to check for GCC and Clang compiler versions,
  and disables LPGEMM compilation if GCC < 11.2 or Clang < 12.0.

- Make:  Updated the configure script to check for the compiler version
              if the addon is specified.
  CMake: Updated the main CMakeLists.txt to check for the compiler version
               if the addon is specified, and to also force-update the associated
               cache variable update. Also updated kernels/CMakeLists.txt to
               check if "aocl_gemm" remains in the ENABLE_ADDONS list after
               all the checks in the previous layers.

AMD-Internal: [CPUPL-7850]

Signed-off by : Vignesh Balasubramanian <Vignesh.Balasubramanian@amd.com>
This commit is contained in:
Balasubramanian, Vignesh
2026-01-16 19:39:55 +05:30
committed by GitHub
parent 9f9bfbed7f
commit 73911d5990
5 changed files with 77 additions and 7 deletions

View File

@@ -751,14 +751,52 @@ else()
# Remove duplicates in the addon list, if they exist.
list(REMOVE_DUPLICATES ENABLE_ADDON)
message(" Configuring with addons:")
# Check compiler version requirements for each addon
set(FILTERED_ADDON_LIST "")
foreach(ADDON ${ENABLE_ADDON})
message(" ${ADDON}")
if(NOT (EXISTS ${PROJECT_SOURCE_DIR}/addon/${ADDON}))
message(FATAL_ERROR "Requested addon sub-directory does not exist! Cannot continue. \
*** Please verify addon existence and name.")
endif()
# Check if this is aocl_gemm addon and verify compiler version
if("${ADDON}" STREQUAL "aocl_gemm")
if("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU")
# aocl_gemm addon (LPGEMM) requires GCC 11.2 or newer
# due to AVX-512 intrinsics and optimization requirements.
if(CMAKE_C_COMPILER_VERSION VERSION_LESS 11.2.0)
message(WARNING "aocl_gemm addon requires GCC 11.2 or newer.")
message(WARNING "Current GCC version is ${CMAKE_C_COMPILER_VERSION}.")
message(WARNING "Skipping aocl_gemm addon.")
continue()
endif()
elseif("${CMAKE_C_COMPILER_ID}" MATCHES "Clang")
# aocl_gemm addon (LPGEMM) requires Clang 12.0 or newer
# due to AVX-512 intrinsics and C++17 requirements.
if(CMAKE_C_COMPILER_VERSION VERSION_LESS 12.0.0)
message(WARNING "aocl_gemm addon requires Clang 12.0 or newer.")
message(WARNING "Current Clang version is ${CMAKE_C_COMPILER_VERSION}.")
message(WARNING "Skipping aocl_gemm addon.")
continue()
endif()
endif()
endif()
list(APPEND FILTERED_ADDON_LIST ${ADDON})
endforeach()
set(ENABLE_ADDONS_01 1)
# Update ENABLE_ADDON with filtered list
set(ENABLE_ADDON ${FILTERED_ADDON_LIST})
# Also update the cache to reflect the filtered list
set(ENABLE_ADDON ${FILTERED_ADDON_LIST} CACHE STRING "Filtered addon list" FORCE)
list(LENGTH ENABLE_ADDON addon_count)
if(addon_count GREATER 0)
set(ENABLE_ADDONS_01 1)
else()
message(" All addons were filtered out due to compatibility issues.")
set(ENABLE_ADDONS_01 0)
endif()
endif()
cmake_print_variables(ENABLE_SANDBOX)
if(ENABLE_SANDBOX STREQUAL "")

View File

@@ -166,10 +166,11 @@ function(generate_addon_targets addon_target)
set_target_properties(${addon_target}_C99_KERNEL_ADDON PROPERTIES FOLDER object-libs-targets)
endif()
if(("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU") AND (CMAKE_C_COMPILER_VERSION VERSION_LESS 11.2.0))
# Collect all subdirectory paths that have at least one file with suffix in ADDON_CXX_SUFS list.
get_filepaths_with_suffixes(LOCAL_SOURCE_CXX_FILES "${CMAKE_CURRENT_SOURCE_DIR}/${addon_target}" "${ADDON_CXX_SUFS}")
endif()
# Note: C++ files (JIT code) are not collected here.
# The main CMakeLists.txt already filters out aocl_gemm addon for compilers
# that don't support BF16 intrinsics (GCC < 11.2, Clang < 12.0).
# For supported compilers, we only use C files with intrinsics, not JIT.
set(LOCAL_SOURCE_CXX_FILES "")
# Only generate the object library if there is at least one source file.
list(LENGTH LOCAL_SOURCE_CXX_FILES size)

View File

@@ -4,7 +4,7 @@
"base.json"
],
"configurePresets": [
{
{
"name": "linux-make-gcc",
"inherits": "base",
"hidden": true,

29
configure vendored
View File

@@ -3441,8 +3441,37 @@ main()
# Remove duplicates in the addon list, if they exist.
addon_list=$(rm_duplicate_words_simple "${addon_list}")
# Check compiler version requirements for each addon
echo "${script_name}: configuring with addons:"
new_addon_list=""
for addon in ${addon_list}; do
# Check if this is aocl_gemm addon and verify compiler version
if [ "${addon}" = "aocl_gemm" ]; then
if [ "${cc_vendor}" = "gcc" ]; then
# aocl_gemm addon (LPGEMM) requires GCC 11.2 or newer
# due to AVX-512 intrinsics and optimization requirements.
if [ ${cc_major} -lt 11 ] || [ ${cc_major} -eq 11 -a ${cc_minor} -lt 2 ]; then
echo "${script_name}: warning: aocl_gemm addon requires GCC 11.2 or newer."
echo "${script_name}: warning: Current GCC version is ${cc_version}."
echo "${script_name}: warning: Skipping aocl_gemm addon."
continue
fi
elif [ "${cc_vendor}" = "clang" ]; then
# aocl_gemm addon (LPGEMM) requires Clang 12.0 or newer
# due to AVX-512 intrinsics and C++17 requirements.
if [ ${cc_major} -lt 12 ]; then
echo "${script_name}: warning: aocl_gemm addon requires Clang 12.0 or newer."
echo "${script_name}: warning: Current Clang version is ${cc_version}."
echo "${script_name}: warning: Skipping aocl_gemm addon."
continue
fi
fi
fi
new_addon_list="${new_addon_list} ${addon}"
done
addon_list="${new_addon_list}"
for addon in ${addon_list}; do
echo "${script_name}: ${addon_dir}/${addon}"

View File

@@ -113,7 +113,9 @@ function(generate_kernel_targets kernel_target)
# Only generate the object library if there is at least one source file.
list(LENGTH LOCAL_LPGEMM_SOURCE_FILES size_lpgemm)
if (size_lpgemm GREATER 0)
# Check if aocl_gemm addon is enabled before building LPGEMM kernels
# ENABLE_ADDON is filtered in the main CMakeLists.txt based on compiler version
if((size_lpgemm GREATER 0) AND ("aocl_gemm" IN_LIST ENABLE_ADDON))
# Create an object library using the source file list above.
add_library(${kernel_target}_LPGEMM_KERNELS
OBJECT