@@ -235,6 +235,22 @@ set(SHARE_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/share CACHE PATH "share install di
235235set (CONFIG_PACKAGE_INSTALL_DIR ${LIB_INSTALL_DIR} /cmake/hip CACHE PATH "cmake config install dir" )
236236set (CONFIG_LANG_PACKAGE_INSTALL_DIR ${LIB_INSTALL_DIR} /cmake/hip-lang CACHE PATH "cmake lang install dir" )
237237
238+ set (HAVE_CLANG_NEW_OFFLOAD_DRIVER OFF )
239+ if (LLVM_VERSION_MAJOR GREATER_EQUAL 23)
240+ # LLVM-22: The new offload driver exists on this version but HIPSPV
241+ # toolchain doesn't support it.
242+ #
243+ # LLVM-23: HIPSPV toolchain supports the new offload driver. The new
244+ # offload driver is enabled by default. To disable it
245+ # --no-offload-new-driver needs to be issued in HIP compilation and
246+ # link steps.
247+ #
248+ # LLVM-23+: the old offload driver may be removed.
249+ set (HAVE_CLANG_NEW_OFFLOAD_DRIVER ON )
250+ endif ()
251+
252+ include (CMakeDependentOption )
253+
238254# HIP options
239255option (STANDALONE_TESTS "Create a separate executable for each test instead of combining tests into a shared lib by category" ON )
240256
@@ -281,6 +297,10 @@ option(OCML_BASIC_ROUNDED_OPERATIONS "Use OCML implementations for devicelib fun
281297option (CHIP_MALI_GPU_WORKAROUNDS "Apply work-arounds for avoiding SPIR-V \
282298consumption issues in ARM Mali GPU driver." OFF )
283299
300+ cmake_dependent_option (
301+ USE_NEW_OFFLOAD_DRIVER "Use Clang's new offload driver."
302+ ON HAVE_CLANG_NEW_OFFLOAD_DRIVER OFF )
303+
284304if (CHIP_EXT_FLOAT_ATOMICS)
285305 message (DEPRECATION "-DCHIP_EXT_FLOAT_ATOMICS is no longer effective." )
286306endif ()
@@ -404,7 +424,15 @@ endif()
404424
405425message (STATUS "chipStar will be installed to: ${CMAKE_INSTALL_PREFIX} " )
406426
407- set (OFFLOAD_TRIPLE spirv64)
427+ if (LLVM_VERSION_MAJOR GREATER_EQUAL 23)
428+ # On LLVM-23+ the emitted SPIR-V version can be controlled with
429+ # subarch string (v#.#). The new "chipstar" OS component sets
430+ # allowed SPIR-V extensions tailored for chipStar.
431+ set (OFFLOAD_TRIPLE spirv64v1.2-unknown-chipstar)
432+ else ()
433+ set (OFFLOAD_TRIPLE spirv64)
434+ endif ()
435+
408436# =============================================================================
409437# chipStar BINARIES & TESTS
410438add_subdirectory (llvm_passes )
@@ -415,6 +443,7 @@ add_subdirectory(bitcode)
415443target_sources (CHIP PRIVATE $<TARGET_OBJECTS :rtdevlib >)
416444
417445set (HIPCC_BUILD_PATH "${CMAKE_BINARY_DIR} /bin" )
446+ set (HIPCC_SPIRV_TRIPLE ${OFFLOAD_TRIPLE} )
418447add_subdirectory (HIPCC )
419448
420449# Override stale version set by HIPCC subdirectory with values from HIP/VERSION
@@ -595,22 +624,39 @@ set(HIP_OFFLOAD_COMPILE_ONLY_OPTIONS_
595624 # excludes the wrappers.
596625 -nohipwrapperinc)
597626
627+ if (LLVM_VERSION_MAJOR GREATER_EQUAL 23 AND NOT USE_NEW_OFFLOAD_DRIVER)
628+ list (APPEND HIP_OFFLOAD_COMPILE_ONLY_OPTIONS_ --no -offload-new-driver)
629+ endif ()
630+
598631# Include a header for applying fixups before any user or system includes.
599632set (HIP_FIXUPS_HEADER_BUILD
600633 -include ${CMAKE_SOURCE_DIR} /include/hip/spirv_fixups.h)
601634set (HIP_FIXUPS_HEADER_INSTALL
602635 -include ${CMAKE_INSTALL_PREFIX} /include/hip/spirv_fixups.h)
603636
604637# Flags needed additionally for linking phase with -fgpu-rdc.
605- set (HIP_RDC_SUPPLEMENT_LINK_FLAGS_
606- # Infors clang the type of the code object inputs (which are different than
607- # in regular host C/C++ linking)
608- --hip-link
609- # Required for selecting HIPSPV toolchain instead of AMD's one in clang.
610- --offload=spirv64
611- # --hip-path is also needed but not included here (different option
612- # value is needed for build and installation).
613- )
638+ #
639+ # --hip-path is also needed in RDC linking stage but on purpose it is
640+ # not added to HIP_RDC_SUPPLEMENT_LINK_FLAGS_ (different option value
641+ # is needed for build and installation). The option is used to
642+ # implicitly load and run chipStar's LLVM passes during this stage.
643+ #
644+ # On the new offload driver, the --hip-path needs to be wrapped in
645+ # -Xoffload-compiler-${OFFLOAD_TRIPLE}.
646+ if (USE_NEW_OFFLOAD_DRIVER)
647+ set (HIP_RDC_SUPPLEMENT_LINK_FLAGS_ --offload-link)
648+ else ()
649+ set (HIP_RDC_SUPPLEMENT_LINK_FLAGS_
650+ # Infors clang the type of the code object inputs (which are different than
651+ # in regular host C/C++ linking).
652+ --hip-link
653+ # Required for selecting HIPSPV toolchain instead of AMD's one in clang.
654+ --offload=${OFFLOAD_TRIPLE} )
655+
656+ if (LLVM_VERSION_MAJOR GREATER_EQUAL 23)
657+ list (APPEND HIP_RDC_SUPPLEMENT_LINK_FLAGS_ --no -offload-new-driver)
658+ endif ()
659+ endif ()
614660
615661if (NOT CLANG_VERSION_LESS_15)
616662 list (APPEND HIP_RDC_SUPPLEMENT_LINK_FLAGS_
@@ -728,13 +774,16 @@ target_link_libraries(host INTERFACE CHIP)
728774add_library (deviceRDCInternal INTERFACE )
729775target_compile_options (deviceRDCInternal INTERFACE -fgpu-rdc )
730776target_link_options (deviceRDCInternal INTERFACE
731- -fgpu-rdc ${HIP_RDC_SUPPLEMENT_LINK_FLAGS_} --hip-path=${CMAKE_BINARY_DIR} )
777+ -fgpu-rdc ${HIP_RDC_SUPPLEMENT_LINK_FLAGS_}
778+ $<$<BOOL :${USE_NEW_OFFLOAD_DRIVER} >:-Xoffload -compiler -${OFFLOAD_TRIPLE} >
779+ --hip-path=${CMAKE_BINARY_DIR} )
732780target_link_libraries (deviceRDCInternal INTERFACE deviceInternal )
733781
734782add_library (deviceRDC INTERFACE )
735783target_compile_options (deviceRDC INTERFACE -fgpu-rdc )
736784target_link_options (deviceRDC INTERFACE
737785 -fgpu-rdc ${HIP_RDC_SUPPLEMENT_LINK_FLAGS_}
786+ $<$<BOOL :${USE_NEW_OFFLOAD_DRIVER} >:-Xoffload -compiler -${OFFLOAD_TRIPLE} >
738787 --hip-path=${CMAKE_INSTALL_PREFIX} )
739788target_link_libraries (deviceRDC INTERFACE device )
740789
@@ -822,9 +871,15 @@ add_to_config(_hipInfo_install
822871 HIP_OFFLOAD_COMPILE_OPTIONS "${HIP_OFFLOAD_COMPILE_OPTIONS_INSTALL} " )
823872add_to_config (_hipInfo_install
824873 HIP_OFFLOAD_LINK_OPTIONS "${HIP_OFFLOAD_LINK_OPTIONS_INSTALL} " )
825- add_to_config (_hipInfo_install
826- HIP_OFFLOAD_RDC_SUPPLEMENT_LINK_OPTIONS
827- "${HIP_RDC_SUPPLEMENT_LINK_FLAGS} --hip-path=${CMAKE_INSTALL_PREFIX} " )
874+ if (USE_NEW_OFFLOAD_DRIVER)
875+ add_to_config (_hipInfo_install
876+ HIP_OFFLOAD_RDC_SUPPLEMENT_LINK_OPTIONS
877+ "${HIP_RDC_SUPPLEMENT_LINK_FLAGS} -Xoffload-compiler-${OFFLOAD_TRIPLE} --hip-path=${CMAKE_INSTALL_PREFIX} " )
878+ else ()
879+ add_to_config (_hipInfo_install
880+ HIP_OFFLOAD_RDC_SUPPLEMENT_LINK_OPTIONS
881+ "${HIP_RDC_SUPPLEMENT_LINK_FLAGS} --hip-path=${CMAKE_INSTALL_PREFIX} " )
882+ endif ()
828883
829884# Build version
830885set (_hipInfo_build "# Auto-generated by cmake on ${_timestamp} UTC\n " )
@@ -837,9 +892,15 @@ add_to_config(_hipInfo_build
837892 HIP_OFFLOAD_COMPILE_OPTIONS "${HIP_OFFLOAD_COMPILE_OPTIONS_BUILD} " )
838893add_to_config (_hipInfo_build
839894 HIP_OFFLOAD_LINK_OPTIONS "${HIP_OFFLOAD_LINK_OPTIONS_BUILD} " )
840- add_to_config (_hipInfo_build
841- HIP_OFFLOAD_RDC_SUPPLEMENT_LINK_OPTIONS
842- "${HIP_RDC_SUPPLEMENT_LINK_FLAGS} --hip-path=${CMAKE_BINARY_DIR} " )
895+ if (USE_NEW_OFFLOAD_DRIVER)
896+ add_to_config (_hipInfo_build
897+ HIP_OFFLOAD_RDC_SUPPLEMENT_LINK_OPTIONS
898+ "${HIP_RDC_SUPPLEMENT_LINK_FLAGS} -Xoffload-compiler-${OFFLOAD_TRIPLE} --hip-path=${CMAKE_BINARY_DIR} " )
899+ else ()
900+ add_to_config (_hipInfo_build
901+ HIP_OFFLOAD_RDC_SUPPLEMENT_LINK_OPTIONS
902+ "${HIP_RDC_SUPPLEMENT_LINK_FLAGS} --hip-path=${CMAKE_BINARY_DIR} " )
903+ endif ()
843904
844905add_library (hip::host ALIAS host )
845906add_library (hip::device ALIAS device )
0 commit comments