Skip to content

Commit

Permalink
Remove extra memory copy
Browse files Browse the repository at this point in the history
  • Loading branch information
matinlotfali committed Jul 4, 2024
1 parent e6584b3 commit f45abfd
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 20 deletions.
4 changes: 3 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 3 additions & 16 deletions gst-plugin/src/drpai-models/drpai_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,29 +203,16 @@ void DRPAI_Base::get_result()
static_cast<uint32_t>(drpai_address.data_out_addr),
static_cast<uint32_t>(drpai_address.data_out_size)
};
float drpai_buf[BUF_SIZE];

errno = 0;
/* Assign the memory address and size to be read */
if ( ioctl(drpai_fd, DRPAI_ASSIGN, &drpai_data) == -1 )
throw std::runtime_error("[ERROR] Failed to run DRPAI_ASSIGN: errno=" + std::to_string(errno) + " " + std::string(std::strerror(errno)));

/* Read the memory via DRP-AI Driver and store the output to buffer */
for (uint32_t i = 0; i < (drpai_data.size / BUF_SIZE); i++)
{
errno = 0;
if ( read(drpai_fd, drpai_buf, BUF_SIZE) == -1 )
throw std::runtime_error("[ERROR] Failed to read via DRP-AI Driver: errno=" + std::to_string(errno) + " " + std::string(std::strerror(errno)));
std::memcpy(&drpai_output_buf[BUF_SIZE/sizeof(float)*i], drpai_buf, BUF_SIZE);
}

if ( 0 != (drpai_data.size % BUF_SIZE))
{
errno = 0;
if ( read(drpai_fd, drpai_buf, (drpai_data.size % BUF_SIZE)) == -1 )
throw std::runtime_error("[ERROR] Failed to read via DRP-AI Driver: errno=" + std::to_string(errno) + " " + std::string(std::strerror(errno)));
std::memcpy(&drpai_output_buf[(drpai_data.size - (drpai_data.size%BUF_SIZE))/sizeof(float)], drpai_buf, (drpai_data.size % BUF_SIZE));
}
drpai_output_buf.reserve(drpai_data.size / sizeof(float));
if ( read(drpai_fd, drpai_output_buf.data(), drpai_data.size) == -1 )
throw std::runtime_error("[ERROR] Failed to read via DRP-AI Driver: errno=" + std::to_string(errno) + " " + std::string(std::strerror(errno)));
}

void DRPAI_Base::start() {
Expand Down
4 changes: 2 additions & 2 deletions gst-plugin/src/gstdrpai.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,10 @@ gst_drpai_sink_event(GstPad *pad, GstObject *parent,
switch (GST_EVENT_TYPE (event)) {
case GST_EVENT_CAPS: {
GstCaps *caps;

gst_event_parse_caps(event, &caps);

/* do something with the caps */
GST_DEBUG("\tCaps: %s\n", gst_caps_to_string(caps));

/* and forward */
ret = gst_pad_event_default(pad, parent, event);
Expand Down Expand Up @@ -202,7 +203,6 @@ gst_drpai_chain(GstPad *pad, GstObject *parent, GstBuffer *buf) {

gst_buffer_unmap(buf, &info);

/* just push out the incoming buffer without touching it */
return gst_pad_push(obj->srcpad, buf);
}

Expand Down
2 changes: 1 addition & 1 deletion meson-aarch64-poky.cross
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ needs_exe_wrapper = true
[built-in options]
c_args = ['-O2', '-pipe', '-g', '-feliminate-unused-debug-types']
c_link_args = ['-Wl,-O1', '-Wl,--hash-style=gnu', '-Wl,--as-needed', '-fstack-protector-strong', '-Wl,-z,relro,-z,now']
cpp_args = []
cpp_args = ['-O2', '-pipe', '-g', '-feliminate-unused-debug-types']
cpp_link_args = ['-Wl,-O1', '-Wl,--hash-style=gnu', '-Wl,--as-needed', '-fstack-protector-strong', '-Wl,-z,relro,-z,now']

[host_machine]
Expand Down

0 comments on commit f45abfd

Please sign in to comment.