UDF API List
This section describes the external APIs provided by the UDF module. You can call these APIs to develop custom processing functions, and then execute such functions on the CPU through DataFlow graph construction.
You can view the API implementation in python/site-packages/dataflow/flow_func/flow_func.py in CANN component directory. The APIs are as follows.
Class FlowMsg
This class is used to process the input and output operations of FlowFunc.
API |
Description |
|---|---|
Constructs an object of class FlowMsg. |
|
Obtains the message type of FlowMsg. |
|
Obtains the tensor object of FlowMsg. |
|
Sets the error code in the FlowMsg message. |
|
Obtains the error code in the input FlowMsg message. |
|
Sets the start timestamp in the FlowMsg message header. |
|
Obtains the start timestamp in the FlowMsg message. |
|
Sets the end timestamp in the FlowMsg message header. |
|
Obtains the end timestamp in the FlowMsg message. |
|
Sets flags in the FlowMsg message header. |
|
Obtains flags in the FlowMsg message header. |
|
Sets route labels. |
|
Obtains the transaction ID in the FlowMsg message. The transaction ID starts from 1, and is incremented by 1 each time a batch of data is fed. This function can be used to identify the ID of the data batch. |
|
Sets the message type of FlowMsg. |
|
Obtains data of the rawdata type. |
|
Sets the transaction ID used for DataFlow data transmission. |
Tensor Class
This class is used to perform tensor-related operations. The obtained tensor is dataflow.Tensor.
API |
Description |
|---|---|
Constructs an object of class Tensor. |
|
Obtains the shape of a tensor. |
|
Obtains the data type of a tensor. |
|
Obtains the data size of a tensor. |
|
Obtains the number of elements in a tensor. |
|
Reshapes a tensor without changing the tensor content. |
Class MetaParams
This class is used to obtain shared variable information.
API |
Description |
|---|---|
Constructs an object of class PyMetaParams. |
|
Obtains the instance name of FlowFunc. |
|
Obtains the attribute value of the int type with the specified name. |
|
Obtains the attribute value of the bool array with the specified name. |
|
Obtains the attribute value of the int array with the specified name. |
|
Obtains the attribute value of the 2D array of the int type with the specified name. |
|
Obtains the attribute value of the bool type with the specified name. |
|
Obtains the attribute value of the float array with the specified name. |
|
Obtains the attribute value of the numpy.dtype type with the specified name. |
|
Obtains the attribute value of the array of the numpy.dtype types with the specified name. |
|
Obtains the attribute value of the string type with the specified name. |
|
Obtains the attribute value of the string array with the specified name. |
|
Obtains the attribute value of the float type with the specified name. |
|
Obtains the number of FlowFunc inputs. |
|
Obtains the number of FlowFunc outputs. |
|
Obtains the working path of FlowFunc. |
|
Obtains the ID of the running device. |
Class MetaRunContext
This class is used to process the context information of the processing function of FlowFunc, such as allocating a tensor, setting the output, and running FlowModel.
API |
Description |
|---|---|
Constructs an object of class MetaRunContext. |
|
Allocates FlowMsg of the tensor type based on the shape, data type, and alignment size. |
|
Sets the tensor of the output with a specified index. |
|
Sets the tensors of the outputs with specified indexes in batches. |
|
Runs a specified model synchronously. |
|
Allocates a message of the MsgType type that carries empty data. |
|
Obtains the user-defined data. |
|
The UDF proactively reports an exception. |
|
The UDF obtains the exception reported by other UDF nodes. |
|
Allocates a continuous memory based on the input size to carry the FlowMsg of the raw data type. |
|
Converts a dataflow tensor into a FlowMsg. |
Class AffinityPolicy
API |
Description |
|---|---|
Defines the affinity policy enumeration. |
Class BalanceConfig
When balanced distribution is required, you need to configure the output data identifier and weight matrix. The scheduling module can implement balanced distribution among multiple instances based on the configuration.
API |
Description |
|---|---|
Constructs an object of class BalanceConfig. |
|
Sets the position of the output data in the weight matrix. |
|
Obtains inner configuration objects. This API is called by set_output or set_multi_outputs. |
Class FlowMsgQueue
This class serves as the input queue for FlowFunc in streaming input scenarios (the input parameter of FlowFunc is a queue). It dequeues FlowMsg entries, converts each to its corresponding data type based on MsgType, and returns the converted value to the caller.
API |
Description |
|---|---|
Constructs and destructs an object of class FlowMsgQueue. |
|
Obtains elements in a queue. |
|
Obtains elements in a queue without waiting. The function is the same as get(block=False). |
|
Checks whether the queue is full. |
|
Checks whether the queue is empty. |
|
Obtains the number of current elements in a queue. |
UDF Log APIs
Logging APIs are exposed for Python UDFs. You need to import the flow_func module to use these APIs. Use the defined logger object within this module to call its encapsulated logging APIs of different severity levels.
API |
Description |
|---|---|
Constructs an object of class FlowFuncLogger. |
|
Obtains log extension header information. |
|
Checks whether logs of the corresponding level and type are enabled. |
|
Defines the error-level log macro of run logs. |
|
Defines the info-level log macro of run logs. |
|
Defines the error-level log macro of debug logs. |
|
Defines the warn-level log macro of debug logs. |
|
Defines the info-level log macro of debug logs. |
|
Defines the debug-level log macro of debug logs. |