| 438 | } |
| 439 | |
| 440 | hipError_t FatBinaryInfo::ExtractFatBinaryUsingCOMGR(const std::vector<hip::Device*>& devices) { |
| 441 | if (fname_.empty() && image_ == nullptr) { |
| 442 | LogError("Both Filename and image cannot be null"); |
| 443 | return hipErrorInvalidValue; |
| 444 | } |
| 445 | |
| 446 | if (image_ != nullptr) { |
| 447 | if (!amd::Os::FindFileNameFromAddress(image_, &fname_, &foffset_)) { |
| 448 | fname_ = std::string(""); |
| 449 | foffset_ = 0; |
| 450 | } |
| 451 | } else { |
| 452 | ufd_ = PlatformState::instance().GetUniqueFileHandle(fname_.c_str()); |
| 453 | if (ufd_ == nullptr) { |
| 454 | return hipErrorFileNotFound; |
| 455 | } |
| 456 | |
| 457 | // If the file name exists but the file size is 0, the something wrong with the file or its path |
| 458 | if (ufd_->fsize_ == 0) { |
| 459 | return hipErrorInvalidImage; |
| 460 | } |
| 461 | |
| 462 | // If image_ is nullptr, then file path is passed via hipMod* APIs, so map the file. |
| 463 | if (!amd::Os::MemoryMapFileDesc(ufd_->fdesc_, ufd_->fsize_, foffset_, &image_)) { |
| 464 | LogError("Cannot map the file descriptor"); |
| 465 | PlatformState::instance().CloseUniqueFileHandle(ufd_); |
| 466 | return hipErrorInvalidValue; |
| 467 | } |
| 468 | |
| 469 | image_mapped_ = true; |
| 470 | } |
| 471 | guarantee(image_ != nullptr, "Image cannot be nullptr, file:%s did not map for some reason", |
| 472 | fname_.c_str()); |
| 473 | |
| 474 | bool is_compressed = IsCodeObjectCompressed(image_), |
| 475 | is_uncompressed = IsCodeObjectUncompressed(image_); |
| 476 | |
| 477 | // It better be elf if its neither compressed nor uncompressed |
| 478 | if (!is_compressed && !is_uncompressed) { |
| 479 | if (IsCodeObjectElf(image_)) { |
| 480 | // Load the binary directly |
| 481 | auto elf_size = amd::Elf::getElfSize(image_); |
| 482 | for (size_t i = 0; i < devices.size(); i++) { |
| 483 | if (hipSuccess != AddDevProgram(devices[i], image_, elf_size, 0)) |
| 484 | return hipErrorInvalidImage; |
| 485 | } |
| 486 | return hipSuccess; // We are done since it was already ELF |
| 487 | } else { |
| 488 | LogError("The code object has invalid header: compressed, uncompressed or elf"); |
| 489 | return hipErrorInvalidImage; |
| 490 | } |
| 491 | } |
| 492 | |
| 493 | // Create a list of all targets, which the current device can run |
| 494 | // For example, gfx1030 can run gfx1030, gfx10-geneeric, amdgcnspirv |
| 495 | std::set<std::string> unique_isa_names; |
| 496 | const std::string spirv_isa_name_empty{"spirv64-amd-amdhsa--amdgcnspirv"}; |
| 497 | const std::string spirv_isa_name{"spirv64-amd-amdhsa-unknown-amdgcnspirv"}; |
no test coverage detected