Revert "SWDEV-433371 - use comgr to unbundle code objects"

This reverts commit e53df57ffe.

Reason for revert: <INSERT REASONING HERE>
New comgr unbundling action leads to perf drop for uncompressed code object.   Will create a new patch to use old path for uncompressed , new unbundling api for compressed . 

Change-Id: I41ef53b71fc9f7aaa8cf231d4d70945f1117db52
Цей коміт міститься в:
Tao Sang
2024-05-13 12:21:06 -04:00
зафіксовано Maneesh Gupta
джерело a4dbc97bd7
коміт a1350fe8c1
11 змінених файлів з 427 додано та 474 видалено
+33
Переглянути файл
@@ -441,6 +441,39 @@ bool isCodeObjectCompatibleWithDevice(std::string co_triple_target_id,
return true;
}
bool UnbundleBitCode(const std::vector<char>& bundled_llvm_bitcode, const std::string& isa,
size_t& co_offset, size_t& co_size) {
std::string magic(bundled_llvm_bitcode.begin(),
bundled_llvm_bitcode.begin() + bundle_magic_string_size);
if (magic.compare(CLANG_OFFLOAD_BUNDLER_MAGIC_STR)) {
// Handle case where the whole file is unbundled
return true;
}
std::string bundled_llvm_bitcode_s(bundled_llvm_bitcode.begin(),
bundled_llvm_bitcode.begin() + bundled_llvm_bitcode.size());
const void* data = reinterpret_cast<const void*>(bundled_llvm_bitcode_s.c_str());
const auto obheader = reinterpret_cast<const __ClangOffloadBundleHeader*>(data);
const auto* desc = &obheader->desc[0];
for (uint64_t idx = 0; idx < obheader->numOfCodeObjects; ++idx,
desc = reinterpret_cast<const __ClangOffloadBundleInfo*>(
reinterpret_cast<uintptr_t>(&desc->bundleEntryId[0]) +
desc->bundleEntryIdSize)) {
const void* image =
reinterpret_cast<const void*>(reinterpret_cast<uintptr_t>(obheader) + desc->offset);
const size_t image_size = desc->size;
std::string bundleEntryId{desc->bundleEntryId, desc->bundleEntryIdSize};
// Check if the device id and code object id are compatible
if (isCodeObjectCompatibleWithDevice(bundleEntryId, isa)) {
co_offset = (reinterpret_cast<uintptr_t>(image) - reinterpret_cast<uintptr_t>(data));
co_size = image_size;
break;
}
}
return true;
}
bool addCodeObjData(amd_comgr_data_set_t& input, const std::vector<char>& source,
const std::string& name, const amd_comgr_data_kind_t type) {
amd_comgr_data_t data;
+2
Переглянути файл
@@ -31,6 +31,8 @@ THE SOFTWARE.
namespace hiprtc {
namespace helpers {
bool UnbundleBitCode(const std::vector<char>& bundled_bit_code, const std::string& isa,
size_t& co_offset, size_t& co_size);
bool addCodeObjData(amd_comgr_data_set_t& input, const std::vector<char>& source,
const std::string& name, const amd_comgr_data_kind_t type);
bool extractBuildLog(amd_comgr_data_set_t dataSet, std::string& buildLog);
+22 -2
Переглянути файл
@@ -545,7 +545,8 @@ amd_comgr_data_kind_t RTCLinkProgram::GetCOMGRDataKind(hiprtcJITInputType input_
data_kind = AMD_COMGR_DATA_KIND_BC;
break;
case HIPRTC_JIT_INPUT_LLVM_BUNDLED_BITCODE:
data_kind = AMD_COMGR_DATA_KIND_BC_BUNDLE;
data_kind =
HIPRTC_USE_RUNTIME_UNBUNDLER ? AMD_COMGR_DATA_KIND_BC : AMD_COMGR_DATA_KIND_BC_BUNDLE;
break;
case HIPRTC_JIT_INPUT_LLVM_ARCHIVES_OF_BUNDLED_BITCODE:
data_kind = AMD_COMGR_DATA_KIND_AR_BUNDLE;
@@ -560,13 +561,32 @@ amd_comgr_data_kind_t RTCLinkProgram::GetCOMGRDataKind(hiprtcJITInputType input_
bool RTCLinkProgram::AddLinkerDataImpl(std::vector<char>& link_data, hiprtcJITInputType input_type,
std::string& link_file_name) {
std::vector<char> llvm_bitcode;
// If this is bundled bitcode then unbundle this.
if (HIPRTC_USE_RUNTIME_UNBUNDLER && input_type == HIPRTC_JIT_INPUT_LLVM_BUNDLED_BITCODE) {
if (!findIsa()) {
return false;
}
size_t co_offset = 0;
size_t co_size = 0;
if (!UnbundleBitCode(link_data, isa_, co_offset, co_size)) {
LogError("Error in hiprtc: unable to unbundle the llvm bitcode");
return false;
}
llvm_bitcode.assign(link_data.begin() + co_offset, link_data.begin() + co_offset + co_size);
} else {
llvm_bitcode.assign(link_data.begin(), link_data.end());
}
amd_comgr_data_kind_t data_kind;
if ((data_kind = GetCOMGRDataKind(input_type)) == AMD_COMGR_DATA_KIND_UNDEF) {
LogError("Cannot find the correct COMGR data kind");
return false;
}
if (!addCodeObjData(link_input_, link_data, link_file_name, data_kind)) {
if (!addCodeObjData(link_input_, llvm_bitcode, link_file_name, data_kind)) {
LogError("Error in hiprtc: unable to add linked code object");
return false;
}