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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
void SimpleDataTest()
{
//创建任务
std::shared_ptr<Task> t1, t2, t3;
GraphManager::Instance().CreateGraph("test");
GraphManager::Instance().CreateTask<TestTask>("test", "t1", t1);
GraphManager::Instance().CreateTask<TestTask>("test", "t2", t2);
GraphManager::Instance().CreateTask<TestTask>("test", "t3", t3);
//创建数据
std::vector<std::any> data = {1, 1.0f};
GraphManager::Instance().CreateDataSource("test", "test_data", data);
TaskDataConnect t1_data_source;
t1_data_source.back_task_name = "t1";
t1_data_source.front_info.emplace_back(std::make_pair("test_data", 0));
t1_data_source.front_info.emplace_back(std::make_pair("test_data", 1));
GraphManager::Instance().AddEdge("test", t1_data_source);
//构建链接关系,构建运行的graph
TaskDataConnect t1_t2_connect;
t1_t2_connect.back_task_name = "t2";
t1_t2_connect.front_info.emplace_back(std::make_pair("t1", 0));
t1_t2_connect.front_info.emplace_back(std::make_pair("t1", 1));
GraphManager::Instance().AddEdge("test", t1_t2_connect);
TaskDataConnect t3_connect;
t3_connect.back_task_name = "t3";
t3_connect.front_info.emplace_back(std::make_pair("t1", 0));
t3_connect.front_info.emplace_back(std::make_pair("t2", 1));
GraphManager::Instance().AddEdge("test", t3_connect);
//执行前更新每个节点的参数
t1->UpdateParams("int_param", 1);
t2->UpdateParams("int_param", 1);
t3->UpdateParams("int_param", 1);
t1->UpdateParams("float_param", 1.0f);
t2->UpdateParams("float_param", 1.0f);
t3->UpdateParams("float_param", 1.0f);
//执行graph
GraphManager::Instance().RunAllGraph();
//获取执行的结果
auto output3 = t3->GetOutputData();
for(auto [name, value] : output3)
{
if(typeid(int).name() == value.type().name())
{
std::cout << "name: "<<t3->GetName() + name << " value:" << std::any_cast<int>(value) << std::endl;
}else if(typeid(float).name() == value.type().name())
{
std::cout << "name: " <<t3->GetName() + name << " value:" << std::any_cast<float>(value) << std::endl;
}
}
}
|