SWDEV-561273 - hip samples on TheRock build using HIP LANGUAGE and hip-lang package. (#1794)
This commit is contained in:
@@ -20,9 +20,7 @@
|
||||
|
||||
#Follow "README.md" to generate square.cpp if it's missing
|
||||
|
||||
project(square)
|
||||
|
||||
cmake_minimum_required(VERSION 3.10)
|
||||
cmake_minimum_required(VERSION 3.21)
|
||||
|
||||
if(UNIX)
|
||||
if(NOT DEFINED ROCM_PATH)
|
||||
@@ -36,27 +34,31 @@ if(UNIX)
|
||||
list(APPEND CMAKE_PREFIX_PATH ${ROCM_PATH})
|
||||
endif()
|
||||
|
||||
project(square LANGUAGES CXX HIP)
|
||||
|
||||
# create square.cpp
|
||||
execute_process(COMMAND sh -c "${ROCM_PATH}/bin/hipify-perl \
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/square.cu > ${CMAKE_CURRENT_BINARY_DIR}/square.cpp")
|
||||
|
||||
# Find hip
|
||||
find_package(hip)
|
||||
|
||||
# Set compiler and linker
|
||||
set(CMAKE_CXX_COMPILER ${HIP_HIPCC_EXECUTABLE})
|
||||
set(CMAKE_CXX_LINKER ${HIP_HIPCC_EXECUTABLE})
|
||||
|
||||
# Create the excutable
|
||||
if(TARGET build_intro)
|
||||
set(EXCLUDE_OPTION EXCLUDE_FROM_ALL)
|
||||
else()
|
||||
set(EXCLUDE_OPTION )
|
||||
set(EXCLUDE_OPTION)
|
||||
endif()
|
||||
|
||||
# Mark source file as HIP code (contains __global__ kernels)
|
||||
set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/square.cpp PROPERTIES LANGUAGE HIP)
|
||||
|
||||
add_executable(square ${EXCLUDE_OPTION} ${CMAKE_CURRENT_BINARY_DIR}/square.cpp)
|
||||
|
||||
# Link with HIP
|
||||
target_link_libraries(square hip::host)
|
||||
# Set RPATH so executable can find HIP libraries at runtime
|
||||
if(UNIX)
|
||||
set_target_properties(square PROPERTIES
|
||||
BUILD_RPATH "${ROCM_PATH}/lib"
|
||||
INSTALL_RPATH "${ROCM_PATH}/lib"
|
||||
)
|
||||
endif()
|
||||
|
||||
if(TARGET build_intro)
|
||||
add_dependencies(build_intro square)
|
||||
|
||||
Reference in New Issue
Block a user