Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug in patching args in multiple runs #8660

Merged
merged 2 commits into from
Dec 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions src/runtime_src/core/common/api/xrt_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ static constexpr size_t column_page_size = AIE_COLUMN_PAGE_SIZE;
static constexpr uint8_t Elf_Amd_Aie2p = 69;
static constexpr uint8_t Elf_Amd_Aie2ps = 64;

// In aie2p max bd data words is 8 and in aie4/aie2ps its 9
// using max bd words as 9 to cover all cases
static constexpr size_t max_bd_words = 9;

static const char* Scratch_Pad_Mem_Symbol = "scratch-pad-mem";
static const char* Control_Packet_Symbol = "control-packet";
static const char* Control_Code_Symbol = "control-code";
Expand Down Expand Up @@ -141,6 +145,8 @@ struct patcher
uint64_t offset_to_patch_buffer;
uint32_t offset_to_base_bo_addr;
uint32_t mask; // This field is valid only when patching scheme is scalar_32bit_kind
bool dirty = false; // Tells whether this entry is already patched or not
uint32_t bd_data_ptrs[max_bd_words]; // array to store bd ptrs original values
};

std::vector<patch_info> m_ctrlcode_patchinfo;
Expand All @@ -166,9 +172,10 @@ struct patcher
, m_ctrlcode_patchinfo(std::move(ctrlcode_offset))
{}

// Replace certain bits of *data_to_patch with register_value. Which bits to be replaced is specified by mask
// For *data_to_patch be 0xbb11aaaa and mask be 0x00ff0000
// To make *data_to_patch be 0xbb55aaaa, register_value must be 0x00550000
// Replace certain bits of *data_to_patch with register_value. Which bits to be replaced is specified by mask
// For *data_to_patch be 0xbb11aaaa and mask be 0x00ff0000
// To make *data_to_patch be 0xbb55aaaa, register_value must be 0x00550000

void
patch32(uint32_t* data_to_patch, uint64_t register_value, uint32_t mask) const
{
Expand Down Expand Up @@ -253,8 +260,18 @@ struct patcher
void
patch_it(uint8_t* base, uint64_t new_value)
{
for (auto item : m_ctrlcode_patchinfo) {
for (auto& item : m_ctrlcode_patchinfo) {
auto bd_data_ptr = reinterpret_cast<uint32_t*>(base + item.offset_to_patch_buffer);
if (!item.dirty) {
// first time patching cache bd ptr values using bd ptrs array in patch info
std::copy(bd_data_ptr, bd_data_ptr + max_bd_words, item.bd_data_ptrs);
item.dirty = true;
}
else {
// not the first time patching, restore bd ptr values from patch info bd ptrs array
std::copy(item.bd_data_ptrs, item.bd_data_ptrs + max_bd_words, bd_data_ptr);
}

switch (m_symbol_type) {
case symbol_type::scalar_32bit_kind:
// new_value is a register value
Expand Down
Loading