import numpy as np
import dataflow as df
options = {
"ge.exec.deviceId": "0",
"ge.exec.logicalDeviceClusterDeployMode": "SINGLE",
"ge.exec.logicalDeviceId": "[0:0]"
}
df.init(options)
'''
FlowData FlowData
| \ / |
| \ / |
| \ / |
| \ / |
| /\ |
| / \ |
| / \ |
FlowNode FlowNode
FuncProcessPoint FuncProcessPoint
\ /
timeBatch /
\ /
\ /
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)
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")
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)
time_batch = df.TimeBatch()
time_batch.time_window = 5
time_batch.batch_dim = 0
flow_node2.map_input(0, pp3, 0, [time_batch])
flow_node2.map_input(1, pp3, 1)
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])
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
dag.feed_data({data0: feed_data0, data1: feed_data1}, flow_info)
result = dag.fetch_data()
print("TEST-OUTPUT:", result)
df.finalize()