kupl_graph_submit
向kupl图中添加task,即提交执行task任务。
接口定义
int kupl_graph_submit(kupl_graph_h graph, kupl_task_info_t *info);
参数
参数名 |
类型 |
描述 |
输入/输出 |
---|---|---|---|
graph |
kupl_graph_h |
需要向其中添加task的kupl graph |
输入 |
info |
kupl_task_info_t * |
需要添加的task的信息,具体见下表 |
输入 |
参数名 |
类型 |
描述 |
---|---|---|
type |
kupl_task_type_t |
task 的具体类型,可以设置为:
|
desc |
void * |
task 类型所对应的描述,可以设置为:
|
参数名 |
类型 |
描述 |
---|---|---|
func |
void (*kupl_task_func_t)(void *args) |
task的函数,task任务需要执行的具体函数 |
args |
void * |
func函数需要传入的参数 |
name |
const char * |
需要配置掩码KUPL_TASK_DESC_FIELD_NAME后才生效;task任务的名字 |
priority |
int |
需要配置掩码KUPL_TASK_DESC_FIELD_PRIORITY后才生效;task任务的优先级,数值越大,优先级越高 |
flag |
uint32_t |
需要配置掩码KUPL_TASK_DESC_FIELD_FLAG后才生效;task任务的flag,可设置为KUPL_TASK_FLAG_IMM,表示直接执行task,不需要调度 |
field_mask |
uint32_t |
掩码,用于指定结构体中哪些值有效,不设置掩码情况下仅func、args参数生效,其他需要设置掩码。 具体可设置的掩码:
|
参数名 |
类型 |
描述 |
---|---|---|
sgraph |
kupl_sgraph_h |
需要提交的静态图 |
name |
const char * |
需要配置掩码KUPL_SGRAPH_TASK_DESC_FIELD_NAME后才能生效;静态图task的名字 |
priority |
int |
需要配置掩码KUPL_SGRAPH_TASK_DESC_FIELD_PRIORITY后才能生效;静态图task的优先级,数值越大,优先级越高 |
flag |
uint32_t |
需要配置掩码KUPL_SGRAPH_TASK_DESC_FIELD_FLAG后才能生效;静态图task的flag,可设置为KUPL_SGRAPH_TASK_FLAG_IMM,表示直接执行静态图任务,不需要调度 |
field_mask |
uint32_t |
掩码,用于指定结构体中哪些值有效,不设置掩码情况下仅sgraph参数生效,其他需要设置掩码。 具体可设置的掩码:
|
参数名 |
类型 |
描述 |
---|---|---|
func |
void (*kupl_taskloop_func_t)(kupl_nd_range_t *nd_range, void *args) |
taskloop 任务需要执行的具体函数 |
args |
void * |
func 函数需要传入的参数 |
range |
kupl_nd_range_t * |
taskloop 范围,详细使用方式见 kupl_parallel_for 章节 |
egroup |
kupl_egroup_h |
执行 taskloop 任务的 egroup,即能在哪个 egroup 中的 executor 执行器上执行 |
返回值
- 成功:返回KUPL_OK
- 失败:返回KUPL_ERROR
示例
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 30 31 32 33 34 35 36 37 38 | #include <stdio.h> #include "kupl.h" #include <assert.h> static inline void task_str(void *args) { printf("graph task test.\n"); } 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 = { .func = task_str, .args = NULL, .flag = KUPL_TASK_FLAG_IMM, .field_mask = KUPL_TASK_DESC_FIELD_FLAG, }; kupl_task_info_t info = { .type = KUPL_TASK_TYPE_SINGLE, .desc = &task_desc, }; int ret = kupl_graph_submit(graph, &info); assert(ret == KUPL_OK); kupl_graph_wait(graph); kupl_graph_destroy(graph); kupl_egroup_destroy(egroup); return 0; } |
运行结果如下。
graph task test.

上述示例演示了向graph图提交task的流程。上述kupl_graph_submit函数提交的task的函数为task_str,函数不需要参数,task设置了flag生效且flag值设置为KUPL_TASK_FLAG_IMM;不需要获取特定的task。