Rate This Document
Findability
Accuracy
Completeness
Readability

kupl::graph_submit(taskloop)

Add a task loop to the KUPL graph, that is, submit a task loop for execution.

Compared with kupl_graph_submit, this interface uses the lambda function to capture the input parameters of the kupl_graph_submit callback, eliminating the need for manual parameter encapsulation and improving interface usability.

Compared with kupl::graph_submit(task), this interface submits a task of the task loop type. The primary distinction is found in the input parameters. This interface relies on C++ function overloading.

Interface Definition

int kupl::graph_submit(kupl_graph_h graph, kupl_taskloop_desc_t* desc, const std::function<void(const kupl_nd_range_t *)> &func);

Parameters

Table 1 Parameter definitions

Parameter

Type

Description

Input/Output

graph

kupl_graph_h

KUPL graph to which a task loop needs to be added.

Input

desc

kupl_taskloop_desc_t *

Description of the task loop to be added. For details, see the following table.

Input

func

std::function<void(const kupl_nd_range_t *)>

Function to be executed by the task loop.

Input

Table 2 kupl_taskloop_desc_t data structure

Parameter

Type

Description

field_mask

uint64_t

Mask of valid fields in the structure, similar to the bit flag of kupl_taskloop_desc_field.

Fields not specified in this mask will be ignored. This parameter is mandatory for all fields.

Options:

  • KUPL_TASKLOOP_DESC_FIELD_RANGE: The range takes effect.
  • KUPL_TASKLOOP_DESC_FIELD_EGROUP: The egroup takes effect.
  • KUPL_TASKLOOP_DESC_FIELD_DEFAULT: All the preceding fields take effect.

range

kupl_nd_range_t *

Task loop range. For details, see the section "kupl_parallel_for."

egroup

kupl_egroup_h

egroup where the task loop is executed, that is, the specific executor assigned to process the loop.

Return Value

  • Success: KUPL_OK
  • Failure: KUPL_ERROR

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <stdio.h> 
#include "kupl.h" 
#include <assert.h>

int main() 
{ 
    int executor_num = kupl_get_num_executors(); 
    int executors[executor_num]; 
    for (int i = 0; i < executor_num; i++) {
        executors[i] = i;
    } 
    kupl_egroup_h egroup = kupl_egroup_create(executors, executor_num);
    kupl_graph_h graph = kupl_graph_create(egroup); 
    kupl_nd_range_t range;
    KUPL_1D_RANGE_INIT(range, 0, executor_num);
    kupl_taskloop_desc_t taskloop_desc = {
        .field_mask = KUPL_TASKLOOP_DESC_FIELD_DEFAULT,
        .range = &range,
        .egroup = egroup
    };
    int ret = kupl::graph_submit(graph, &taskloop_desc, [](const kupl_nd_range_t *nd_range) {
        printf("graph taskloop test\n");
    }); 
    assert(ret == KUPL_OK);

    kupl_graph_wait(graph);
    kupl_egroup_destroy(egroup);
    return 0;
}

The execution result is as follows:

graph taskloop test.
graph taskloop test.
graph taskloop test.
graph taskloop test.

The preceding example demonstrates the process of submitting a task loop to a graph.