OpenCL,我是否需要使用事件在同一命令队列中同步内核启动?(OpenCL, do I need to use events to synchronize kernel launches insid

编程入门 行业动态 更新时间:2024-10-23 08:37:49
OpenCL,我是否需要使用事件在同一命令队列中同步内核启动?(OpenCL, do I need to use events to synchronize kernel launches inside the same command queue?)

我不确定这是否有必要。 我有两个内核需要以串口方式启动。 我是否需要为第一个事件创建一个事件,然后让第二个内核启动等待该事件,或者我可以假设所有事务都是按照我放置它的顺序执行的队列吗? 我在代码中使用cl_event是否正确?

cl_event acceleration_finished; cl_check(clEnqueueNDRangeKernel(cmdq, acceleration_kernel, 1, NULL, &acceleration_blocks, &acceleration_threads, 0, NULL, &acceleration_finished)); cl_event stepper_finished; cl_check(clEnqueueNDRangeKernel(cmdq, stepper_kernel, 1, NULL, &N, NULL, 1, &acceleration_finished, &stepper_finished)); cl_double3* positions_mapped = clEnqueueMapBuffer(cmdq, positions, CL_TRUE, CL_MAP_READ, 0, sizeof(cl_double3) * N, 1, &stepper_finished, NULL, &error); cl_check(error);

I am unsure if this is necessary. I have two kernels which I need to launch in serial. Do I need to create an event for the first one and then have the second kernel launch wait for that event or can I assume that everything is the queue executes in the order in which I placed it? Is my use of cl_event in the code bellow nessary?

cl_event acceleration_finished; cl_check(clEnqueueNDRangeKernel(cmdq, acceleration_kernel, 1, NULL, &acceleration_blocks, &acceleration_threads, 0, NULL, &acceleration_finished)); cl_event stepper_finished; cl_check(clEnqueueNDRangeKernel(cmdq, stepper_kernel, 1, NULL, &N, NULL, 1, &acceleration_finished, &stepper_finished)); cl_double3* positions_mapped = clEnqueueMapBuffer(cmdq, positions, CL_TRUE, CL_MAP_READ, 0, sizeof(cl_double3) * N, 1, &stepper_finished, NULL, &error); cl_check(error);

最满意答案

对于您的情况,您可以假设完全按顺序执行(如果您没有手动启用无序)。

OpenCL中有两种类型的队列:

有序(默认):

任务按排队顺序执行。 如果它们中的任何一个因任何原因而阻塞,则在完成任务之前,以下所有任务都不会执行。 事件仍在用于检查给定任务是否可以启动。

CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE序(使用标志CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE创建)

任务一旦准备就绪就会执行(它们所依赖的所有事件都是CL_COMPLETED )。

这并不意味着N个任务可以在单个队列中并行运行,如果它们不相互依赖的话。 某些硬件不支持该行为,并且需要创建单独的队列以允许并行执行任务。 其他一些硬件一次只能支持1个任务。 这取决于实现。

https://www.khronos.org/registry/cl/sdk/1.0/docs/man/xhtml/clCreateCommandQueue.html

For your case, you can just assume full in-order execution (if you did not manually enabled out-of-order).

There a re 2 types of queues in OpenCL:

In-order (default):

Tasks are executed in the order they are queued. If any of them blocks for any reason, all the following task will not execute until that one finishes. Events are still being used to check if a given task can start or not.

Out-of-order (created with the flag CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE):

Tasks execute as soon as they are ready to be consumed (all the events they depend on are CL_COMPLETED).

This does not mean that N tasks can run in parallel in a single queue if they do not depend on each other. Some hardware does not support that behavior, and requires to create a separate queue to allow parallel execution of tasks. Some other hardware will only support 1 task at a time. That is implementation dependent.

https://www.khronos.org/registry/cl/sdk/1.0/docs/man/xhtml/clCreateCommandQueue.html

更多推荐

本文发布于:2023-08-06 05:15:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1444802.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:队列   内核   命令   事件   在同一

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!