mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-05 09:09:04 +08:00
feat(ocloc concat): allow device binary
Allow for use of device binary in ocloc concat. Previously only AR files could be concatenated. This feature only works for zebin with AOT Product Config note. Signed-off-by: Krystian Chmielewski <krystian.chmielewski@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
d1b2311207
commit
7982e26ae7
@@ -248,4 +248,63 @@ ZebinCopyBufferSimdModule<numBits>::ZebinCopyBufferSimdModule(const NEO::Hardwar
|
||||
this->elfHeader = reinterpret_cast<NEO::Elf::ElfFileHeader<numBits> *>(storage.data());
|
||||
}
|
||||
|
||||
size_t writeElfNote(ArrayRef<uint8_t> dst, ArrayRef<const uint8_t> desc, NEO::ConstStringRef name, uint32_t type) {
|
||||
auto noteSize = sizeof(NEO::Elf::ElfNoteSection) + alignUp(desc.size(), 4U) + alignUp(name.size() + 1U, 4U);
|
||||
UNRECOVERABLE_IF(dst.size() < noteSize)
|
||||
|
||||
memset(dst.begin(), 0, noteSize);
|
||||
auto note = reinterpret_cast<NEO::Elf::ElfNoteSection *>(dst.begin());
|
||||
note->descSize = static_cast<uint32_t>(desc.size());
|
||||
note->nameSize = static_cast<uint32_t>(name.size() + 1U);
|
||||
note->type = type;
|
||||
auto noteName = ptrOffset(dst.begin(), sizeof(NEO::Elf::ElfNoteSection));
|
||||
std::memcpy(noteName, name.begin(), name.size());
|
||||
auto noteDesc = ptrOffset(noteName, note->nameSize);
|
||||
std::memcpy(noteDesc, desc.begin(), desc.size());
|
||||
return noteSize;
|
||||
}
|
||||
|
||||
size_t writeIntelGTNote(ArrayRef<uint8_t> dst, NEO::Elf::IntelGTSectionType sectionType, ArrayRef<const uint8_t> desc) {
|
||||
return writeElfNote(dst, desc, NEO::Elf::IntelGtNoteOwnerName, static_cast<uint32_t>(sectionType));
|
||||
}
|
||||
|
||||
size_t writeIntelGTVersionNote(ArrayRef<uint8_t> dst, NEO::ConstStringRef version) {
|
||||
std::vector<uint8_t> desc(version.length() + 1U, 0U);
|
||||
std::memcpy(desc.data(), version.begin(), version.length());
|
||||
return writeIntelGTNote(dst, NEO::Elf::ZebinVersion, {desc.data(), desc.size()});
|
||||
}
|
||||
|
||||
std::vector<uint8_t> createIntelGTNoteSection(NEO::ConstStringRef version, AOT::PRODUCT_CONFIG productConfig) {
|
||||
const size_t noteSectionSize = sizeof(NEO::Elf::ElfNoteSection) * 2 + 8U * 2 + alignUp(version.length() + 1, 4U) + sizeof(AOT::PRODUCT_CONFIG);
|
||||
std::vector<uint8_t> intelGTNotesSection(noteSectionSize, 0);
|
||||
size_t noteOffset = 0U;
|
||||
noteOffset += writeIntelGTVersionNote(ArrayRef<uint8_t>(ptrOffset(intelGTNotesSection.data(), noteOffset), intelGTNotesSection.size() - noteOffset), version);
|
||||
|
||||
writeIntelGTNote(ArrayRef<uint8_t>(ptrOffset(intelGTNotesSection.data(), noteOffset), intelGTNotesSection.size() - noteOffset),
|
||||
NEO::Elf::IntelGTSectionType::ProductConfig,
|
||||
ArrayRef<const uint8_t>::fromAny(&productConfig, 1U));
|
||||
return intelGTNotesSection;
|
||||
}
|
||||
|
||||
std::vector<uint8_t> createIntelGTNoteSection(PRODUCT_FAMILY productFamily, GFXCORE_FAMILY coreFamily, NEO::Elf::ZebinTargetFlags flags, NEO::ConstStringRef version) {
|
||||
const size_t noteSectionSize = sizeof(NEO::Elf::ElfNoteSection) * 4U + 4U * 8U + 3U * 4U + alignUp(version.length() + 1, 4U);
|
||||
std::vector<uint8_t> intelGTNotes(noteSectionSize, 0);
|
||||
size_t noteOffset = 0U;
|
||||
noteOffset += writeIntelGTNote(ArrayRef<uint8_t>(ptrOffset(intelGTNotes.data(), noteOffset), intelGTNotes.size() - noteOffset),
|
||||
NEO::Elf::ProductFamily,
|
||||
ArrayRef<const uint8_t>::fromAny(&productFamily, 1U));
|
||||
|
||||
noteOffset += writeIntelGTNote(ArrayRef<uint8_t>(ptrOffset(intelGTNotes.data(), noteOffset), intelGTNotes.size() - noteOffset),
|
||||
NEO::Elf::GfxCore,
|
||||
ArrayRef<const uint8_t>::fromAny(&coreFamily, 1U));
|
||||
|
||||
noteOffset += writeIntelGTNote(ArrayRef<uint8_t>(ptrOffset(intelGTNotes.data(), noteOffset), intelGTNotes.size() - noteOffset),
|
||||
NEO::Elf::TargetMetadata,
|
||||
ArrayRef<const uint8_t>::fromAny(&flags.packed, 1U));
|
||||
|
||||
writeIntelGTVersionNote(ArrayRef<uint8_t>(ptrOffset(intelGTNotes.data(), noteOffset), intelGTNotes.size() - noteOffset),
|
||||
version);
|
||||
return intelGTNotes;
|
||||
}
|
||||
|
||||
}; // namespace ZebinTestData
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2020-2022 Intel Corporation
|
||||
* Copyright (C) 2020-2023 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
@@ -263,44 +263,6 @@ kernels:
|
||||
-)===";
|
||||
};
|
||||
|
||||
inline std::vector<uint8_t> createIntelGTNoteSection(PRODUCT_FAMILY productFamily, GFXCORE_FAMILY coreFamily, NEO::Elf::ZebinTargetFlags flags, NEO::ConstStringRef version) {
|
||||
std::array<NEO::Elf::ElfNoteSection, 4> notes = {{{8, 4, NEO::Elf::IntelGTSectionType::ProductFamily},
|
||||
{8, 4, NEO::Elf::IntelGTSectionType::GfxCore},
|
||||
{8, 4, NEO::Elf::IntelGTSectionType::TargetMetadata},
|
||||
{8, static_cast<uint32_t>(alignUp(version.length(), 4U)), NEO::Elf::IntelGTSectionType::ZebinVersion}}};
|
||||
|
||||
std::array<std::vector<uint8_t>, 4> descData;
|
||||
descData[0].resize(4);
|
||||
std::memcpy(descData[0].data(), &productFamily, 4);
|
||||
|
||||
descData[1].resize(4);
|
||||
std::memcpy(descData[1].data(), &coreFamily, 4);
|
||||
|
||||
descData[2].resize(4);
|
||||
std::memcpy(descData[2].data(), &flags.packed, 4);
|
||||
|
||||
descData[3].resize(notes[3].descSize);
|
||||
std::memcpy(descData[3].data(), version.data(), notes[3].descSize);
|
||||
|
||||
size_t noteSectionSize = 0U;
|
||||
for (auto ¬e : notes) {
|
||||
noteSectionSize += sizeof(note) + note.descSize + note.nameSize;
|
||||
}
|
||||
|
||||
std::vector<uint8_t> intelGTNotesSection(noteSectionSize);
|
||||
auto intelGTNotes = intelGTNotesSection.data();
|
||||
for (size_t i = 0; i < 4U; i++) {
|
||||
auto ¬e = notes[i];
|
||||
std::memcpy(intelGTNotes, ¬e, sizeof(NEO::Elf::ElfNoteSection));
|
||||
intelGTNotes = ptrOffset(intelGTNotes, sizeof(NEO::Elf::ElfNoteSection));
|
||||
std::memcpy(intelGTNotes, NEO::Elf::IntelGtNoteOwnerName.data(), note.nameSize);
|
||||
intelGTNotes = ptrOffset(intelGTNotes, note.nameSize);
|
||||
std::memcpy(intelGTNotes, descData[i].data(), note.descSize);
|
||||
intelGTNotes = ptrOffset(intelGTNotes, note.descSize);
|
||||
}
|
||||
return intelGTNotesSection;
|
||||
}
|
||||
|
||||
template <NEO::Elf::ELF_IDENTIFIER_CLASS numBits>
|
||||
struct ZebinCopyBufferSimdModule {
|
||||
ZebinCopyBufferSimdModule(const NEO::HardwareInfo &hwInfo, uint8_t simdSize);
|
||||
@@ -372,4 +334,8 @@ kernels:
|
||||
)===";
|
||||
};
|
||||
|
||||
size_t writeElfNote(ArrayRef<uint8_t> dst, ArrayRef<const uint8_t> desc, NEO::ConstStringRef name, uint32_t type);
|
||||
size_t writeIntelGTNote(ArrayRef<uint8_t> dst, NEO::Elf::IntelGTSectionType sectionType, ArrayRef<const uint8_t> desc);
|
||||
std::vector<uint8_t> createIntelGTNoteSection(NEO::ConstStringRef version, AOT::PRODUCT_CONFIG productConfig);
|
||||
std::vector<uint8_t> createIntelGTNoteSection(PRODUCT_FAMILY productFamily, GFXCORE_FAMILY coreFamily, NEO::Elf::ZebinTargetFlags flags, NEO::ConstStringRef version);
|
||||
} // namespace ZebinTestData
|
||||
Reference in New Issue
Block a user