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

add xrt::elf raw elf data constructor #7963

Merged
merged 4 commits into from
Mar 13, 2024

Conversation

HimanshuChoudhary-Xilinx
Copy link
Collaborator

@HimanshuChoudhary-Xilinx HimanshuChoudhary-Xilinx commented Feb 22, 2024

Problem solved by the commit

Added new xrt::elf constructor to take in-memory buffer as input

Bug / issue (if any) fixed, which PR introduced the bug, how it was discovered

NA

How problem was solved, alternative solutions (if any) and why they were rejected

added new constructor to take memory elf buffer

Risks (if any) associated the changes in the commit

None

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

taken multiple efl and check we are able to get correct xrt::elf object

 // Sample usage
  aiebu::aiebu_assembler as(aiebu::aiebu_assembler::buffer_type::blob_instr_dpu, v1, v2, patch_data);
  auto e = as.get_elf();

  std::istringstream elf_stream;
  elf_stream.rdbuf()->pubsetbuf(e.data(), e.size());
  xrt::elf elf{elf_stream};
  xrt::module mod{elf};

Documentation impact (if any)

Yes, we have to update XRT doc

@gbuildx
Copy link
Collaborator

gbuildx commented Feb 22, 2024

HimanshuChoudhary-Xilinx - is not a collaborator
Can XRT admins please validate PR

@gbuildx
Copy link
Collaborator

gbuildx commented Feb 22, 2024

Can one of the admins verify this patch?

@gbuildx
Copy link
Collaborator

gbuildx commented Feb 22, 2024

HimanshuChoudhary-Xilinx - is not a collaborator
Can XRT admins please validate PR

@gbuildx
Copy link
Collaborator

gbuildx commented Feb 22, 2024

HimanshuChoudhary-Xilinx - is not a collaborator
Can XRT admins please validate PR

@sonals
Copy link
Member

sonals commented Feb 22, 2024

ok to test

@chvamshi-xilinx
Copy link
Collaborator

ok to test/retest is no longer working. We need to go to actions and run all jobs again. Started run just now

{
const std::string elf_string(data.begin(), data.end());
std::istringstream elf_stream(elf_string);
if (!m_elf.load(elf_stream))
Copy link
Member

Choose a reason for hiding this comment

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

We are copying the vector here. Can we write a simple adapter for std::vector to make it look like std::istream?

Copy link
Collaborator

Choose a reason for hiding this comment

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

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

elf_impl(const std::vector<char>& data)
{
std::istringstream elf_stream;
elf_stream.rdbuf()->pubsetbuf(const_cast<char*>(data.data()), data.size());
Copy link
Member

Choose a reason for hiding this comment

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

The const_cast looks evil here. Can you add a comment why we are doing it and the fact that elf_stream is input stream (read only) so it cannot accidentally change data.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

since data is const type so data.data() return const char*
https://cplusplus.com/reference/vector/vector/data/
If the vector object is const-qualified, the function returns a pointer to const value_type. Otherwise, it returns a pointer to value_type.
while
streambuf* pubsetbuf (char* s, streamsize n);
https://cplusplus.com/reference/streambuf/streambuf/pubsetbuf/

*
*/
XRT_API_EXPORT
elf(const std::vector<char>& data);
Copy link
Collaborator

Choose a reason for hiding this comment

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

A constructor from std::vector isn't great IMO. What if data is not held in a vector? A std::span would be better, but that's c++20. I would opt for const char*, size_t but you are still faced with the problem of how to create the istream without copying the in-memory buffer.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@stsoe
Updated the PR with changes discussed offline.

Signed-off-by: HimanshuChoudhary-Xilinx <[email protected]>
@larry9523 larry9523 merged commit d7e2096 into Xilinx:master Mar 13, 2024
21 of 33 checks passed
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.

7 participants