DataFlow APIs

You can view the header file of each API in the ${INSTALL_DIR}/include/flow_graph directory.

Replace ${INSTALL_DIR} with the CANN component directory. For example, if the installation is performed by the root user, the default file storage path is /usr/local/Ascend/cann.

Note that the char_t type in the header file is the alias for the char type.

API Category

Header File Path

Description

Matching Library File

FlowOperator class

flow_graph.h

The FlowOperator class is the node base class of DataFlow graphs and is inherited from the Operator class of the GE. It cannot be independently constructed and used externally.

N/A

FlowData class

flow_graph.h

This class is the data node of DataFlow graphs and is inherited from the FlowOperator class. Each FlowData corresponds to one input.

libflow_graph.so

FlowNode class

flow_graph.h

This class is the compute node of DataFlow graphs and is inherited from the FlowOperator class.

libflow_graph.so

FlowGraph class

flow_graph.h

This class indicates a DataFlow graph, which consists of the input node FlowData and compute node FlowNode.

libflow_graph.so

ProcessPoint class

process_point.h

The ProcessPoint class is a virtual base class and cannot be instantiated as objects.

N/A

FunctionPp class

process_point.h

This class is the compute ProcessPoint of functions and is inherited from Class ProcessPoint.

libflow_graph.so

GraphPp class

process_point.h

This class is the compute ProcessPoint of graphs and is inherited from Class ProcessPoint.

libflow_graph.so

DataFlowInputAttr structure

flow_attr.h

This structure defines the timeBatch and countBatch functions to implement the batch capabilities of the UDF.

libflow_graph.so

DataFlow Graph Construction APIs

Table 1 DataFlow graph construction APIs

API

Overview

Class FlowOperator

The FlowOperator class is the node base class of DataFlow graphs and is inherited from the Operator class of the GE.

FlowData Constructor and Destructor

Constructs and destructs an object of class FlowData. The constructor returns a FlowData node.

FlowNode Constructor and Destructor

Constructs and destructs an object of class FlowNode. The constructor returns a FlowNode node.

SetInput

Sets the output ranked src_index of src_op as the input ranked dst_index of FlowNode, and returns a FlowNode node with the input set.

AddPp

Adds a mapping ProcessPoint to a FlowNode node. Currently, only one ProcessPoint can be added to a FlowNode node. After a ProcessPoint is added, the input and output of the FlowNode node are mapped to those of the ProcessPoint in sequence by default.

MapInput

Maps inputs to FlowNode, indicating that the node_input_index input of FlowNode is sent to the pp_input_index input of ProcessPoint, all attributes in attrs are set for the input of ProcessPoint, and the mapped FlowNode is returned. This function is optional. If it is not called, the inputs of FlowNode and ProcessPoint are mapped in sequence by default.

MapOutput

Maps the output ranked pp_output_index of ProcessPoint to the output ranked node_output_index of FlowNode, and returns FlowNode with the output mapped.

SetBalanceScatter

Sets the balance scatter attribute. The UDF with the balance scatter attribute can use balance options to set the load balancing output.

SetBalanceGather

Sets the balance gather attribute. The UDF with the balance gather attribute can use balance options to set the load balancing and affinity output.

FlowGraph Constructor and Destructor

Constructs and destructs an object of class FlowGraph. The constructor returns an empty FlowGraph graph.

SetInputs

Sets the input of FlowGraph. An empty FlowGraph will be built based on node output connections and then returned.

SetOutputs

Sets the output node of the FlowGraph and returns the graph.

SetOutputs (index)

Sets the association between the FlowNode and FlowNode output index in the FlowGraph and returns the graph. It is usually used to set some output of FlowNodes. For example, FlowNode1 has two outputs, but only one output of FlowNode1 is required when FlowNode2 is used as the input. In this case, you can set an output index of FlowNode1.

SetContainsNMappingNode

Sets whether FlowGraph contains an n_mapping node.

SetInputsAlignAttrs

Sets the attribute of input alignment in FlowGraph.

const ge::Graph &ToGeGraph() const

Converts FlowGraph into a GE graph.

SetGraphPpBuilderAsync

Sets whether the builder of GraphPp in FlowGraph is executed asynchronously.

SetExceptionCatch

Sets whether to enable the user exception capture function.

ProcessPoint Destructor

Destructs an object of class ProcessPoint.

GetProcessPointType

Obtains the type of ProcessPoint.

GetProcessPointName

Obtains the name of ProcessPoint.

GetCompileConfig

Obtains the compilation configuration file of ProcessPoint.

Serialize

Serializes ProcessPoint. The function of this API is implemented by the subclass of ProcessPoint.

FunctionPp Constructor and Destructor

Constructs and destructs an object of class FunctionPp. The constructor returns an object of class FunctionPp.

SetCompileConfig

Sets the name and path of the JSON configuration file of FunctionPp. The configuration file is used to map FunctionPp to UDF.

AddInvokedClosure (Adding GraphPp)

Adds GraphPp called by FunctionPp, and returns FunctionPp with GraphPp added.

AddInvokedClosure (Adding the ProcessPoint Subclass)

Adds GraphPp called by FunctionPp, and returns FunctionPp with GraphPp added.

AddInvokedClosure (Adding FlowGraphPp)

Adds FlowGraphPp called by FunctionPp, and returns FunctionPp with FlowGraphPp added.

SetInitParam

Sets the initialization parameter of FunctionPp, and returns FunctionPp with the initialization parameter set.

Serialize

Serializes FunctionPp.

GetInvokedClosures

Obtains GraphPp called by FunctionPp.

GraphPp Constructor and Destructor

Constructs and destructs an object of class GraphPp. The constructor returns an object of class GraphPp.

SetCompileConfig

Sets the path and name of the JSON configuration file of GraphPp. The configuration file is used to describe and compile AscendGraph.

Serialize

Serializes GraphPp.

GetGraphBuilder

Obtains the graph creation function in GraphPp.

FlowGraphPp Constructor and Destructor

Constructs and destructs an object of class FlowGraphPp. The constructor returns an object of class FlowGraphPp.

Serialize

Serializes FlowGraphPp.

GetGraphBuilder

Obtains the graph creation function in FlowGraphPp.

TimeBatch

The TimeBatch function is based on the UDF.

A model normally processes a piece of data each time. When it needs to process many pieces of data at a time, these pieces of data need to be combined into a batch. The basic mode is to combine the N pieces of data and add N before the shape. In some scenarios, data of one or more time segments needs to be combined into a batch based on a specific dimension, which can be implemented using the TimeBatch function.

CountBatch

CountBatch is used to combine multiple data records into batches based on batchSize, by using UDFs as compute ProcessPoints.

DataFlow Execution APIs

Table 2 DataFlow Execution APIs

API

Overview

FeedDataFlowGraph (Feeding All Inputs)

Inputs all data to a graph.

FeedDataFlowGraph (Feeding Inputs by Index)

Inputs data to a graph by index.

FeedDataFlowGraph (Feeding All FlowMsgs)

Inputs data to a graph.

FeedDataFlowGraph (Feeding FlowMsgs by Index)

Inputs data to a graph by index.

FeedRawData

Inputs raw data to a graph.

FetchDataFlowGraph (Fetching All Output Data)

Fetches output data of a graph.

FetchDataFlowGraph (Fetching Output Data by Index)

Fetches output data of a graph by index.

FetchDataFlowGraph (Fetching All Output FlowMsgs)

Fetches output data of a graph.

FetchDataFlowGraph (Fetching Output FlowMsgs by Index)

Fetches output data of a graph by index.

DataFlowInfo Constructor and Destructor

Constructs and destructs an object of class DataFlowInfo.

SetUserData

Sets user information.

GetUserData

Obtains user information.

SetStartTime

Sets the start timestamp of data.

GetStartTime

Obtains the start timestamp of data.

SetEndTime

Sets the end timestamp of data.

GetEndTime

Obtains the end timestamp of data.

SetFlowFlags

Sets flags in data.

GetFlowFlags

Obtains flags in data.

SetTransactionId

Sets the transaction ID used for DataFlow data transmission.

GetTransactionId

Obtains the transaction ID used for DataFlow data transmission.

FlowMsg Constructor and Destructor

Constructs and destructs an object of class FlowMsg.

GetMsgType

Obtains the message type of FlowMsg.

SetMsgType

Sets the message type of FlowMsg.

GetTensor

Obtains the tensor pointer in FlowMsg.

GetRetCode

Obtains the error code in the input FlowMsg.

SetRetCode

Sets the error code in FlowMsg.

SetStartTime

Sets the start timestamp in the FlowMsg message header.

GetStartTime

Obtains the start timestamp in FlowMsg.

SetEndTime

Sets the end timestamp in the FlowMsg message header.

GetEndTime

Obtains the end timestamp in FlowMsg.

SetFlowFlags

Sets flags in the FlowMsg message header.

GetFlowFlags

Obtains flags in the FlowMsg message header.

GetTransactionId

Obtains the transaction ID in FlowMsg.

SetTransactionId

Sets the transaction ID in FlowMsg.

SetUserData

Sets user information.

GetUserData

Obtains user information.

GetRawData

Obtains the pointer to and size of data of the RawData type.

AllocTensor

Allocates tensors based on the shape, data type, and alignment size.

AllocTensorMsg

Allocates FlowMsg based on the shape, data type, and alignment size.

AllocRawDataMsg

Allocates a continuous memory block based on the input size to carry the raw data.

AllocEmptyDataMsg

Allocates a message of the MsgType type that carries empty data.

ToFlowMsg (Tensor)

Converts the input tensor to FlowMsg that carries tensors.

ToFlowMsg (Raw Data)

Converts the input raw data to FlowMsg that carries the raw data.