Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/instrumentation/InstrumentationCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,22 @@ std::string getBitcodePath(const llvm::Module &M) {
arch = "unknown";
}

// Architecture -> bitcode suffix mapping. Must match the bitcode
// variants emitted by dh_comms (see dh_comms/CMakeLists.txt):
// gfx94x -> _cdna3 (legacy bundled bitcode)
// gfx90a -> _cdna2 (legacy bundled bitcode)
// other gfx* -> _<arch> per-arch bitcode (e.g. gfx908 -> _gfx908)
// unknown -> warn and best-effort fall back to _cdna2
if (arch == "gfx940" || arch == "gfx941" || arch == "gfx942") {
CDNAVersion = "_cdna3";
} else if (arch == "gfx90a") {
CDNAVersion = "_cdna2";
} else if (arch.size() >= 3 && arch.substr(0, 3) == "gfx") {
CDNAVersion = "_" + arch;
} else {
llvm::errs() << "Warning: architecture '" << arch
<< "' has no matching bitcode. "
<< "Falling back to cdna2.\n";
CDNAVersion = "_cdna2";
}

Expand Down
23 changes: 19 additions & 4 deletions tests/test_kernels/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,29 @@ set(INST_PLUGIN "${CMAKE_BINARY_DIR}/lib/plugins/libAMDGCNSubmitAddressMessages-
set(DH_COMMS_LIB_DIR "${CMAKE_BINARY_DIR}/external/dh_comms/lib")
set(BITCODE_DIR "${CMAKE_BINARY_DIR}/lib/bitcode")

# Build the list of bitcode files to copy (must mirror dh_comms/CMakeLists.txt)
set(BITCODE_COPY_FILES
${DH_COMMS_LIB_DIR}/dh_comms_dev_cdna2_co5.bc
${DH_COMMS_LIB_DIR}/dh_comms_dev_cdna2_co6.bc
${DH_COMMS_LIB_DIR}/dh_comms_dev_cdna3_co5.bc
${DH_COMMS_LIB_DIR}/dh_comms_dev_cdna3_co6.bc
)
foreach(ARCH IN LISTS CMAKE_HIP_ARCHITECTURES)
# Strip arch features such as ":xnack+" so the resulting filename
# (e.g. dh_comms_dev_gfx908_co5.bc) matches what dh_comms emits.
string(REGEX REPLACE ":.*$" "" ARCH_BASE "${ARCH}")
list(APPEND BITCODE_COPY_FILES
${DH_COMMS_LIB_DIR}/dh_comms_dev_${ARCH_BASE}_co5.bc
${DH_COMMS_LIB_DIR}/dh_comms_dev_${ARCH_BASE}_co6.bc
)
endforeach()
list(REMOVE_DUPLICATES BITCODE_COPY_FILES)

# Copy all bitcode files to build/lib/bitcode/
add_custom_target(copy_bitcode ALL
COMMAND ${CMAKE_COMMAND} -E make_directory ${BITCODE_DIR}
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${DH_COMMS_LIB_DIR}/dh_comms_dev_cdna2_co5.bc
${DH_COMMS_LIB_DIR}/dh_comms_dev_cdna3_co5.bc
${DH_COMMS_LIB_DIR}/dh_comms_dev_cdna2_co6.bc
${DH_COMMS_LIB_DIR}/dh_comms_dev_cdna3_co6.bc
${BITCODE_COPY_FILES}
${BITCODE_DIR}/
DEPENDS dh_comms_bc
COMMENT "Copying bitcode files to build/lib/bitcode/"
Expand Down