| 244 | } |
| 245 | |
| 246 | static bool UncompressAndPopulateCodeObject( |
| 247 | const void* image, const std::set<std::string>& unique_isa_names, |
| 248 | std::map<std::string, std::pair<const void*, size_t>>& code_obj_map) { |
| 249 | auto remove_file_extension = [](const std::string& input) -> std::string { |
| 250 | size_t index = input.find_last_of("."); |
| 251 | std::string ret = input.substr(0, index); |
| 252 | return ret; |
| 253 | }; |
| 254 | |
| 255 | std::vector<std::string> bundle_ids_str; |
| 256 | std::set<std::string> unique_ids; |
| 257 | |
| 258 | for (const auto& isa_name : unique_isa_names) { |
| 259 | bundle_ids_str.push_back(std::string(symbols::kOffloadKindHipv4_) + isa_name); |
| 260 | } |
| 261 | |
| 262 | std::vector<const char*> bundle_ids; |
| 263 | bundle_ids.reserve(bundle_ids_str.size()); |
| 264 | for (auto& bundle_id_str : bundle_ids_str) { |
| 265 | bundle_ids.push_back(bundle_id_str.c_str()); |
| 266 | } |
| 267 | |
| 268 | const auto obheader = reinterpret_cast<const symbols::ClangOffloadBundleCompressedHeader*>(image); |
| 269 | const size_t size = obheader->totalSize; |
| 270 | |
| 271 | bool passed = false; |
| 272 | do { |
| 273 | comgr_helper::ComgrDataSetUniqueHandle bundled_co, unbundled_co; |
| 274 | comgr_helper::ComgrDataUniqueHandle input_bundle; |
| 275 | if (auto comgr_status = bundled_co.Create(); comgr_status != AMD_COMGR_STATUS_SUCCESS) { |
| 276 | LogError("Error in creating bundled_co"); |
| 277 | break; |
| 278 | } |
| 279 | |
| 280 | if (auto comgr_status = unbundled_co.Create(); comgr_status != AMD_COMGR_STATUS_SUCCESS) { |
| 281 | LogError("Error in creating unbundled_co"); |
| 282 | break; |
| 283 | } |
| 284 | |
| 285 | if (auto comgr_status = input_bundle.Create(AMD_COMGR_DATA_KIND_OBJ_BUNDLE); |
| 286 | comgr_status != AMD_COMGR_STATUS_SUCCESS) { |
| 287 | LogError("Error in creating input bundle"); |
| 288 | break; |
| 289 | } |
| 290 | |
| 291 | if (auto comgr_status = |
| 292 | amd::Comgr::set_data(input_bundle.get(), size, static_cast<const char*>(image)); |
| 293 | comgr_status != AMD_COMGR_STATUS_SUCCESS) { |
| 294 | LogError("Error in setting image data to bundle"); |
| 295 | break; |
| 296 | } |
| 297 | |
| 298 | if (auto comgr_status = amd::Comgr::set_data_name(input_bundle.get(), symbols::kHipFatBinName); |
| 299 | comgr_status != AMD_COMGR_STATUS_SUCCESS) { |
| 300 | LogError("Error in setting image data to bundle"); |
| 301 | break; |
| 302 | } |
| 303 | |