OpenCL™ C 6.15.19. 排队内核

6.15.19. Enqueuing Kernels
6.15.19. 排队内核

The functionality described in this section requires support for OpenCL C 2.0, or OpenCL C 3.0 or newer and the __opencl_c_device_enqueue feature.

​本节中描述的功能需要支持OpenCL C 2.0、OpenCL C 3.0或更高版本以及__OpenCL_C_device_enqueue功能。

This section describes built-in functions that allow a kernel to enqueue additional work to the same device, without host interaction. A kernel may enqueue code represented by Block syntax, and control execution order with event dependencies including user events and markers. There are several advantages to using the Block syntax: it is more compact; it does not require a cl_kernel object; and enqueuing can be done as a single semantic step.

本节描述了允许内核将额外工作队列到同一设备而无需主机交互的内置函数。内核可以将块语法表示的代码排队,并使用包括用户事件和标记在内的事件依赖关系来控制执行顺序。使用Block语法有几个优点:它更紧凑;它不需要cl_kernel对象;查询可以作为单个语义步骤完成。

The following table describes the list of built-in functions that can be used to enqueue a kernel(s).

下表描述了可用于将内核排队的内置函数列表。

When the cl_khr_device_enqueue_local_arg_types extension macro is supported, the Built-in Kernel Enqueue Functions and Built-in Kernel Query Functions described in this section can use any of the built-in OpenCL C scalar or vector integer or floating-point data types, or any user defined type built from these scalar and vector data types, as the pointee type of their arguments. This is indicated by the generic type name gentype in those function signatures.

​当支持cl_khr_device_enqueue_local_arg_types扩展宏时,本节中描述的内置内核队列函数和内置内核查询函数可以使用任何内置的OpenCL C标量或矢量整数或浮点数据类型,或从这些标量和矢量数据类型构建的任何用户定义类型作为其参数的指针类型。这由这些函数签名中的泛型类型名称gentype表示。

When the cl_khr_device_enqueue_local_arg_types extension macro is not supported, the pointee type of these functions must be void.

当不支持cl_khr_device_enqueue_local_arg_types扩展宏时,这些函数的指针类型必须为void。

The macro CLK_NULL_EVENT refers to an invalid device event. The macro CLK_NULL_QUEUE refers to an invalid device queue.

宏CLK_NULL_EVENT引用了无效的设备事件。宏CLK_NULL_QUEUE引用了无效的设备队列。

6.15.19.1. Built-in Functions - Enqueuing a Kernel
6.15.19.1. 内置函数-对内核进行入队列

Table 44. Built-in Kernel Enqueue Functions

表44 内置内核Enqueue函数

Built-in Function

内置函数

Description

描述

int enqueue_kernel(queue_t queue, kernel_enqueue_flags_t flags, const ndrange_t ndrange, void (^block)(void))
int enqueue_kernel(queue_t queue, kernel_enqueue_flags_t flags, const ndrange_t ndrange, uint num_events_in_wait_list, const clk_event_t *event_wait_list, clk_event_t *event_ret, void (^block)(void))
int enqueue_kernel(queue_t queue, kernel_enqueue_flags_t flags, const ndrange_t ndrange, void (^block)(local gentype *, …​), uint size0, …​)
int enqueue_kernel(queue_t queue, kernel_enqueue_flags_t flags, const ndrange_t ndrange, uint num_events_in_wait_list, const clk_event_t *event_wait_list, clk_event_t *event_ret, void (^block)(local gentype *, …​), uint size0, …​)

Enqueue the block for execution to queue.

将要执行的块放入队列。

If an event is returned, enqueue_kernel performs an implicit retain on the returned event.

如果返回了一个事件,enqueue_kernel会对返回的事件执行隐式保留。

The enqueue_kernel built-in function allows a work-item to enqueue a block. Work-items can enqueue multiple blocks to a device queue(s).

enqueue_kernel内置函数允许工作项将块入队列。工作项可以将多个块排队到设备队列中。

The enqueue_kernel built-in function returns CLK_SUCCESS if the block is enqueued successfully and returns CLK_ENQUEUE_FAILURE otherwise. If the -g compile option is specified in compiler options passed to clCompileProgram or clBuildProgram when compiling or building the parent program, the following errors may be returned instead of CLK_ENQUEUE_FAILURE to indicate why enqueue_kernel failed to enqueue the block:

如果块成功入队列,则enqueue_kernel内置函数返回CLK_SUCCESS,否则返回CLK_ENQUEUE_FAILURE。如果在编译或构建父程序时在传递给clCompileProgram或clBuildProgram的编译器选项中指定了-g compile选项,则可能会返回以下错误,而不是CLK_ENQUEUE_FAILURE,以指示enquee_kernel未能将块入队列的原因:

  • CLK_INVALID_QUEUE if queue is not a valid device queue.

  • 如果queue不是有效的设备队列,则返回CLK_INVALID_QUEUE。

  • CLK_INVALID_NDRANGE if ndrange is not a valid ND-range descriptor or if the program was compiled with -cl-uniform-work-group-size and the local_work_size is specified in ndrange but the global_work_size specified in ndrange is not a multiple of the local_work_size.

  • 如果ndrange不是有效的ND范围描述符,或者程序是使用-cl-uniform-work-group-size编译的,并且在ndrange 中指定了local_work_size,但在ndranges中指定的global_work_size不是local_work_size的倍数,则返回CLK_INVALID_NDRAGE。

  • CLK_INVALID_EVENT_WAIT_LIST if event_wait_list is NULL and num_events_in_wait_list > 0, or if event_wait_list is not NULL and num_events_in_wait_list is 0, or if event objects in event_wait_list are not valid events.

  • 如果event_wait_list 为NULL且num_events_in_wait_list>0,或者如果event_wait_list 不为NULL且num_events_in_wait_list 为0,或者event_wait_list 中的事件对象不是有效事件,则返回CLK_INVALID_EVENT_WAIT_LIST。

  • CLK_DEVICE_QUEUE_FULL if queue is full.

  • 如果queue 已满,则返回CLK_DEVICE_QUEUE_FULL 。

  • CLK_INVALID_ARG_SIZE if size of local memory arguments is 0.

  • 如果本地内存参数的大小为0,则返回CLK_INVALID_ARG_SIZE。

  • CLK_EVENT_ALLOCATION_FAILURE if event_ret is not NULL and an event could not be allocated.

  • 如果event_ret 不为NULL并且无法分配事件,则返回CLK_EVENT_ALLOCATION_FAILURE 。

  • CLK_OUT_OF_RESOURCES if there is a failure to queue the block in queue because of insufficient resources needed to execute the kernel.

  • CLK_OUT_OF_RESOURCES,如果由于执行内核所需的资源不足而无法将块排队到queue 中。

Below are some examples of how to enqueue a block.

下面是一些如何入队列的例子。

kernel void
my_func_A(global int *a, global int *b, global int *c)
{
    ...
}

kernel void
my_func_B(global int *a, global int *b, global int *c)
{
    ndrange_t ndrange;
    // build ndrange information
    ...

    // example - enqueue a kernel as a block
    enqueue_kernel(get_default_queue(), ndrange,
                   ^{my_func_A(a, b, c);});

    ...
}

kernel void
my_func_C(global int *a, global int *b, global int *c)
{
    ndrange_t ndrange;
    // build ndrange information
    ...

    // note that a, b and c are variables in scope of
    // the block
    void (^my_block_A)(void) = ^{my_func_A(a, b, c);};

    // enqueue the block variable
    enqueue_kernel(get_default_queue(),
                   CLK_ENQUEUE_FLAGS_WAIT_KERNEL,
                   ndrange,
                   my_block_A);
    ...
}

The example below shows how to declare a block literal and enqueue it.

下面的示例显示了如何声明块文本并将其入队列。

kernel void
my_func(global int *a, global int *b)
{
    ndrange_t ndrange;
    // build ndrange information
    ...

    // note that a, b and c are variables in scope of
    // the block
    void (^my_block_A)(void) =
    ^{
        size_t id = get_global_id(0);
        b[id] += a[id];
    };

    // enqueue the block variable
    enqueue_kernel(get_default_queue(),
                   CLK_ENQUEUE_FLAGS_WAIT_KERNEL,
                   ndrange,
                   my_block_A);

    // or we could have done the following
    enqueue_kernel(get_default_queue(),
                   CLK_ENQUEUE_FLAGS_WAIT_KERNEL,
                   ndrange,
                   ^{
                       size_t id = get_global_id(0);
                       b[id] += a[id];
                   };
}

Blocks passed to enqueue_kernel cannot use global variables or stack variables local to the enclosing lexical scope that are a pointer type in the local or private address space.

传递给enqueue_kernel的块不能使用全局变量或封闭词法作用域本地的堆栈变量,这些变量是本地或私有地址空间中的指针类型。

Example:

示例:

kernel void
foo(global int *a, local int *lptr, ...)
{
    enqueue_kernel(get_default_queue(),
                   CLK_ENQUEUE_FLAGS_WAIT_KERNEL,
                   ndrange,
                   ^{
                       size_t id = get_global_id(0);
                       local int *p = lptr; // undefined behavior
                   } );
}
6.15.19.2. Arguments That are a Pointer Type to Local Address Space
6.15.19.2. 指向本地地址空间的指针类型的参数

A block passed to enqueue_kernel can have arguments declared to be a pointer to local memory. The enqueue_kernel built-in function variants allow blocks to be enqueued with a variable number of arguments. Each argument must be declared to be a void pointer to local memory. These enqueue_kernel built-in function variants also have a corresponding number of arguments each of type uint that follow the block argument. These arguments specify the size of each local memory pointer argument of the enqueued block.

传递给enqueue_kernel的块可以将参数声明为指向本地内存的指针。enqueue_kernel内置函数变j量允许使用可变数量的参数对块进行排队。每个参数都必须声明为指向本地内存的空指针。这些enqueue_kernel内置函数变体也有相应数量的参数,每个参数都是块参数后面的uint类型。这些参数指定了排队块的每个本地内存指针参数的大小。

Some examples follow:

以下是一些示例:

kernel void
my_func_A_local_arg1(global int *a, local int *lptr, ...)
{
    ...
}

kernel void
my_func_A_local_arg2(global int *a,
                     local int *lptr1, local float4 *lptr2, ...)
{
    ...
}

kernel void
my_func_B(global int *a, ...)
{
    ...

    ndrange_t ndrange = ndrange_1D(...);

    uint local_mem_size = compute_local_mem_size();

    enqueue_kernel(get_default_queue(),
                   CLK_ENQUEUE_FLAGS_WAIT_KERNEL,
                   ndrange,
                   ^(local void *p){
                       my_func_A_local_arg1(a, (local int *)p, ...);},
                   local_mem_size);
}

kernel void
my_func_C(global int *a, ...)
{
    ...
    ndrange_t ndrange = ndrange_1D(...);

    void (^my_blk_A)(local void *, local void *) =
        ^(local void *lptr1, local void *lptr2){
        my_func_A_local_arg2(
            a,
            (local int *)lptr1,
            (local float4 *)lptr2, ...);};

    // calculate local memory size for lptr
    // argument in local address space for my_blk_A
    uint local_mem_size = compute_local_mem_size();

    enqueue_kernel(get_default_queue(),
                   CLK_ENQUEUE_FLAGS_WAIT_KERNEL,
                   ndrange,
                   my_blk_A,
                   local_mem_size, local_mem_size*4);
}
6.15.19.3. A Complete Example
6.15.19.3. 完整示例

The example below shows how to implement an iterative algorithm where the host enqueues the first instance of the nd-range kernel (dp_func_A). The kernel dp_func_A will launch a kernel (evaluate_dp_work_A) that will determine if new nd-range work needs to be performed. If new nd-range work does need to be performed, then evaluate_dp_work_A will enqueue a new instance of dp_func_A . This process is repeated until all the work is completed.

下面的示例显示了如何实现迭代算法,其中主机将nd范围内核(dp_func_A)的第一个实例入队列。内核dp_func_A将启动一个内核(evaluate_dp_work_A),该内核将确定是否需要执行新的nd范围工作。如果确实需要执行新的nd范围工作,则evaluate_dp_work_A将为dp_func_A的新实例排队。重复此过程,直到完成所有工作。

kernel void
dp_func_A(queue_t q, ...)
{
    ...

    // queue a single instance of evaluate_dp_work_A to
    // device queue q. queued kernel begins execution after
    // kernel dp_func_A finishes

    if (get_global_id(0) == 0)
    {
        enqueue_kernel(q,
                       CLK_ENQUEUE_FLAGS_WAIT_KERNEL,
                       ndrange_1D(1),
                       ^{evaluate_dp_work_A(q, ...);});
    }
}

kernel void
evaluate_dp_work_A(queue_t q,...)
{
    // check if more work needs to be performed
    bool more_work = check_new_work(...);
    if (more_work)
    {
        size_t global_work_size = compute_global_size(...);

        void (^dp_func_A_blk)(void) =
            ^{dp_func_A(q, ...});

        // get local WG-size for kernel dp_func_A
        size_t local_work_size =
            get_kernel_work_group_size(dp_func_A_blk);

        // build nd-range descriptor
        ndrange_t ndrange = ndrange_1D(global_work_size,
                                       local_work_size);

        // enqueue dp_func_A
        enqueue_kernel(q,
                       CLK_ENQUEUE_FLAGS_WAIT_KERNEL,
                       ndrange,
                       dp_func_A_blk);
    }
    ...
}
6.15.19.4. Determining when a Child Kernel Begins Execution
6.15.19.4. 确定子内核何时开始执行

The kernel_enqueue_flags_t [88] argument to the enqueue_kernel built-in functions can be used to specify when the child kernel begins execution. Supported values are described in the following table:

enqueue_kernel函数的​kernel_enqueue_flags_t [88]参数可用于指定子内核何时开始执行。支持的值如下表所示:

Table 45. Kernel Enqueue Flags

表45 内核Enqueue标志

kernel_enqueue_flags_t enum

kernel_enqueue_flags_t枚举

Description

描述

CLK_ENQUEUE_FLAGS_NO_WAIT

Indicates that the enqueued kernels do not need to wait for the parent kernel to finish execution before they begin execution.

表示队列的内核在开始执行之前不需要等待父内核完成执行。

CLK_ENQUEUE_FLAGS_WAIT_KERNEL

Indicates that all work-items of the parent kernel must finish executing and all immediate [89] side effects committed before the enqueued child kernel may begin execution.

​表示父内核的所有工作项必须完成执行,并且在排队的子内核开始执行之前,必须提交所有立即的[89]副作用。

CLK_ENQUEUE_FLAGS_WAIT_WORK_GROUP

Indicates that the enqueued kernels wait only for the workgroup that enqueued the kernels to finish before they begin execution. [90]

​表示入排列的内核在开始执行之前只等待将内核队列的工作组完成。 [90]

The kernel_enqueue_flags_t flags are useful when a kernel enqueued from the host and executing on a device enqueues kernels on the device. The kernel enqueued from the host may not have an event associated with it. The kernel_enqueue_flags_t flags allow the developer to indicate when the child kernels can begin execution.

当从主机队列并在设备上执行的内核将设备上的内核入队列时,kernel_enqueue_flags_t标志很有用。从主机队列的内核可能没有与之关联的事件。kernel_enqueue_flags_t标志允许开发人员指示子内核何时可以开始执行。

6.15.19.5. Determining When a Parent Kernel has Finished Execution
6.15.19.5. 确定父内核何时完成执行

A parent kernel’s execution status is considered to be complete when it and all its child kernels have finished execution. The execution status of a parent kernel will be CL_COMPLETE if this kernel and all its child kernels finish execution successfully. The execution status of the kernel will be an error code (given by a negative integer value) if it or any of its child kernels encounter an error, or are abnormally terminated.

当父内核及其所有子内核都完成执行时,父内核的执行状态被认为是完成的。如果此内核及其所有子内核成功完成执行,则父内核的执行状态将为CL_COMPLETE。如果内核或其任何子内核遇到错误或异常终止,则内核的执行状态将是错误代码(由负整数值给出)。

For example, assume that the host enqueues a kernel k for execution on a device. Kernel k when executing on the device enqueues kernels A and B to a device queue(s). The enqueue_kernel call to enqueue kernel B specifies the event associated with kernel A in the event_wait_list argument, i.e. wait for kernel A to finish execution before kernel B can begin execution. Let’s assume kernel A enqueues kernels XY and Z. Kernel A is considered to have finished execution, i.e. its execution status is CL_COMPLETE, only after A and the kernels A enqueued (and any kernels these enqueued kernels enqueue and so on) have finished execution.

例如,假设主机将内核k入队列在设备上执行。内核k在设备上执行时,将内核A和B入队列到设备队列中。对入队内核B的入队内核调用在event_wait_list参数中指定了与内核A关联的事件,即等待内核A完成执行,然后内核B才能开始执行。让我们假设内核A将内核X、Y和Z排队。只有在A和排队的内核A(以及这些排队的内核等)完成执行后,内核A才被认为已经完成执行,即其执行状态为CL_COMPLETE。

6.15.19.6. Built-in Functions - Kernel Query Functions
6.15.19.6. 内置函数-内核查询函数

Table 46. Built-in Kernel Query Functions

表46 内置内核查询函数

Built-in Function

内置函数

Description

描述

uint get_kernel_work_group_size(void (^block)(void))
uint get_kernel_work_group_size(void (^block)(local gentype *, …​))

This provides a mechanism to query the maximum work-group size that can be used to execute a block on a specific device given by device.

这提供了一种机制来查询可用于在设备给定的特定device上执行块的最大工作组大小。

block specifies the block to be enqueued.

block指定要排队的块。

uint get_kernel_preferred_work_group_size_multiple( void (^block)(void))
uint get_kernel_preferred_work_group_size_multiple( void (^block)(local gentype *, …​))

Returns the preferred multiple of work-group size for launch. This is a performance hint. Specifying a work-group size that is not a multiple of the value returned by this query as the value of the local work size argument to enqueue_kernel will not fail to enqueue the block for execution unless the work-group size specified is larger than the device maximum.

返回启动时工作组大小的首选倍数。这是一个性能提示。指定一个不是此查询返回值的倍数的工作组大小作为enqueue_kernel的本地工作大小参数的值,不会导致块入队列执行失败,除非指定的工作组大小将大于设备最大值。

6.15.19.7. Built-in Functions - Queuing Other Commands
6.15.19.7. 内置函数-排队其他命令

The following table describes the list of built-in functions that can be used to enqueue commands such as a marker.

下表描述了可用于将标记等命令排队的内置函数列表。

Table 47. Built-in Other Enqueue Functions

表47 内置其他入队列函数

Built-in Function

内置函数

Description

描述

int enqueue_marker(queue_t queue, uint num_events_in_wait_list, const clk_event_t *event_wait_list, clk_event_t *event_ret)

Enqueue a marker command to queue.

将标记命令入队列。

The marker command waits for a list of events specified by event_wait_list to complete before the marker completes.

marker命令在标记完成之前等待event_wait_list指定的事件列表完成。

event_ret must not be NULL as otherwise this is a no-op.

event_ret不能为NULL,否则这是一个无操作。

If an event is returned, enqueue_marker performs an implicit retain on the returned event.

如果返回了一个事件,enqueue_marker会对返回的事件执行隐式保留。

The enqueue_marker built-in function returns CLK_SUCCESS if the marked command is enqueued successfully and returns CLK_ENQUEUE_FAILURE otherwise. If the -g compile option is specified in compiler options passed to clCompileProgram or clBuildProgram, the following errors may be returned instead of CLK_ENQUEUE_FAILURE to indicate why enqueue_marker failed to enqueue the marker command:

如果标记的命令成功入队列,则enqueue_marker内置函数返回CLK_SUCCESS,否则返回CLK_ENQUEUE_FAILURE。如果在传递给clCompileProgram或clBuildProgram的编译器选项中指定了-g compile选项,则可能会返回以下错误,而不是CLK_ENQUEUE_FAILURE,以指示enqueue_marker未能将标记命令排队的原因:

  • CLK_INVALID_QUEUE if queue is not a valid device queue.

  • 如果queue不是有效的设备队列,则返回CLK_INVALID_QUEUE。

  • CLK_INVALID_EVENT_WAIT_LIST if event_wait_list is NULL, or if event_wait_list is not NULL and num_events_in_wait_list is 0, or if event objects in event_wait_list are not valid events.

  • 如果event_wait_list为NULL,或者event_wait_list不为NULL且num_events_in_wait_list=0,或者event_wait_list中的事件对象不是有效事件,则返回CLK_INVALID_EVENT_WAIT_LIST。

  • CLK_DEVICE_QUEUE_FULL if queue is full.

  • 如果queue已满,则返回CLK_DEVICE_QUEUE_FULL

  • CLK_EVENT_ALLOCATION_FAILURE if event_ret is not NULL and an event could not be allocated.

  • 如果event_ret不为NULL并且无法分配事件,则返回CLK_EVENT_ALLOCATION_FAILURE

  • CLK_OUT_OF_RESOURCES if there is a failure to queue the block in queue because of insufficient resources needed to execute the kernel.

  • CLK_OUT_OF_RESOURCES,如果由于执行内核所需的资源不足而无法将块排队到queue中。

6.15.19.8. Built-in Functions - Event Functions
6.15.19.8. 内置函数-事件函数

The following table describes the list of built-in functions that work on events.

下表描述了处理事件的内置函数列表。

Table 48. Built-in Event Functions

表48 内置事件函数

Built-in Function

内置函数

Description

描述

void retain_event(clk_event_t event)

Increments the event reference count. Behavior is undefined if event is not a valid event.

递增事件引用计数。如果event不是有效事件,则行为未定义。

void release_event(clk_event_t event)

Decrements the event reference count. The event object is deleted once the event reference count is zero, the specific command identified by this event has completed (or terminated), and there are no commands in any device command-queue that require a wait for this event to complete. Behavior is undefined if event is not a valid event.

递减事件引用计数。一旦事件引用计数为零,此事件标识的特定命令已完成(或终止),并且任何设备命令队列中都没有需要等待此事件完成的命令,则会删除事件对象。如果event不是有效事件,则行为未定义。

clk_event_t create_user_event()

Create a user event. Returns the user event. The execution status of the user event created is set to CL_SUBMITTED.

创建用户事件。返回用户事件。创建的用户事件的执行状态设置为CL_SUBMITTED。

bool is_valid_event(clk_event_t event)

Returns true if event is a valid event. Otherwise returns false.

如果event是有效事件,则返回true。否则返回false。

void set_user_event_status(clk_event_t event, int status)

Sets the execution status of a user event. Behavior is undefined if event is not a valid event returned by create_user_eventstatus can be either CL_COMPLETE or a negative integer value indicating an error.

设置用户事件的执行状态。如果event不是create_user_event返回的有效事件,则行为未定义。status可以是CL_COMPLETE,也可以是表示错误的负整数值。

void capture_event_profiling_info(clk_event_t event, clk_profiling_info name, global void *value)

Captures the profiling information for functions that are enqueued as commands. These enqueued commands are identified by unique event objects. The profiling information will be available in value once the command identified by event has completed.

捕获作为命令排队的函数的分析信息。这些入队列命令由唯一的事件对象标识。一旦event标识的命令完成,分析信息将以value的形式可用。

Behavior is undefined if event is not a valid event returned by enqueue_kernel.

如果event不是enqueue_kernel返回的有效事件,则行为未定义。

name identifies which profiling information is to be queried and can be:

name标识要查询的分析信息,可以是:

CLK_PROFILING_COMMAND_EXEC_TIME

value is a pointer to two 64-bit values.

value是指向两个64位值的指针。

The first 64-bit value describes the elapsed time CL_PROFILING_COMMAND_END - CL_PROFILING_COMMAND_START for the command identified by event in nanoseconds.

第一个64位值描述了event标识的命令的运行时间CL_PROFILING_COMMAND_END-CL_PROFILING_COMMAND_START,单位为纳秒。

The second 64-bit value describes the elapsed time CL_PROFILING_COMMAND_COMPLETE - CL_PROFILING_COMMAND_START for the command identified by event in nanoseconds.

第二个64位值描述了event标识的命令的运行时间CL_PROFILING_COMMAND_COMPLETE-CL_PROFILING_COMMAND_START,单位为纳秒。

The behavior of capture_event_profiling_info when called multiple times for the same event is undefined.

当对同一event多次调用capture_event_profiling_info时,其行为未定义。

Events can be used to identify commands enqueued to a command-queue from the host. These events created by the OpenCL runtime can only be used on the host, i.e. as events passed in the event_wait_list argument to various enqueue APIs or runtime APIs that take events as arguments, such as clRetainEventclReleaseEvent, and clGetEventProfilingInfo.

事件可用于标识从主机排队到命令队列的命令。由OpenCL运行时创建的这些事件只能在主机上使用,即作为在event_wait_list参数中传递给各种队列API或将事件作为参数的运行时API的事件,如clRetainEvent、clReleaseEvent和clGetEventProfilingInfo。

Similarly, events can be used to identify commands enqueued to a device queue (from a kernel). These event objects cannot be passed to the host or used by OpenCL runtime APIs such as the enqueue APIs or runtime APIs that take event arguments.

同样,事件可用于标识(从内核)排队到设备队列的命令。这些事件对象不能传递给主机,也不能由OpenCL运行时API使用,如排队API或接受事件参数的运行时API。

clRetainEvent and clReleaseEvent will return CL_INVALID_OPERATION if event specified is an event that refers to any kernel enqueued to a device queue using enqueue_kernel or enqueue_marker, or is a user event created by create_user_event.

如果指定的event是指使用enqueue_kernel或enqueue_marker排队到设备队列的任何内核的事件,或者是由create_user_event创建的用户事件,则clRetainEvent和clReleaseEvent将返回CL_INVALID_OPERATION。

Similarly, clSetUserEventStatus can only be used to set the execution status of events created using clCreateUserEvent. User events created on the device can be set using set_user_event_status built-in function.

同样,clSetUserEventStatus只能用于设置使用clCreateUserEvent创建的事件的执行状态。可以使用set_user_event_status内置函数设置在设备上创建的用户事件。

The example below shows how events can be used with kernels enqueued to multiple device queues.

下面的示例显示了如何将事件与排队到多个设备队列的内核一起使用。

extern void barA_kernel(...);
extern void barB_kernel(...);

kernel void
foo(queue_t q0, queue q1, ...)
{
    ...
    clk_event_t evt0;

    // enqueue kernel to queue q0
    enqueue_kernel(q0,
                   CLK_ENQUEUE_FLAGS_NO_WAIT,
                   ndrange_A,
                   0, NULL, &evt0,
                   ^{barA_kernel(...);} );

    // enqueue kernel to queue q1
    enqueue_kernel(q1,
                   CLK_ENQUEUE_FLAGS_NO_WAIT,
                   ndrange_B,
                   1, &evt0, NULL,
                   ^{barB_kernel(...);} );

    // release event evt0. This will get released
    // after barA_kernel enqueued in queue q0 has finished
    // execution and barB_kernel enqueued in queue q1 and
    // waits for evt0 is submitted for execution, i.e. wait
    // for evt0 is satisfied.
    release_event(evt0);

}

The example below shows how the marker command can be used with kernels enqueued to a device queue.

下面的示例显示了如何将标记命令与排队到设备队列的内核一起使用。

kernel void
foo(queue_t q, ...)
{
    ...
    clk_event_t marker_event;
    clk_event_t events[2];

    enqueue_kernel(q,
                   CLK_ENQUEUE_FLAGS_NO_WAIT,
                   ndrange,
                   0, NULL, &events[0],
                   ^{barA_kernel(...);} );

    enqueue_kernel(q,
                   CLK_ENQUEUE_FLAGS_NO_WAIT,
                   ndrange,
                   0, NULL, &events[1],
                   ^{barB_kernel(...);} );

    // barA_kernel and barB_kernel can be executed
    // out-of-order. We need to wait for both these
    // kernels to finish execution before barC_kernel
    // starts execution so we enqueue a marker command and
    // then enqueue barC_kernel that waits on the event
    // associated with the marker.
    enqueue_marker(q, 2, events, &marker_event);

    enqueue_kernel(q,
                   CLK_ENQUEUE_FLAGS_NO_WAIT,
                   1, &marker_event, NULL,
                   ^{barC_kernel(...);} );

    release_event(events[0];
    release_event(events[1]);
    release_event(marker_event);
}
6.15.19.9. Built-in Functions - Helper Functions
6.15.19.9. 内置函数-帮助函数

Table 49. Built-in Helper Functions

表49 内置帮助功能

Built-in Function

内置函数

Description

描述

queue_t get_default_queue(void)

Returns the default device queue. If a default device queue has not been created, CLK_NULL_QUEUE is returned.

返回默认设备队列。如果尚未创建默认设备队列,则返回CLK_NULL_QUEUE

ndrange_t ndrange_1D(size_t global_work_size)
ndrange_t ndrange_1D(size_t global_work_size, size_t local_work_size)
ndrange_t ndrange_1D(size_t global_work_offset, size_t global_work_size, size_t local_work_size)
ndrange_t ndrange_2D(const size_t global_work_size[2])
ndrange_t ndrange_2D(const size_t global_work_size[2], const size_t local_work_size[2])
ndrange_t ndrange_2D(const size_t global_work_offset[2], const size_t global_work_size[2], const size_t local_work_size[2])
ndrange_t ndrange_3D(const size_t global_work_size[3])
ndrange_t ndrange_3D(const size_t global_work_size[3], const size_t local_work_size[3])
ndrange_t ndrange_3D(const size_t global_work_offset[3], const size_t global_work_size[3], const size_t local_work_size[3])

Builds a 1D, 2D or 3D ND-range descriptor.

构建1D、2D或3D ND范围描述符。

内容概要:本文围绕“计及V2G主动支撑的光伏-储能-电动汽车输配协同日前优化调度”展开研究,提出了一种综合考虑光伏发电、储能系统与电动汽车(EV)在V2G(Vehicle-to-Grid)模式下协同参与电网调度的优化模型。通过Matlab代码实现,构建了日前优化调度框架,充分挖掘电动汽车作为移动储能单元的潜力,利用其双向充放电能力为主动配电网提供调峰、填谷和备用等主动支撑服务。研究综合考虑了可再生能源出力不确定性、负荷需求波动以及电动汽车出行行为特征,建立了多主体、多目标的协同优化机制,旨在降低系统运行成本、提高新能源消纳水平,并增强电网运行的稳定性与可靠性。该资源属于电力系统与综合能源系统领域的高水平科研复现资料,具备较强的理论深度与工程应用价值; 适合人群:具备电力系统分析、优化建模基础及Matlab编程能力的研究生、科研人员,以及从事智能电网、能源互联网、综合能源系统等相关领域技术研发的专业技术人员; 使用场景及目标:①用于学习和复现源-网-荷-储协同优化调度的核心建模方法与求解流程;②掌握V2G技术在电网调频调峰中的数学建模方法及其在优化调度中的集成应用;③支撑光伏、储能与电动汽车耦合系统的低碳经济调度、鲁棒优化或分布鲁棒优化等前沿课题的研究与仿真验证; 阅读建议:建议结合文中提供的Matlab代码与主流优化工具箱(如YALMIP、CPLEX、Gurobi等)进行实践操作,重点理解目标函数设计、约束条件构建及多变量耦合关系的处理策略,同时可进一步拓展至日内滚动优化、实时调度或多时间尺度协调优化方向开展深入研究。
内容概要:本文提出了一种基于改进自适应完备集合经验模态分解(Improved Adaptive Complete Ensemble Empirical Mode Decomposition, ICEEMDAN)的混合储能辅助火电机组调频协同控制策略,并提供了完整的Matlab代码实现。该策略利用ICEEMDAN对电网频率波动信号进行高精度自适应分解,提取不同时间尺度下的功率分量,进而合理分配火电机组与混合储能系统(如蓄电池、飞轮等)的调频任务,充分发挥各自响应速度快慢互补的优势。通过引入优化算法对功率分配系数进行动态整定,实现了调频过程中储能系统的高效协同运行,有效抑制了功率波动,提升了系统频率调节的快速性、稳定性和调节精度,同时延长了储能设备的使用寿命。文中详细阐述了算法原理、模型构建、控制逻辑设计及仿真验证过程,具有较强的可复现性与工程应用价值。; 适合人群:具备电力系统自动化、新能源并网控制或智能优化算法等相关专业知识背景,熟悉Matlab/Simulink仿真平台的技术人员,特别适用于从事电网调频、储能系统控制、信号处理在电力系统中应用等方向的研究生、科研人员及工程技术人员。; 使用场景及目标:①深入研究混合储能系统在提升传统火电机组调频性能中的作用机制;②掌握ICEEMDAN等先进非平稳信号处理方法在功率动态分解中的具体实现与参数调优;③构建火电机组-储能协同调频仿真模型,开展多工况对比分析以优化控制性能;④为相关学术论文复现、科研项目申报或实际工程方案设计提供可靠的技术参考与代码支持。; 阅读建议:建议结合Matlab代码逐模块阅读文档内容,重点关注ICEEMDAN的实现流程、IMF分量筛选规则、功率分配权重计算逻辑及整体控制架构的设计思路。读者可通过调整信号噪声水平、滤波参数、储能容量配置等变量进行仿真实验,对比不同策略下的调频效果,从而深化对协同控制机理的理解,并可进一步拓展至风光火储联合系统或多时间尺度协调控制的研究场景。
内容概要:本文围绕《【顶级EI完整复现】【DRCC】考虑N-1准则的分布鲁棒机会约束低碳经济调度(Matlab代码实现)》展开,系统介绍了一种融合分布鲁棒优化(DRO)与机会约束规划(CCP)的低碳经济调度模型,并引入电力系统N-1安全准则以增强调度方案在设备故障等异常工况下的可靠性。该研究针对新能源出力波动、负荷不确定性等实际挑战,构建了兼具环保性与经济性的优化调度框架,通过Matlab实现了完整的数学建模、算法求解与仿真验证流程,属于高水平学术成果的工程化复现,具有较强的理论深度与实践价值。; 适合人群:具备电力系统分析、优化建模基础及Matlab编程能力,从事能源系统调度、低碳技术、智能电网等领域研究的研究生、科研人员及工程技术人员(建议工作年限1-5年)。; 使用场景及目标:① 学习并复现顶级EI期刊中低碳经济调度的先进建模范式;② 掌握分布鲁棒优化与机会约束在处理不确定性问题中的建模技巧;③ 理解N-1安全准则在优化模型中的集成方法与工程意义;④ 利用所提供的Matlab代码进行算法验证、参数调试或拓展至微电网、综合能源系统等应用场景。; 阅读建议:建议结合相关优化理论文献与原始论文对照学习,重点剖析模型构建的数学逻辑与物理含义,动手运行代码并尝试修改约束条件、调整不确定性参数或替换测试系统,以深化对算法性能与调度策略的理解,提升解决复杂电力系统优化问题的实战能力。
源码直接下载地址: https://pan.quark.cn/s/a4b39357ea24 标题中的“mac驱动兼容win11系统驱动适配版本bootcamp_5.1.5640”明确指出这是一个面向苹果Mac电脑用户的产品,其核心目的是协助用户在Windows 11操作系统上完成驱动程序的安装与配置工作。BootCamp作为苹果公司推出的一项工具,赋予Mac用户在不移除原有macOS系统的前提下,安装并执行Windows操作系统的能力。此特定版本的BootCamp 5.1.5640是专门针对Windows 11环境进行优化的驱动适配版本。 描述部分提及的“mac装win11适配的驱动包”,表明这个压缩文件内含了适配Mac硬件在Windows 11操作系统下运行的驱动程序,涵盖显卡、声卡、网卡等关键设备。用户需首先对文件进行解压缩操作,随后在BootCamp文件夹中找到名为"BootCamp.msi"的安装文件,通过双击执行来启动安装流程。这一步骤是BootCamp驱动安装过程中的核心环节,其中msi文件代表Microsoft Installer格式,其功能在于应用程序的分发与管理。 “BootCamp”标签进一步验证了该压缩包的主要功能,即借助BootCamp服务实现Mac设备与Windows系统之间的硬件兼容性。BootCamp的功能不止于提供驱动程序,还集成了一个引导管理器,允许用户在系统启动时选择运行macOS或Windows。 在压缩包的文件清单中: 1. "AutoUnattend.xml":该文件通常作为无人值守安装的配置文档,旨在自动执行Windows安装过程中的部分或全部设置任务,如用户账户的建立、地区设定的调整、网络配置等,从而提升安装的便捷性。 ...
内容概要:本文聚焦于“考虑能流-物流耦合的港口综合能源系统规划关键技术及挑战”的研究,深入探讨了在港口这一特定场景下,能源流(如电力、热能、氢能等)与货物物流系统之间的协同优化问题。通过构建综合能源系统(IES)的数学模型,并结合Matlab代码实现,研究旨在满足港口高强度物流作业需求的同时,优化能源系统的设备配置与运行调度策略,从而提升整体能源利用效率、降低碳排放水平。核心技术涵盖多能流耦合建模、多目标优化算法(如智能优化算法)的应用、关键能源设备(如储能、发电机)的容量规划、以及复杂的运行调度机制。文章还系统分析了当前在多源异构数据融合、模型求解复杂性、不确定性处理以及从理论研究到实际工程应用转化过程中所面临的关键挑战。; 适合人群:具备电力系统、能源系统、自动化或交通运输等相关专业背景,熟悉Matlab编程语言,且正在从事综合能源系统规划、港口智慧能源管理、多目标优化调度等领域研究的研究生、科研人员及工程技术人员。; 使用场景及目标:①开展港口综合能源系统的规划与多时间尺度优化调度研究;②学习并掌握能流-物流耦合系统的系统性建模方法与多目标优化求解技术;③深入理解并实践Matlab在复杂能源系统仿真、优化算法实现与结果分析中的具体应用; 阅读建议:此资源以Matlab代码实现为核心载体,强调理论模型构建与编程实践的高度结合,建议读者在学习过程中务必关注模型的设计逻辑、假设条件与代码实现细节,通过动手复现、调试和修改程序,以深刻理解能流-物流耦合系统内在的优化机制与关键技术难点。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值