P4 to Git Change 1610640 by gandryey@gera-w8 on 2018/09/25 17:34:09
SWDEV-79445 - OCL generic changes and code clean-up Program compilation clean-up. Step#4: - Add common method FindGlobalVarSize() and metadata setup to the abstraction layer Affected files ... ... //depot/stg/opencl/drivers/opencl/runtime/device/devprogram.cpp#6 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/devprogram.hpp#4 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palprogram.cpp#76 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palprogram.hpp#32 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rocprogram.cpp#89 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rocprogram.hpp#38 edit
Этот коммит содержится в:
@@ -503,11 +503,6 @@ LightningProgram::LightningProgram(roc::NullDevice& device)
|
||||
isLC_ = true;
|
||||
xnackEnabled_ = dev().deviceInfo().xnackEnabled_;
|
||||
machineTarget_ = dev().deviceInfo().machineTarget_;
|
||||
metadata_ = nullptr;
|
||||
}
|
||||
|
||||
LightningProgram::~LightningProgram() {
|
||||
delete metadata_;
|
||||
}
|
||||
|
||||
bool LightningProgram::createBinary(amd::option::Options* options) {
|
||||
@@ -849,89 +844,11 @@ bool LightningProgram::linkImpl(amd::option::Options* options) {
|
||||
}
|
||||
|
||||
bool LightningProgram::setKernels(amd::option::Options* options, void* binary, size_t binSize) {
|
||||
size_t progvarsTotalSize = 0;
|
||||
size_t dynamicSize = 0;
|
||||
size_t progvarsWriteSize = 0;
|
||||
|
||||
// Begin the Elf image from memory
|
||||
Elf* e = elf_memory((char*)binary, binSize, nullptr);
|
||||
if (elf_kind(e) != ELF_K_ELF) {
|
||||
buildLog_ += "Error while reading the ELF program binary\n";
|
||||
// Find the size of global variables from the binary
|
||||
if (!FindGlobalVarSize(binary, binSize)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
size_t numpHdrs;
|
||||
if (elf_getphdrnum(e, &numpHdrs) != 0) {
|
||||
buildLog_ += "Error while reading the ELF program binary\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < numpHdrs; ++i) {
|
||||
GElf_Phdr pHdr;
|
||||
if (gelf_getphdr(e, i, &pHdr) != &pHdr) {
|
||||
continue;
|
||||
}
|
||||
// Look for the runtime metadata note
|
||||
if (pHdr.p_type == PT_NOTE && pHdr.p_align >= sizeof(int)) {
|
||||
// Iterate over the notes in this segment
|
||||
address ptr = (address)binary + pHdr.p_offset;
|
||||
address segmentEnd = ptr + pHdr.p_filesz;
|
||||
|
||||
while (ptr < segmentEnd) {
|
||||
Elf_Note* note = (Elf_Note*)ptr;
|
||||
address name = (address)¬e[1];
|
||||
address desc = name + amd::alignUp(note->n_namesz, sizeof(int));
|
||||
|
||||
if (note->n_type == 7 || note->n_type == 8) {
|
||||
buildLog_ +=
|
||||
"Error: object code with old metadata is not "
|
||||
"supported\n";
|
||||
return false;
|
||||
} else if (note->n_type == 10 /* NT_AMD_AMDGPU_HSA_METADATA */ &&
|
||||
note->n_namesz == sizeof "AMD" &&
|
||||
!memcmp(name, "AMD", note->n_namesz)) {
|
||||
std::string metadataStr((const char*)desc, (size_t)note->n_descsz);
|
||||
metadata_ = new CodeObjectMD();
|
||||
if (llvm::AMDGPU::HSAMD::fromString(metadataStr, *metadata_)) {
|
||||
buildLog_ += "Error: failed to process metadata\n";
|
||||
return false;
|
||||
}
|
||||
// We've found and loaded the runtime metadata, exit the
|
||||
// note record loop now.
|
||||
break;
|
||||
}
|
||||
ptr += sizeof(*note) + amd::alignUp(note->n_namesz, sizeof(int)) +
|
||||
amd::alignUp(note->n_descsz, sizeof(int));
|
||||
}
|
||||
}
|
||||
// Accumulate the size of R & !X loadable segments
|
||||
else if (pHdr.p_type == PT_LOAD && !(pHdr.p_flags & PF_X)) {
|
||||
if (pHdr.p_flags & PF_R) {
|
||||
progvarsTotalSize += pHdr.p_memsz;
|
||||
}
|
||||
if (pHdr.p_flags & PF_W) {
|
||||
progvarsWriteSize += pHdr.p_memsz;
|
||||
}
|
||||
} else if (pHdr.p_type == PT_DYNAMIC) {
|
||||
dynamicSize += pHdr.p_memsz;
|
||||
}
|
||||
}
|
||||
|
||||
elf_end(e);
|
||||
|
||||
if (!metadata_) {
|
||||
buildLog_ +=
|
||||
"Error: runtime metadata section not present in "
|
||||
"ELF program binary\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (progvarsWriteSize != dynamicSize) {
|
||||
hasGlobalStores_ = true;
|
||||
}
|
||||
progvarsTotalSize -= dynamicSize;
|
||||
setGlobalVariableTotalSize(progvarsTotalSize);
|
||||
|
||||
saveBinaryAndSetType(TYPE_EXECUTABLE, binary, binSize);
|
||||
|
||||
//Load the stored copy of the ELF binary.
|
||||
|
||||
Ссылка в новой задаче
Block a user