Skip to content

rga在使用dma内存的情况下,improcess耗时过高,影响NPU推理效率,单线程场景下单帧耗时大约2ms,多线程场景下单帧耗时最高能到13ms。 #149

@sztukai

Description

@sztukai

源图: w1920 h1080 hor_stride0 ver_stride0 rgb888 size=w * h * bpp(format)
目标图: w960 h544 hor_stride0 ver_stride0 rgb888 size=w * h * bpp(format)

auto rga_start = std::chrono::high_resolution_clock::now();
image_buffer_t src = m_MppDecoder.GetDstImg();
int release_fence_fd = -1, ret;
ret = improcess(src.rga_buf, m_input_img, {}, {}, dst_rect, {}, {}, &release_fence_fd, NULL, IM_ASYNC);
if (ret != IM_STATUS_SUCCESS || release_fence_fd < 0) {
    printf("[RGA ERROR] improcess failed!!!\n");
    printf("  -> error code: %d\n", ret);
    printf("  -> error msg : %s\n", imStrError(ret));  // 关键:打印文字错误原因
    printf("  -> dst_rect  : x=%d, y=%d, w=%d, h=%d\n", dst_rect.x, dst_rect.y, dst_rect.width, dst_rect.height);
    printf("  -> src width : %u, height: %u\n", src.rga_buf.width, src.rga_buf.height);
    printf("  -> dst width : %u, height: %u\n", m_input_img.width, m_input_img.height);
    printf("  -> async mode: %s\n", (IM_ASYNC == 1) ? "ASYNC" : "SYNC");
    sleep(30);
    return;
}
//std::this_thread::sleep_for(std::chrono::milliseconds(1));
ret = imsync(release_fence_fd);
if (ret != IM_STATUS_SUCCESS) {
    printf("improcess waiting failed, %s\n", imStrError((IM_STATUS)ret));
    return;
}
auto rga_end = std::chrono::high_resolution_clock::now();
std::chrono::duration<double, std::milli> rga_cost = rga_end - rga_start;
printf("[RGA] 图像处理耗时: %.2f ms\n", rga_cost.count());

typedef struct {
int width;
int height;
int wstride;
int hstride;

  int format;
  rga_buffer_handle_t rga_handle; 
  rga_buffer_t rga_buf; 

  unsigned char* buf;
  int fd;
  int size;

} image_buffer_t;

image_buffer_t& GetDstImg()
{
return m_vecDst_img[frame_index%FRAME_BUFFER_COUNT];
}

static bool Init_image_buffer_t(image_buffer_t& DecodeFrame)
{
int ret = dma_buf_alloc(DMA_HEAP_DMA32_UNCACHED_PATH, DecodeFrame.size, &DecodeFrame.fd, (void **)&DecodeFrame.buf);
if (ret < 0)
{
std::cout << "Init_image_buffer_t, dma_buf_alloc failed" << std::endl;
return false;
}
DecodeFrame.rga_handle = importbuffer_fd(DecodeFrame.fd, DecodeFrame.size);
if (DecodeFrame.rga_handle == 0)
{
std::cout << "Init_image_buffer_t, importbuffer_fd failed" << std::endl;
return false;
}
DecodeFrame.rga_buf = wrapbuffer_handle(DecodeFrame.rga_handle, DecodeFrame.width, DecodeFrame.height, DecodeFrame.format, DecodeFrame.wstride, DecodeFrame.hstride);

return true;

}

单线程下耗时日志:
[RGA] 图像处理耗时: 2.02 ms
[RGA] 图像处理耗时: 2.02 ms
[RGA] 图像处理耗时: 2.02 ms
[RGA] 图像处理耗时: 2.01 ms
[RGA] 图像处理耗时: 2.03 ms
[RGA] 图像处理耗时: 2.04 ms
[RGA] 图像处理耗时: 2.03 ms
[RGA] 图像处理耗时: 2.02 ms
[RGA] 图像处理耗时: 2.05 ms
[RGA] 图像处理耗时: 2.05 ms
[RGA] 图像处理耗时: 2.02 ms
[RGA] 图像处理耗时: 2.02 ms
[RGA] 图像处理耗时: 2.02 ms
[RGA] 图像处理耗时: 2.02 ms
[RGA] 图像处理耗时: 2.02 ms
[RGA] 图像处理耗时: 2.01 ms
[RGA] 图像处理耗时: 2.01 ms
[RGA] 图像处理耗时: 2.08 ms
[RGA] 图像处理耗时: 2.07 ms
[RGA] 图像处理耗时: 2.03 ms

6线程下耗时日志:
[RGA] 图像处理耗时: 2.38 ms
[RGA] 图像处理耗时: 2.41 ms
[RGA] 图像处理耗时: 2.26 ms
[RGA] 图像处理耗时: 2.46 ms
[RGA] 图像处理耗时: 2.46 ms
[RGA] 图像处理耗时: 2.75 ms
[RGA] 图像处理耗时: 2.15 ms
[RGA] 图像处理耗时: 2.14 ms
[RGA] 图像处理耗时: 2.56 ms
[RGA] 图像处理耗时: 1.64 ms
[RGA] 图像处理耗时: 2.70 ms
[RGA] 图像处理耗时: 2.20 ms
[RGA] 图像处理耗时: 2.52 ms
[RGA] 图像处理耗时: 2.73 ms
[RGA] 图像处理耗时: 2.48 ms
[RGA] 图像处理耗时: 2.12 ms
[RGA] 图像处理耗时: 4.45 ms
[RGA] 图像处理耗时: 2.21 ms
[RGA] 图像处理耗时: 2.32 ms
[RGA] 图像处理耗时: 4.39 ms
[RGA] 图像处理耗时: 2.25 ms
[RGA] 图像处理耗时: 2.39 ms
[RGA] 图像处理耗时: 4.72 ms
[RGA] 图像处理耗时: 2.38 ms
[RGA] 图像处理耗时: 2.60 ms
[RGA] 图像处理耗时: 2.77 ms
[RGA] 图像处理耗时: 2.68 ms
[RGA] 图像处理耗时: 2.31 ms
[RGA] 图像处理耗时: 2.23 ms
[RGA] 图像处理耗时: 2.27 ms
[RGA] 图像处理耗时: 2.94 ms
[RGA] 图像处理耗时: 2.25 ms
[RGA] 图像处理耗时: 2.20 ms
[RGA] 图像处理耗时: 2.61 ms
[RGA] 图像处理耗时: 2.39 ms
[RGA] 图像处理耗时: 1.68 ms
[RGA] 图像处理耗时: 2.21 ms
[RGA] 图像处理耗时: 2.32 ms
[RGA] 图像处理耗时: 2.46 ms
[RGA] 图像处理耗时: 1.68 ms
[RGA] 图像处理耗时: 2.23 ms
[RGA] 图像处理耗时: 3.22 ms
[RGA] 图像处理耗时: 2.20 ms
[RGA] 图像处理耗时: 2.18 ms
[RGA] 图像处理耗时: 2.65 ms
[RGA] 图像处理耗时: 2.54 ms
[RGA] 图像处理耗时: 2.19 ms
[RGA] 图像处理耗时: 4.64 ms
[RGA] 图像处理耗时: 2.59 ms
[RGA] 图像处理耗时: 5.21 ms
[RGA] 图像处理耗时: 2.27 ms
[RGA] 图像处理耗时: 1.61 ms
[RGA] 图像处理耗时: 3.32 ms
[RGA] 图像处理耗时: 4.41 ms
[RGA] 图像处理耗时: 2.48 ms
[RGA] 图像处理耗时: 1.69 ms
[RGA] 图像处理耗时: 1.71 ms
[RGA] 图像处理耗时: 2.31 ms
[RGA] 图像处理耗时: 2.08 ms
[RGA] 图像处理耗时: 3.89 ms
[RGA] 图像处理耗时: 2.46 ms
[RGA] 图像处理耗时: 1.70 ms
[RGA] 图像处理耗时: 2.22 ms
[RGA] 图像处理耗时: 4.29 ms
[RGA] 图像处理耗时: 2.24 ms
[RGA] 图像处理耗时: 4.23 ms
[RGA] 图像处理耗时: 2.27 ms
[RGA] 图像处理耗时: 2.29 ms
[RGA] 图像处理耗时: 2.26 ms
[RGA] 图像处理耗时: 2.42 ms
[RGA] 图像处理耗时: 2.27 ms
[RGA] 图像处理耗时: 2.27 ms
[RGA] 图像处理耗时: 2.35 ms
[RGA] 图像处理耗时: 2.38 ms
[RGA] 图像处理耗时: 2.51 ms
[RGA] 图像处理耗时: 2.56 ms
[RGA] 图像处理耗时: 2.30 ms
[RGA] 图像处理耗时: 3.76 ms
[RGA] 图像处理耗时: 2.20 ms
[RGA] 图像处理耗时: 2.22 ms
[RGA] 图像处理耗时: 2.35 ms
[RGA] 图像处理耗时: 2.42 ms
[RGA] 图像处理耗时: 2.26 ms
[RGA] 图像处理耗时: 2.74 ms
[RGA] 图像处理耗时: 2.32 ms
[RGA] 图像处理耗时: 2.29 ms
[RGA] 图像处理耗时: 2.61 ms
[RGA] 图像处理耗时: 2.48 ms

12线程下耗时日志:
[RGA] 图像处理耗时: 3.00 ms
[RGA] 图像处理耗时: 2.74 ms
[RGA] 图像处理耗时: 2.34 ms
[RGA] 图像处理耗时: 1.67 ms
[RGA] 图像处理耗时: 3.93 ms
[RGA] 图像处理耗时: 2.66 ms
[RGA] 图像处理耗时: 1.82 ms
[RGA] 图像处理耗时: 2.59 ms
[RGA] 图像处理耗时: 2.59 ms
[RGA] 图像处理耗时: 4.41 ms
[RGA] 图像处理耗时: 3.82 ms
[RGA] 图像处理耗时: 3.14 ms
[RGA] 图像处理耗时: 2.10 ms
[RGA] 图像处理耗时: 2.57 ms
[RGA] 图像处理耗时: 2.66 ms
[RGA] 图像处理耗时: 1.89 ms
[RGA] 图像处理耗时: 4.88 ms
[RGA] 图像处理耗时: 1.84 ms
[RGA] 图像处理耗时: 2.26 ms
[RGA] 图像处理耗时: 2.82 ms
[RGA] 图像处理耗时: 1.77 ms
[RGA] 图像处理耗时: 2.69 ms
[RGA] 图像处理耗时: 3.13 ms
[RGA] 图像处理耗时: 2.36 ms
[RGA] 图像处理耗时: 2.68 ms
[RGA] 图像处理耗时: 2.99 ms
[RGA] 图像处理耗时: 2.99 ms
[RGA] 图像处理耗时: 5.05 ms
[RGA] 图像处理耗时: 5.71 ms
[RGA] 图像处理耗时: 2.58 ms
[RGA] 图像处理耗时: 2.51 ms
[RGA] 图像处理耗时: 2.76 ms
[RGA] 图像处理耗时: 1.74 ms
[RGA] 图像处理耗时: 5.15 ms
[RGA] 图像处理耗时: 2.42 ms
[RGA] 图像处理耗时: 3.12 ms
[RGA] 图像处理耗时: 2.25 ms
[RGA] 图像处理耗时: 2.42 ms
[RGA] 图像处理耗时: 2.68 ms
[RGA] 图像处理耗时: 2.11 ms
[RGA] 图像处理耗时: 2.66 ms
[RGA] 图像处理耗时: 2.78 ms
[RGA] 图像处理耗时: 3.52 ms
[RGA] 图像处理耗时: 2.82 ms
[RGA] 图像处理耗时: 2.30 ms
[RGA] 图像处理耗时: 2.40 ms
[RGA] 图像处理耗时: 2.69 ms
[RGA] 图像处理耗时: 2.67 ms
[RGA] 图像处理耗时: 1.83 ms
[RGA] 图像处理耗时: 2.46 ms
[RGA] 图像处理耗时: 2.47 ms
[RGA] 图像处理耗时: 2.58 ms
[RGA] 图像处理耗时: 2.89 ms
[RGA] 图像处理耗时: 3.06 ms
[RGA] 图像处理耗时: 2.15 ms
[RGA] 图像处理耗时: 2.32 ms
[RGA] 图像处理耗时: 2.51 ms
[RGA] 图像处理耗时: 3.11 ms
[RGA] 图像处理耗时: 2.96 ms
[RGA] 图像处理耗时: 3.23 ms
[RGA] 图像处理耗时: 2.64 ms
[RGA] 图像处理耗时: 2.34 ms
[RGA] 图像处理耗时: 1.68 ms

rga占用:
root@poodle:/userdata# cat /sys/kernel/debug/rkrga/load
num of scheduler = 3
================= load ==================
scheduler[0]: rga3_core0
load = 45%

scheduler[1]: rga3_core1
load = 24%

scheduler[2]: rga2
load = 7%

     process 182: pid = 185826, name: ./rkdmademo /data/solder.mp4 /home/nvidia/algo/models/monitor_yolov8.rknn2 12

root@poodle:/userdata# cat /sys/kernel/debug/rkrga/load
num of scheduler = 3
================= load ==================
scheduler[0]: rga3_core0
load = 45%

scheduler[1]: rga3_core1
load = 23%

scheduler[2]: rga2
load = 9%

     process 182: pid = 185826, name: ./rkdmademo /data/solder.mp4 /home/nvidia/algo/models/monitor_yolov8.rknn2 12

root@poodle:/userdata# cat /sys/kernel/debug/rkrga/load
num of scheduler = 3
================= load ==================
scheduler[0]: rga3_core0
load = 45%

scheduler[1]: rga3_core1
load = 22%

scheduler[2]: rga2
load = 7%

     process 182: pid = 185826, name: ./rkdmademo /data/solder.mp4 /home/nvidia/algo/models/monitor_yolov8.rknn2 12

root@poodle:/userdata#

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions