MCPcopy Create free account
hub / github.com/ROCm/clr / ExtractFatBinaryUsingCOMGR

Method ExtractFatBinaryUsingCOMGR

hipamd/src/hip_fatbin.cpp:440–696  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

438}
439
440hipError_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"};

Callers 3

BuildItMethod · 0.80
loadCodeObjectMethod · 0.80
digestFatBinaryMethod · 0.80

Calls 15

IsCodeObjectCompressedFunction · 0.85
IsCodeObjectUncompressedFunction · 0.85
IsCodeObjectElfFunction · 0.85
TargetToGenericFunction · 0.85
PopulateCodeObjectMapFunction · 0.85
emptyMethod · 0.80
GetUniqueFileHandleMethod · 0.80
CloseUniqueFileHandleMethod · 0.80
isaNameMethod · 0.80
targetIdMethod · 0.80
stringFunction · 0.50

Tested by

no test coverage detected