import dataflow as df
import numpy as np
options = {
"ge.exec.deviceId": "0",
"ge.exec.logicalDeviceClusterDeployMode": "SINGLE",
"ge.exec.logicalDeviceId": "[0:0]",
}
df.init(options)
r"""
FlowData FlowData
| \ / |
| \ / |
| \ / |
| \ / |
| /\ |
| / \ |
| / \ |
FlowNode FlowNode
FuncProcessPoint FuncProcessPoint
\ /
\ /
\ /
FlowNode
GraphProcessPoint
"""
data0 = df.FlowData()
data1 = df.FlowData()
pp0 = df.FuncProcessPoint(compile_config_path="config/add_func.json")
pp0.set_init_param("out_type", df.DT_INT32)
pp0.set_init_param("enableExceptionCatch", True)
flow_node0 = df.FlowNode(input_num=2, output_num=1)
flow_node0.add_process_point(pp0)
flow_node0.set_attr("_flow_attr", True)
flow_node0.set_attr("_flow_attr_depth", 108)
flow_node0.set_attr("_flow_attr_enqueue_policy", "FIFO")
pp1 = df.FuncProcessPoint(compile_config_path="config/invoke_func.json")
pp1.set_init_param("enableExceptionCatch", True)
pp2 = df.GraphProcessPoint(
df.Framework.TENSORFLOW,
"config/add.pb",
load_params={"input_data_names": "Placeholder,Placeholder_1"},
compile_config_path="config/add_graph.json",
)
pp1.add_invoked_closure("invoke_graph", pp2)
flow_node1 = df.FlowNode(input_num=2, output_num=1)
flow_node1.add_process_point(pp1)
pp3 = df.GraphProcessPoint(
df.Framework.TENSORFLOW,
"config/add.pb",
load_params={"input_data_names": "Placeholder,Placeholder_1"},
compile_config_path="config/add_graph.json",
)
flow_node2 = df.FlowNode(input_num=2, output_num=1)
flow_node2.add_process_point(pp3)
flow_node0_out = flow_node0(data0, data1)
flow_node1_out = flow_node1(data0, data1)
flow_node2_out = flow_node2(flow_node0_out, flow_node1_out)
dag = df.FlowGraph([flow_node2_out])
dag.set_inputs_align_attrs(100, 1000, False)
dag.set_exception_catch(True)
feed_data0 = np.ones([3], dtype=np.int32)
feed_data1 = np.array([1, 2, 3], dtype=np.int32)
flow_info = df.FlowInfo()
flow_info.start_time = 0
flow_info.end_time = 5
for i in range(10):
dag.feed_data({data0: feed_data0, data1: feed_data1}, flow_info)
for i in range(10):
result = dag.fetch_data()
print("TEST-OUTPUT:", result)
df.finalize()