SWDEV-561273 - hip samples on TheRock build using HIP LANGUAGE and hip-lang package. (#1794)
This commit is contained in:
@@ -18,11 +18,7 @@
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
# THE SOFTWARE.
|
||||
|
||||
project(hipDispatchLatency)
|
||||
|
||||
cmake_minimum_required(VERSION 3.10)
|
||||
|
||||
include_directories(../../common)
|
||||
cmake_minimum_required(VERSION 3.21)
|
||||
|
||||
if(UNIX)
|
||||
if(NOT DEFINED ROCM_PATH)
|
||||
@@ -36,39 +32,55 @@ if(UNIX)
|
||||
list(APPEND CMAKE_PREFIX_PATH ${ROCM_PATH})
|
||||
endif()
|
||||
|
||||
# Find hip
|
||||
find_package(hip)
|
||||
project(hipDispatchLatency LANGUAGES CXX HIP)
|
||||
|
||||
# Set compiler and linker
|
||||
set(CMAKE_CXX_COMPILER ${HIP_HIPCC_EXECUTABLE})
|
||||
set(CMAKE_CXX_LINKER ${HIP_HIPCC_EXECUTABLE})
|
||||
set(CMAKE_BUILD_TYPE Release)
|
||||
|
||||
# Detect GPU architectures and setup OFFLOAD_ARCH_FLAGS
|
||||
include(${CMAKE_CURRENT_SOURCE_DIR}/../../common/DetectGPUArchs.cmake)
|
||||
|
||||
# Create the excutable
|
||||
if(TARGET build_utils)
|
||||
set(EXCLUDE_OPTION EXCLUDE_FROM_ALL)
|
||||
set(EXCLUDE_OPTION EXCLUDE_FROM_ALL)
|
||||
else()
|
||||
set(EXCLUDE_OPTION )
|
||||
set(EXCLUDE_OPTION)
|
||||
endif()
|
||||
|
||||
# Mark source files as HIP code
|
||||
set_source_files_properties(hipDispatchLatency.cpp PROPERTIES LANGUAGE HIP)
|
||||
set_source_files_properties(hipDispatchEnqueueRateMT.cpp PROPERTIES LANGUAGE HIP)
|
||||
set_source_files_properties(test_kernel.cpp PROPERTIES LANGUAGE HIP)
|
||||
|
||||
add_executable(hipDispatchLatency ${EXCLUDE_OPTION} hipDispatchLatency.cpp)
|
||||
add_executable(hipDispatchEnqueueRateMT ${EXCLUDE_OPTION} hipDispatchEnqueueRateMT.cpp)
|
||||
|
||||
# Generate code object
|
||||
add_custom_target(
|
||||
codeobj2
|
||||
COMMAND ${HIP_HIPCC_EXECUTABLE} --cuda-device-only ${CMAKE_CURRENT_SOURCE_DIR}/test_kernel.cpp -o test_kernel.code
|
||||
COMMENT "codeobj2 generated"
|
||||
# Generate code object using CMake's HIP language support
|
||||
# Note: Build for all detected architectures to support multiple GPUs (like hipcc does)
|
||||
add_custom_command(
|
||||
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/test_kernel.code
|
||||
COMMAND ${CMAKE_HIP_COMPILER} -x hip --cuda-device-only ${OFFLOAD_ARCH_FLAGS} ${CMAKE_CURRENT_SOURCE_DIR}/test_kernel.cpp -o ${CMAKE_CURRENT_BINARY_DIR}/test_kernel.code
|
||||
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/test_kernel.cpp
|
||||
COMMENT "Generating code object test_kernel.code for ${CMAKE_HIP_ARCHITECTURES}"
|
||||
VERBATIM
|
||||
)
|
||||
|
||||
add_custom_target(codeobj2 ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/test_kernel.code)
|
||||
|
||||
add_dependencies(hipDispatchLatency codeobj2)
|
||||
add_dependencies(hipDispatchEnqueueRateMT codeobj2)
|
||||
|
||||
# Link with HIP
|
||||
target_link_libraries(hipDispatchLatency hip::host)
|
||||
target_link_libraries(hipDispatchEnqueueRateMT hip::host)
|
||||
target_include_directories(hipDispatchLatency PRIVATE ../../common)
|
||||
target_include_directories(hipDispatchEnqueueRateMT PRIVATE ../../common)
|
||||
|
||||
if(UNIX)
|
||||
target_link_libraries(hipDispatchEnqueueRateMT pthread)
|
||||
# Set RPATH so executables can find HIP libraries at runtime
|
||||
set_target_properties(hipDispatchLatency hipDispatchEnqueueRateMT PROPERTIES
|
||||
BUILD_RPATH "${ROCM_PATH}/lib"
|
||||
INSTALL_RPATH "${ROCM_PATH}/lib"
|
||||
)
|
||||
endif()
|
||||
|
||||
set_property(TARGET hipDispatchLatency PROPERTY CXX_STANDARD 11)
|
||||
set_property(TARGET hipDispatchEnqueueRateMT PROPERTY CXX_STANDARD 11)
|
||||
|
||||
|
||||
@@ -17,12 +17,9 @@
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
# THE SOFTWARE.
|
||||
project(hipInfo)
|
||||
|
||||
# flag is set to ON in compute build for windows
|
||||
option(HIPINFO_INTERNAL_BUILD "Enable building hipInfo from compute" OFF)
|
||||
cmake_minimum_required(VERSION 3.21)
|
||||
|
||||
cmake_minimum_required(VERSION 3.10)
|
||||
if(UNIX)
|
||||
if(NOT DEFINED ROCM_PATH)
|
||||
if(DEFINED ENV{ROCM_PATH})
|
||||
@@ -35,26 +32,55 @@ if(UNIX)
|
||||
list(APPEND CMAKE_PREFIX_PATH ${ROCM_PATH})
|
||||
endif()
|
||||
|
||||
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --hip-path=${CMAKE_PREFIX_PATH}")
|
||||
# Find hip
|
||||
find_package(hip)
|
||||
# flag is set to ON in compute build for windows
|
||||
option(HIPINFO_INTERNAL_BUILD "Enable building hipInfo from compute" OFF)
|
||||
|
||||
# Windows internal build: Configure HIP compiler before project() to bypass CMake's auto-detection
|
||||
# HIPINFO_INTERNAL_BUILD is set by amd_build.py when building as part of compute project
|
||||
if(WIN32 AND HIPINFO_INTERNAL_BUILD)
|
||||
# Set HIP compiler to use same as CXX compiler (set by amd_build.py)
|
||||
if(CMAKE_CXX_COMPILER)
|
||||
set(CMAKE_HIP_COMPILER "${CMAKE_CXX_COMPILER}" CACHE FILEPATH "HIP compiler")
|
||||
endif()
|
||||
# Disable CMake's HIP architecture auto-detection (which fails on Windows)
|
||||
set(CMAKE_HIP_ARCHITECTURES OFF CACHE STRING "Disable HIP architecture detection")
|
||||
# Skip CMake's HIP compiler testing phase
|
||||
set(CMAKE_HIP_COMPILER_FORCED TRUE CACHE BOOL "Skip HIP compiler test")
|
||||
endif()
|
||||
|
||||
project(hipInfo LANGUAGES CXX HIP)
|
||||
|
||||
# Set compiler and linker
|
||||
set(CMAKE_BUILD_TYPE Release)
|
||||
|
||||
# Create the excutable
|
||||
if(TARGET build_utils)
|
||||
set(EXCLUDE_OPTION EXCLUDE_FROM_ALL)
|
||||
set(EXCLUDE_OPTION EXCLUDE_FROM_ALL)
|
||||
else()
|
||||
set(EXCLUDE_OPTION )
|
||||
set(EXCLUDE_OPTION)
|
||||
endif()
|
||||
|
||||
# Mark source file as HIP code
|
||||
set_source_files_properties(hipInfo.cpp PROPERTIES LANGUAGE HIP)
|
||||
|
||||
add_executable(hipInfo ${EXCLUDE_OPTION} hipInfo.cpp)
|
||||
|
||||
# Link with HIP
|
||||
target_link_libraries(hipInfo hip::host)
|
||||
|
||||
target_include_directories(hipInfo PRIVATE ../../common)
|
||||
|
||||
# Windows: Add HIP compile options since CMAKE_HIP_ARCHITECTURES=OFF disables automatic flag handling
|
||||
if(WIN32 AND HIPINFO_INTERNAL_BUILD)
|
||||
target_compile_options(hipInfo PRIVATE $<$<COMPILE_LANGUAGE:HIP>:-x hip --hip-path=${CMAKE_PREFIX_PATH}>)
|
||||
target_link_directories(hipInfo PRIVATE ${CMAKE_PREFIX_PATH}/lib)
|
||||
target_link_libraries(hipInfo PRIVATE amdhip64)
|
||||
endif()
|
||||
|
||||
# Set RPATH so executable can find HIP libraries at runtime
|
||||
if(UNIX)
|
||||
set_target_properties(hipInfo PROPERTIES
|
||||
BUILD_RPATH "${ROCM_PATH}/lib"
|
||||
INSTALL_RPATH "${ROCM_PATH}/lib"
|
||||
)
|
||||
endif()
|
||||
|
||||
# Used only when make install is called
|
||||
# when hipInfo is built as part of compute project
|
||||
# hipInfo.exe will be installed to install/hip/bin path
|
||||
@@ -63,5 +89,5 @@ if (WIN32 AND HIPINFO_INTERNAL_BUILD)
|
||||
endif()
|
||||
|
||||
if(TARGET build_utils)
|
||||
add_dependencies(build_utils hipInfo)
|
||||
add_dependencies(build_utils hipInfo)
|
||||
endif()
|
||||
|
||||
Viittaa uudesa ongelmassa
Block a user