我试图想出一种方法来定义在运行时定义的流图(比如TBB)。目前,我们使用TBB定义编译时节点和节点之间的边。这有点烦人,因为我们有些人想要添加处理步骤和修改处理链,而不需要重新编译整个应用程序,或者除了如何添加处理内核之外,还必须真正了解有关应用程序的任何信息。在一个理想的世界里,我会有某种使用dll的插件框架。我们已经有了软件架构,这样TBB中的每个节点都代表了一个处理步骤,所以如果您愿意重新编译的话,很容易添加内容。
作为第一步,我试图想出一种在YAML中定义TBB流图的方法,但它是一个巨大的兔子洞。在我从无到有地实现这一点之前,有人知道这样的事情是否存在吗?这将是一个有趣的项目,但没有必要重复工作。
发布于 2022-03-14 16:27:03
我不确定TBB配套库中是否存在这样的功能,但在运行时实现流图功能的一小部分肯定是可行的。
如果通过图形传输的数据具有定义良好的类型,也就是您的节点基本上是function_node<T, T>,那么事情是可以管理的。如果图形将数据从一种类型转换为另一种类型,那么更复杂的-one解决方案将是使用这些类型的变体,并在运行时处理可能不兼容的类型。这实际上取决于所需的灵活性水平。
通过以下方式:
$ cat nodes.txt
# type concurrency params...
multiply unlimited 2
affine serial 5 -3和
$ cat edges.txt
# src dst
0 1
1 2在索引0是源节点的地方,下面是如何实现它的脚手架:
using data_t = double;
using node_t = function_node<data_t , data_t >;
graph g;
std::vector<node_t> nodes;
auto node_factory = [&g](std::string type, std::string concurrency, std::string params) -> node_t {
// Implement a dynamic factory of nodes
};
// Add source node first
nodes.push_back(flow::input_node<data_t>(g,
[&]( oneapi::tbb::flow_control &fc ) -> data_t { /*...*/ });
// Parse the node description file and populate the node vector using the factory
for (auto&& n : nodes)
nodes.push_back(node_factory(n.type, n.concurrency, n.params));
// Parse the edge description file and call make_edge accordingly
for (auto&& e : edges)
flow::make_edge(nodes[e.src], nodes[e.dst]);
// Run the graph
nodes[0].activate();
g.wait_for_all();https://stackoverflow.com/questions/70491117
复制相似问题