Skip to content

revise API to patch address directly #8272

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

Merged
merged 3 commits into from
Jul 8, 2024
Merged

revise API to patch address directly #8272

merged 3 commits into from
Jul 8, 2024

Conversation

maxzhen
Copy link
Collaborator

@maxzhen maxzhen commented Jul 3, 2024

Problem solved by the commit

Revise API introduced in PR#8226 for patching address directly. The original API requires module_sram, which, in turn, requires xrt::hwctx, which is not available for SHIM level test cases. Revising the API to only require module_elf, which is more friendly to SHIM test cases.

What has been tested and how, request additional testing if necessary

Run through a SHIM test case which uses this API and make sure the control buffer is patched properly.

maxzhen added 2 commits July 3, 2024 13:55
@maxzhen maxzhen requested review from larry9523 and dezhiAmd July 3, 2024 21:14
@maxzhen maxzhen requested a review from stsoe as a code owner July 3, 2024 21:14
@@ -1285,9 +1268,35 @@ patch(const xrt::module& module, const std::string& argnm, size_t index, const x
}

void
patch(const xrt::module& module, const std::string& argnm, size_t index, uint64_t address)
patch(const xrt::module& module, uint8_t *buf, size_t *sz, const std::vector< std::pair<std::string, uint64_t> > *args)
Copy link
Collaborator

@stsoe stsoe Jul 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
patch(const xrt::module& module, uint8_t *buf, size_t *sz, const std::vector< std::pair<std::string, uint64_t> > *args)
patch(const xrt::module& module, uint8_t* buf, size_t* sz, const std::vector<std::pair<std::string, uint64_t>>& args)

Please document this function. It's not obvious that with buf==nullptr, the function returns the size the caller should allocate for buf. What is args representing?

Commenting should be in header declaration of course.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The args here representing a list of arguments that needs to be patched to the control code buffer. I have added comments to make it clear that how caller can discover the size for buffer allocation. I still need to keep args as a pointer (v.s. a reference) since when caller tries to discover the real size, it does not pass in a real arg list (nullptr would do).

module.get_handle()->patch(argnm, index, address);
auto hdl = module.get_handle();
size_t orig_sz = *sz;
const struct buf *inst = nullptr;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const struct buf *inst = nullptr;
const buf* inst = nullptr;

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

throw std::runtime_error{"Control code buffer passed in is too small"}; // Need a bigger buffer.
std::memcpy(buf, inst->data(), *sz);

for (size_t index = 0; index < args->size(); index++) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use structured binding. Please pick descriptive names of what ever an element in args represents.

Suggested change
for (size_t index = 0; index < args->size(); index++) {
for (auto& [str, size] : args) {
...
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a loop counter and used more descriptive names in the binding.

@maxzhen maxzhen requested a review from stsoe July 3, 2024 22:46
@maxzhen maxzhen merged commit 205e0d3 into Xilinx:master Jul 8, 2024
17 checks passed
@maxzhen maxzhen deleted the elf branch July 9, 2024 03:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants