在随机地址之间快速复制

发布于 2025-02-03 05:11:42 字数 407 浏览 2 评论 0原文

我正在开发一个应用程序,该应用程序需要从一个地址执行大量复制数据字节到另一个地址。现在,在多线程中使用循环。数组的大小可以是从100k元素到2M元素。它起作用相对较快,但还不够。是否有更快的方法执行此任务?

std::vector<uchar*> src, dst
//Filling src and dst vectors with pointers. src.size() and dst.size() are equal.

for (int i=0; i<src.size();i++)
   *dst[i]=*src[i]

upd:这是一个像素为8位灰度的图像处理任务。诸如OPENCV之类的现成解决方案不合适,因为它甚至较慢(最多20次)。也许GPU解决方案是可能的?

I'm developing an application which needs to perform a massive copying data byte-by-byte from one addresses to another addresses. Now'm using for loop in multithread. Size of arrays can be from 100k elements to 2M elements. It works relatively fast, but not enough. Is there a faster way to perform this task?

std::vector<uchar*> src, dst
//Filling src and dst vectors with pointers. src.size() and dst.size() are equal.

for (int i=0; i<src.size();i++)
   *dst[i]=*src[i]

UPD: It's an image processing task where pixel is 8-bit grayscale. Ready-to-use solutions such as OpenCV isn't suitable because it's even slower (up to 20 times). Maybe GPU solution is possible?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

情徒 2025-02-10 05:11:42

我正在开发一个需要执行大规模复制数据字节的应用程序

这不太可能。

创建副本的唯一原因是数据正在以某种方式进行修改(不同的代码不能仅以“仅读”方式共享相同的数据);而且,如果数据正在以某种方式进行修改,那么您很可能可以将修改合并到复制中。

也许您正在对所有像素进行相同的更改,例如(例如)“从源读取16个像素,修改16像素,将16个像素写入目标”循环(在其中修改像素的工作中涉及的工作是并行发生的将下一个像素预先添加到缓存等中)。

也许您只是在修改一些像素,并且可以(例如)懒if(pointer_to_row [row] == null){pointer_to_row [row [row] = create_copy_of_row(row); } modify_row(pointer_to_rows [row]);避免复制您不修改的所有像素行。也许您可以创建数据的共享内存映射,并让操作系统的“写入”虚拟内存管理为您负责复制。

也许您可以拥有某种更改的杂志并独自留下原始数据(您可能拥有int get_pixel(int x,int y){int temp = check_journal(x,y);如果(temp!= temp!=) not_present)返回temp; else return get_original_pixel_data(x,y);}

。创建从旧行和日记的新行,然后将日记重置为空”)。

I'm developing an application which needs to perform a massive copying data byte-by-byte

That's very unlikely.

The only reason to create a copy is that the data is being modified in some way (and different pieces of code can't just share the same data in a "read only" way); and if the data is being modified in some way then it's very likely that you can merge the modification into the copying.

Maybe you're doing the same changes to all pixels, and it can be (e.g.) a "read 16 pixels from source, modify 16 pixels, write 16 pixels to destination" loop (where the work involved in modifying the pixels happens in parallel with pre-fetching the next pixels into cache, etc).

Maybe you're only modifying some pixels, and can do (e.g.) a lazy if( pointer_to_row[row] == NULL) { pointer_to_row[row] = create_copy_of_row(row); } modify_row(pointer_to_rows[row]); to avoid copying all the rows of pixels you don't modify. Maybe you can create a shared memory mapping of the data and let the operating system's "copy on write" virtual memory management take care of the copying for you.

Maybe you can have some kind of journal of changes and leave the original data alone (where you might have an int get_pixel(int x, int y ) { int temp = check_journal(x, y); if(temp != NOT_PRESENT) return temp; else return get_original_pixel_data(x, y); }.

Maybe you can combine multiple techniques (e.g. a small journal for each row of pixels, with a lazy "if/when journal for row becomes full, create new row from old row and journal, and reset the journal to empty").

辞取 2025-02-10 05:11:42

我使用GLSL在GPU上移动了整个项目。阵列替换为2D采样器。即使是低端英特尔UHD也可以在高帧率下处理高分辨率。

I moved entire project on GPU, using GLSL. Arrays are replaced with 2D samplers. Even low-end Intel UHD can handle high resolutions at high framerate.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文