---
title: kpccl_graph_add_subgraph_task
description: "向kpccl图中添加子图(静态图)task，即提交执行静态图任务。"
url: https://www.hikunpeng.com/document/detail/zh/hpchistory/hpckit/develop2400/KunoengHPCKit_developer_043.html
sourcePath: /source/zh/hpchistory/hpckit/develop2400/KunoengHPCKit_developer_043.html
indexId: 0af9da27c71a4654e93869bea2650677b4a9787ece2fa7bf6535b8974fb696a973
---
# kpccl_graph_add_subgraph_task

向kpccl图中添加子图(静态图)task，即提交执行静态图任务。

#### 接口定义

int kpccl_graph_add_subgraph_task(kpccl_graph_h graph, kpccl_subgraph_task_desc_t *task_desc, kpccl_task_h task);


#### 参数


**表1 参数定义**

| 参数名 | 类型 | 描述 | 输入/输出 |
| --- | --- | --- | --- |
| graph | kpccl\_graph\_h | 需要向其中添加静态图task的图 | 输入/输出 |
| task\_desc | kpccl\_subgraph\_task\_desc\_t | 需要添加的静态图task的描述，具体见下表 | 输入 |
| task | kpccl\_task\_h | 需要被赋值的task任务对象；当不需要获取特定task的状态时，可以设置为nullptr | 输入/输出 |


**表2 kpccl_subgraph_task_desc_t的数据结构**

| 参数名 | 类型 | 描述 |
| --- | --- | --- |
| field\_mask | uint32\_t | 掩码，用于指定结构体中哪些值有效，不设置掩码情况下仅sgraph参数生效，其他需要设置掩码。 具体可设置的掩码： KPCCL\_SUBGRAPH\_TASK\_DESC\_FIELD\_PRIORITY：priority生效 KPCCL\_SUBGRAPH\_TASK\_DESC\_FIELD\_NAME：name生效 KPCCL\_SUBGRAPH\_TASK\_DESC\_FIELD\_FLAG：flag生效 |
| sgraph | kpccl\_static\_graph\_h | 需要提交的静态图 |
| priority | int | 需要配置掩码KPCCL\_SUBGRAPH\_TASK\_DESC\_FIELD\_PRIORITY后才能生效；静态图task的优先级，数值越大，优先级越高 |
| name | const char \* | 需要配置掩码KPCCL\_SUBGRAPH\_TASK\_DESC\_FIELD\_NAME后才能生效；静态图task的名字 |
| flag | uint32\_t | 需要配置掩码KPCCL\_SUBGRAPH\_TASK\_DESC\_FIELD\_FLAG后才能生效；静态图task的flag，可设置为KPCCL\_SUBGRAPH\_TASK\_FLAG\_IMM，表示直接执行静态图任务，不需要调度 |


#### 返回值

- 成功：返回KPCCL_OK
- 失败：返回KPCCL_ERROR


#### 示例

```
#include <stdio.h>
#include "kpccl.h"
static inline void task_str(void *args)
{
printf("static graph task test.\n");
}
int main()
{
kpccl_graph_h graph = kpccl_graph_create(nullptr);
kpccl_static_graph_h sgraph = kpccl_static_graph_create();
kpccl_gnode_desc_t node_desc = {
.func = task_str,
.args = nullptr,
};
kpccl_gnode_h gnode = kpccl_static_graph_add_norm_gnode(sgraph, &node_desc);
kpccl_subgraph_task_desc_t subgraph_task_desc = {
.field_mask = KPCCL_SUBGRAPH_TASK_DESC_FIELD_FLAG,
.sgraph = sgraph,
.flag = KPCCL_SUBGRAPH_TASK_FLAG_IMM,
};
kpccl_graph_add_subgraph_task
(graph, &subgraph_task_desc, nullptr);
kpccl_graph_synchronize(graph);
kpccl_graph_destroy(graph);
kpccl_static_graph_destroy(sgraph);
return 0;
}
```

运行结果如下。

```
static graph task test.
```

上述示例演示了向graph图提交静态图task的流程。上述kpccl_graph_add_subgraph_task函数提交的静态图task的静态图为sgraph，该静态图task设置了flag生效且flag值设置为KPCCL_SUBGRAPH_TASK_FLAG_IMM；不需要获取特定的task。
