SWDEV-561273 - hip samples on TheRock build using HIP LANGUAGE and hip-lang package. (#1794)

This commit is contained in:
Jaydeep
2026-01-29 13:45:58 +05:30
committed by GitHub
parent fa6f071751
commit 190d9a8e27
30 changed files with 740 additions and 430 deletions
@@ -18,11 +18,7 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
project(module_api)
cmake_minimum_required(VERSION 3.10)
include_directories(../../common)
cmake_minimum_required(VERSION 3.21)
if(UNIX)
if(NOT DEFINED ROCM_PATH)
@@ -36,41 +32,57 @@ if(UNIX)
list(APPEND CMAKE_PREFIX_PATH ${ROCM_PATH})
endif()
# Find hip
find_package(hip)
project(module_api LANGUAGES CXX HIP)
# Set compiler and linker
set(CMAKE_CXX_COMPILER ${HIP_HIPCC_EXECUTABLE})
set(CMAKE_CXX_LINKER ${HIP_HIPCC_EXECUTABLE})
# Detect GPU architectures and setup OFFLOAD_ARCH_FLAGS
include(${CMAKE_CURRENT_SOURCE_DIR}/../../common/DetectGPUArchs.cmake)
# Create the excutable
if(TARGET build_intro)
set(EXCLUDE_OPTION EXCLUDE_FROM_ALL)
else()
set(EXCLUDE_OPTION )
set(EXCLUDE_OPTION)
endif()
# Mark source files as HIP (they use HIP runtime APIs)
set_source_files_properties(runKernel.cpp PROPERTIES LANGUAGE HIP)
set_source_files_properties(launchKernelHcc.cpp PROPERTIES LANGUAGE HIP)
set_source_files_properties(defaultDriver.cpp PROPERTIES LANGUAGE HIP)
set_source_files_properties(vcpy_kernel.cpp PROPERTIES LANGUAGE HIP)
add_executable(runKernel.hip.out ${EXCLUDE_OPTION} runKernel.cpp)
add_executable(launchKernelHcc.hip.out ${EXCLUDE_OPTION} launchKernelHcc.cpp)
add_executable(defaultDriver.hip.out ${EXCLUDE_OPTION} defaultDriver.cpp)
# Generate code object
add_custom_target(
codeobj
COMMAND ${HIP_HIPCC_EXECUTABLE} --cuda-device-only ${CMAKE_CURRENT_SOURCE_DIR}/vcpy_kernel.cpp -o vcpy_kernel.code
COMMENT "codeobj 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}/vcpy_kernel.code
COMMAND ${CMAKE_HIP_COMPILER} -x hip --cuda-device-only ${OFFLOAD_ARCH_FLAGS} ${CMAKE_CURRENT_SOURCE_DIR}/vcpy_kernel.cpp -o ${CMAKE_CURRENT_BINARY_DIR}/vcpy_kernel.code
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/vcpy_kernel.cpp
COMMENT "Generating code object vcpy_kernel.code for ${CMAKE_HIP_ARCHITECTURES}"
VERBATIM
)
add_custom_target(codeobj ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/vcpy_kernel.code)
add_dependencies(runKernel.hip.out codeobj)
add_dependencies(launchKernelHcc.hip.out codeobj)
add_dependencies(defaultDriver.hip.out codeobj)
# Link with HIP
target_link_libraries(runKernel.hip.out hip::host)
target_link_libraries(launchKernelHcc.hip.out hip::host)
target_link_libraries(defaultDriver.hip.out hip::host)
target_include_directories(runKernel.hip.out PRIVATE ../../common)
target_include_directories(launchKernelHcc.hip.out PRIVATE ../../common)
target_include_directories(defaultDriver.hip.out PRIVATE ../../common)
# Set RPATH so executables can find HIP libraries at runtime
if(UNIX)
set_target_properties(runKernel.hip.out launchKernelHcc.hip.out defaultDriver.hip.out PROPERTIES
BUILD_RPATH "${ROCM_PATH}/lib"
INSTALL_RPATH "${ROCM_PATH}/lib"
)
endif()
if(TARGET build_intro)
add_dependencies(build_intro runKernel.hip.out launchKernelHcc.hip.out defaultDriver.hip.out)
endif()
add_dependencies(build_intro runKernel.hip.out launchKernelHcc.hip.out defaultDriver.hip.out)
endif()