kupl::graph_submit(task)
Add a dynamic graph task to the KUPL graph, that is, submit the task 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.
Interface Definition
int kupl::graph_submit(kupl_graph_h graph, kupl_task_desc_t *desc, const std::function<void(void)> &func);
Parameters
Parameter |
Type |
Description |
Input/Output |
|---|---|---|---|
graph |
kupl_graph_h |
KUPL graph to which a dynamic graph task needs to be added. |
Input |
desc |
kupl_task_desc_t * |
Description of the dynamic graph task to be added. For details, see the following table. |
Input |
func |
std::function<void(void)> |
Function to be executed by the task. |
Input |
Parameter |
Type |
Description |
|---|---|---|
field_mask |
uint64_t |
Mask, which is used to specify which values in the structure are valid. The mask must be set for parameters to take effect. Options:
|
name |
const char * |
Task name, which takes effect only after the mask KUPL_TASK_DESC_FIELD_NAME is configured. |
priority |
int |
Task priority, which takes effect only after the mask KUPL_TASK_DESC_FIELD_PRIORITY is configured. A larger value indicates a higher priority. |
ndep |
size_t |
Number of depends in dep_list of a dynamic graph task, that is, the number of parameters passed by the task for dependency between tasks. This parameter takes effect only after the mask KUPL_TASK_DESC_FIELD_DEP is configured. |
dep_list |
kupl_task_dep_t * |
List of depends of a dynamic graph task, that is, the parameter list passed by the task for dependency between tasks. This parameter takes effect only after the mask KUPL_TASK_DESC_FIELD_DEP is configured. |
flag |
uint32_t |
Task flag, which takes effect only after the mask KUPL_TASK_DESC_FIELD_FLAG is configured. It can be set to KUPL_TASK_FLAG_IMM, indicating that the task is directly executed without scheduling. |
Parameter |
Type |
Description |
|---|---|---|
base_addr |
const void * |
Address of the dep parameter. |
type |
kupl_task_dep_type_t |
dep type, including: KUPL_TASK_DEP_TYPE_IN: input parameter of a task. KUPL_TASK_DEP_TYPE_OUT: output parameter of a task. KUPL_TASK_DEP_TYPE_INOUT: input and output parameters of a task. KUPL_TASK_DEP_TYPE_ALL: This parameter depends on all previous tasks. |
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 | #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_task_desc_t task_desc = { .field_mask = KUPL_TASK_DESC_FIELD_FLAG, .flag = KUPL_TASK_FLAG_IMM, }; int ret = kupl::graph_submit(graph, &task_desc, []() { printf("graph task test\n"); }); assert(ret == KUPL_OK); kupl_graph_wait(graph); kupl_graph_destroy(graph); kupl_egroup_destroy(egroup); return 0; } |
The execution result is as follows:
graph task test
The preceding example demonstrates the process of submitting a task to a graph. The kupl::graph_submit function is used to submit a task and print the corresponding information.