Skip to content
Open
107 changes: 56 additions & 51 deletions projects/hiptensor/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,29 @@ message(STATUS "CMake version: ${CMAKE_VERSION}")

# NOTE: This has to be initialized before the project() command appears
# Set the default of CMAKE_BUILD_TYPE to be release, unless user specifies with -D. MSVC_IDE does not use CMAKE_BUILD_TYPE
if( NOT DEFINED CMAKE_CONFIGURATION_TYPES AND NOT DEFINED CMAKE_BUILD_TYPE )
set( CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel." )
if(NOT DEFINED CMAKE_CONFIGURATION_TYPES AND NOT DEFINED CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel.")
endif()
message(STATUS "CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}")
set(CMAKE_EXPORT_COMPILE_COMMANDS ON CACHE BOOL "" FORCE )
set(CMAKE_EXPORT_COMPILE_COMMANDS ON CACHE BOOL "" FORCE)

if(NOT DEFINED CMAKE_INSTALL_PREFIX)
set(CMAKE_INSTALL_PREFIX "/opt/rocm" CACHE PATH "Install path prefix, prepended onto install directories")
if(NOT WIN32)
set(CMAKE_INSTALL_PREFIX "/opt/rocm" CACHE PATH "Install path prefix, prepended onto install directories")
else()
set(CMAKE_INSTALL_PREFIX "C:/dist/TheRock" CACHE PATH "Install path prefix, prepended onto install directories")
endif()
endif()
if( NOT DEFINED CPACK_PACKAGING_INSTALL_PREFIX )
set(CPACK_PACKAGING_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}" CACHE PATH "Install path prefix for packages.")
set(CPACK_SET_DESTDIR OFF)
if(NOT DEFINED CPACK_PACKAGING_INSTALL_PREFIX)
set(CPACK_PACKAGING_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}" CACHE PATH "Install path prefix for packages.")
set(CPACK_SET_DESTDIR OFF)
endif()

# This helps cmake properly find hip-config.cmake
list( APPEND CMAKE_PREFIX_PATH $ENV{ROCM_PATH} ${ROCM_PATH} /opt/rocm )
list(APPEND CMAKE_PREFIX_PATH $ENV{ROCM_PATH} ${ROCM_PATH} /opt/rocm)
# Append our library helper cmake path and the cmake path for hip (for convenience).
# Users may override HIP path by specifying their own in CMAKE_MODULE_PATH
list( APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake )
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)

# Build shared libs
set(BUILD_SHARED_LIBS ON)
Expand All @@ -63,13 +67,13 @@ set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g -O1 -ggdb") # c
set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} -O2 -DNDEBUG") # clang++ failed to build the project with the default -Os

# Project options
if( CMAKE_PROJECT_NAME STREQUAL "hiptensor" )
option( HIPTENSOR_BUILD_TESTS "Build hiptensor tests" ON )
option( HIPTENSOR_BUILD_SAMPLES "Build hiptensor samples" ON )
option( HIPTENSOR_BUILD_COMPRESSED_DBG "Enable compressed debug symbols" ON )
option( HIPTENSOR_DEFAULT_STRIDES_COL_MAJOR "Set hiptensor default strides to column major" ON )
option( BUILD_OFFLOAD_COMPRESS "Build hiptensor with offload compression" ON )
option( HIPTENSOR_CODE_COVERAGE "Build with code coverage flags (clang only)" OFF )
if(CMAKE_PROJECT_NAME STREQUAL "hiptensor")
option(HIPTENSOR_BUILD_TESTS "Build hiptensor tests" ON)
option(HIPTENSOR_BUILD_SAMPLES "Build hiptensor samples" ON)
option(HIPTENSOR_BUILD_COMPRESSED_DBG "Enable compressed debug symbols" ON)
option(HIPTENSOR_DEFAULT_STRIDES_COL_MAJOR "Set hiptensor default strides to column major" ON)
option(BUILD_OFFLOAD_COMPRESS "Build hiptensor with offload compression" ON)
option(HIPTENSOR_CODE_COVERAGE "Build with code coverage flags (clang only)" OFF)
endif()

# Setup output paths
Expand All @@ -93,9 +97,10 @@ include(CheckCXXCompilerFlag)
include(cmake/Macros/CheckF8.cmake)
check_f8(F8_EXISTS)
if(F8_EXISTS)
message( STATUS "Performing Test `__hip_fp8_e5m2` and `__hip_fp8_e4m3` - Success" )
message(STATUS "Performing Test `__hip_fp8_e5m2` and `__hip_fp8_e4m3` - Success")
else()
message(FATAL_ERROR "The detected ROCm does not support data type `__hip_fp8_e5m2` or `__hip_fp8_e4m3`.")
# Inform but do not fail the build, as these data types are not required for the library to function.
message(STATUS "The detected ROCm does not support data type `__hip_fp8_e5m2` or `__hip_fp8_e4m3`.")
endif()

# check if asan is enabled
Expand All @@ -111,23 +116,23 @@ endif()
include(cmake/Functions/hiptensorSupportedArchitectures.cmake)
if (ADDRESS_SANITIZER_ENABLED)
rocm_check_target_ids(DEFAULT_GPU_TARGETS
TARGETS "gfx90a:xnack+;gfx942:xnack+;gfx950:xnack+" )
TARGETS "gfx90a:xnack+;gfx942:xnack+;gfx950:xnack+")
else()
hiptensor_get_supported_architectures(SUPPORTED_ARCHS)
hiptensor_get_default_architectures(DEFAULT_ARCHS)
rocm_check_target_ids(DEFAULT_GPU_TARGETS
TARGETS ${SUPPORTED_ARCHS} )
TARGETS ${DEFAULT_ARCHS})
endif()

# Check if offload compression is supported
include(CheckCXXCompilerFlag)
if (BUILD_OFFLOAD_COMPRESS)
check_cxx_compiler_flag("--offload-compress" CXX_COMPILER_SUPPORTS_OFFLOAD_COMPRESS)
if (NOT CXX_COMPILER_SUPPORTS_OFFLOAD_COMPRESS)
message(WARNING "BUILD_OFFLOAD_COMPRESS=ON but flag not supported by compiler. Ignoring option." )
set(CMAKE_NO_BUILTIN_CHRPATH ON)
else()
set(CMAKE_NO_BUILTIN_CHRPATH OFF)
endif()
check_cxx_compiler_flag("--offload-compress" CXX_COMPILER_SUPPORTS_OFFLOAD_COMPRESS)
if (NOT CXX_COMPILER_SUPPORTS_OFFLOAD_COMPRESS)
message(WARNING "BUILD_OFFLOAD_COMPRESS=ON but flag not supported by compiler. Ignoring option.")
set(CMAKE_NO_BUILTIN_CHRPATH ON)
else()
set(CMAKE_NO_BUILTIN_CHRPATH OFF)
endif()
endif()

# Variable GPU_TARGET must be a cached variable and must be specified before calling find_package(hip)
Expand All @@ -136,42 +141,42 @@ endif()
#
# By rule, once cached variable is set, it cannot be overridden unless we use the FORCE option
if(GPU_TARGETS)
set(GPU_TARGETS "${GPU_TARGETS}" CACHE STRING "List of specific machine types for library to target")
set(GPU_TARGETS "${GPU_TARGETS}" CACHE STRING "List of specific machine types for library to target")
elseif(AMDGPU_TARGETS)
set(GPU_TARGETS "${AMDGPU_TARGETS}" CACHE STRING "List of specific machine types for library to target")
message(DEPRECATION "AMDGPU_TARGETS use is deprecated. Use GPU_TARGETS.")
set(GPU_TARGETS "${AMDGPU_TARGETS}" CACHE STRING "List of specific machine types for library to target")
message(DEPRECATION "AMDGPU_TARGETS use is deprecated. Use GPU_TARGETS.")
else()
set(GPU_TARGETS "${DEFAULT_GPU_TARGETS}" CACHE STRING "List of specific machine types for library to target")
set(GPU_TARGETS "${DEFAULT_GPU_TARGETS}" CACHE STRING "List of specific machine types for library to target")
endif()
message(STATUS "GPU_TARGETS=${GPU_TARGETS}")

if(HIPTENSOR_DEFAULT_STRIDES_COL_MAJOR)
add_compile_definitions(HIPTENSOR_DEFAULT_STRIDES_COL_MAJOR=1)
add_compile_definitions(HIPTENSOR_DEFAULT_STRIDES_COL_MAJOR=1)
else()
add_compile_definitions(HIPTENSOR_DEFAULT_STRIDES_COL_MAJOR=0)
add_compile_definitions(HIPTENSOR_DEFAULT_STRIDES_COL_MAJOR=0)
endif()
message(STATUS "HIPTENSOR_DEFAULT_STRIDES_COL_MAJOR=${HIPTENSOR_DEFAULT_STRIDES_COL_MAJOR}")

# Setup HIP
find_package(hip REQUIRED )
find_package(hip REQUIRED)
math(EXPR hip_VERSION_FLAT "(${hip_VERSION_MAJOR} * 1000 + ${hip_VERSION_MINOR}) * 100000 + ${hip_VERSION_PATCH}")
message(STATUS "hip_version_flat=${hip_VERSION_FLAT}")

# No assumption that HIP kernels are launched with uniform block size for backward compatibility
# SWDEV-413293 and https://reviews.llvm.org/D155213
if(NOT WIN32 AND ${hip_VERSION_FLAT} GREATER 500723302)
message(STATUS "Adding the fno-offload-uniform-block compiler flag")
add_compile_options(-fno-offload-uniform-block)
message(STATUS "Adding the fno-offload-uniform-block compiler flag")
add_compile_options(-fno-offload-uniform-block)
endif()
# Add optimization flags needed by backend
if(NOT WIN32 AND ${hip_VERSION_FLAT} GREATER 600140090)
message(STATUS "Adding the enable-post-misched=0 compiler flag")
add_compile_options("SHELL: -mllvm -enable-post-misched=0")
message(STATUS "Adding the enable-post-misched=0 compiler flag")
add_compile_options("SHELL: -mllvm -enable-post-misched=0")
endif()
if(NOT WIN32 AND ${hip_VERSION_FLAT} GREATER 600241132)
message(STATUS "Adding -amdgpu-early-inline-all=true and -amdgpu-function-calls=false")
add_compile_options("SHELL: -mllvm -amdgpu-early-inline-all=true")
add_compile_options("SHELL: -mllvm -amdgpu-function-calls=false")
message(STATUS "Adding -amdgpu-early-inline-all=true and -amdgpu-function-calls=false")
add_compile_options("SHELL: -mllvm -amdgpu-early-inline-all=true")
add_compile_options("SHELL: -mllvm -amdgpu-function-calls=false")
endif()

if(HIPTENSOR_CODE_COVERAGE)
Expand All @@ -190,29 +195,29 @@ add_subdirectory(library/src)

# Configure testing setup
if(HIPTENSOR_BUILD_TESTS OR HIPTENSOR_BUILD_SAMPLES)
enable_testing()
rocm_package_setup_component(clients)
enable_testing()
rocm_package_setup_component(clients)
endif()

# Configure tests build
if(HIPTENSOR_BUILD_TESTS)
rocm_package_setup_client_component(tests)
add_subdirectory(test)
rocm_package_setup_client_component(tests)
add_subdirectory(test)
endif()

# Configure clients build
if(HIPTENSOR_BUILD_SAMPLES)
rocm_package_setup_client_component(samples)
add_subdirectory(samples)
rocm_package_setup_client_component(samples)
add_subdirectory(samples)
endif()

# Versioning via rocm-cmake
set ( VERSION_STRING "2.2.0" )
rocm_setup_version( VERSION ${VERSION_STRING} )
set (VERSION_STRING "2.2.0")
rocm_setup_version(VERSION ${VERSION_STRING})

# Configure a header file to pass the CMake version settings to the source
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/library/include/hiptensor/internal/hiptensor-version.h.in"
"${CMAKE_CURRENT_SOURCE_DIR}/library/include/hiptensor/internal/hiptensor-version.h" )
"${CMAKE_CURRENT_SOURCE_DIR}/library/include/hiptensor/internal/hiptensor-version.h")

# Define package dependencies for export
set(PACKAGE_DEPENDS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ set(SUPPORTED_ARCHITECTURES
gfx12-generic
)

set(DEFAULT_ARCHITECTURES
gfx908
gfx90a
gfx942
gfx950
gfx11-generic
gfx12-generic
)

function(hiptensor_is_supported_architecture ARCHITECTURE_NAME RESULT_VAR)
list(FIND SUPPORTED_ARCHITECTURES "${ARCHITECTURE_NAME}" INDEX)
if (INDEX EQUAL -1)
Expand All @@ -26,7 +35,7 @@ function(hiptensor_is_supported_architecture ARCHITECTURE_NAME RESULT_VAR)
endif()
endfunction()

function(hiptensor_get_supported_architectures RESULT_VAR)
string(JOIN ";" SUPPORTED_ARCHITECTURES_STRING ${SUPPORTED_ARCHITECTURES})
set(${RESULT_VAR} "${SUPPORTED_ARCHITECTURES_STRING}" PARENT_SCOPE)
function(hiptensor_get_default_architectures RESULT_VAR)
string(JOIN ";" DEFAULT_ARCHITECTURES_STRING ${DEFAULT_ARCHITECTURES})
set(${RESULT_VAR} "${DEFAULT_ARCHITECTURES_STRING}" PARENT_SCOPE)
endfunction()
Loading
Loading