UDF APIs
This section describes the external APIs provided by the User-Defined Function (UDF) module. You can call these APIs to develop user-defined processing functions, and then execute the processing functions on the CPU through DataFlow graph construction.
You can view the header files of the corresponding APIs in ${INSTALL_DIR}/include/flow_func.
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.
API categories and corresponding header files
API Category |
Header File Path |
Description |
|---|---|---|
Class AttrValue |
attr_value.h |
Used to obtain the attribute value set by the user. |
Class AscendString |
ascend_string.h |
Encapsulation for the string type. |
Class MetaContext |
meta_context.h |
Used to process UDF context, such as allocating tensors and obtaining configured attributes. |
Class FlowMsg |
flow_msg.h |
Used to process the input and output operations of FlowFunc. |
Class Tensor |
flow_msg.h |
Used to perform tensor-related operations. |
Class MetaFlowFunc |
meta_flow_func.h |
Defined in meta_flow_func.h. You can inherit this class to compile user-defined single-func processing function. |
Class MetaMultiFunc |
meta_multi_func.h |
Defined in meta_multi_func.h. You can inherit this class to compile user-defined multi-func processing function. |
Class FlowFuncRegistrar |
meta_multi_func.h |
Defined in meta_multi_func.h and is an auxiliary template class for registering MetaMultiFunc. |
Class MetaParams |
meta_params.h |
Defined in meta_params.h and is used in the multi-func processing function of FlowFunc to obtain shared variable information. |
Class MetaRunContext |
meta_run_context.h |
Used to process the context of the multi-func processing function of FlowFunc, such as allocating a tensor, setting the output, and running FlowModel. |
Class OutOptions |
out_options.h |
Used to carry related options when a service releases data. |
Class BalanceConfig |
balance_config.h |
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. |
Class FlowBufferFactory |
flow_msg.h |
- |
Class FlowMsgQueue |
flow_msg_queue.h |
Used to serve as the input queue of FlowFunc in scenarios with streaming input (the input parameter of FlowFunc is a queue). The data object in the queue is Class FlowMsg. |
Registering Macros |
meta_flow_func.h meta_multi_func.h |
- |
UDF Log API |
flow_func_log.h |
flow_func_log.h provides log APIs to facilitate log recording during FlowFunc development. |
Error Code |
flow_func_defines.h |
- |
Class AttrValue
API |
Description |
|---|---|
Constructs and destructs an object of class AttrValue. |
|
Obtains the attribute value of the string type. |
|
Obtains the attribute value of the list string type. |
|
Obtains the attribute value of the int type. |
|
Obtains the attribute value of the list int type. |
|
Obtains the attribute value of the list list int type. |
|
Obtains the attribute value of the float type. |
|
Obtains the attribute value of the list float type. |
|
Obtains the attribute value of the bool type. |
|
Obtains the attribute value of the list bool type. |
|
Obtains the attribute value of the TensorDataType type. |
|
Obtains the attribute value of the list TensorDataType type. |
Class AscendString
API |
Description |
|---|---|
Constructs and destructs an object of class AscendString. |
|
Obtains the address of a string. |
|
Compares AscendString objects (sort key values by data structure of map). See the following examples. |
|
Obtains the length of a string. |
Class MetaContext
API |
Description |
|---|---|
Constructs and destructs an object of class MetaContext. |
|
Allocates a message of the tensor type based on the shape and data type. This function is called by Proc. |
|
Allocates the message of the MsgType type of empty data. This function is called by Proc. |
|
Sets the tensor of the output with a specified index. This function is called by Proc. |
|
Obtains the pointer to the AttrValue type based on the attribute name. This function is called by Init. |
|
Obtains the attribute value based on the attribute name. This function is called by Init. |
|
Runs a specified model synchronously. This function is called by Proc. |
|
Obtains the number of FlowFunc inputs. This function is called by Init. |
|
Obtains the number of FlowFunc outputs. This function is called by Init. |
|
Obtains the working path of FlowFunc. This function is called by Init. |
|
Obtains the ID of the running device. This function is called by Init. |
|
Obtains user data. This function is called by Proc. |
|
Allocates FlowMsg of the tensor type based on the shape, data type, and alignment size. The difference between this function and AllocTensorMsg is that AllocTensorMsg is 64-byte aligned by default. This function can be used to specify the alignment size, to facilitate performance optimization. |
|
A UDF proactively reports an exception, which can be captured by other UDFs in the same scope. |
|
UDF obtaining exception. If the exception capture function is enabled, try to capture the exception at the start position of the Proc function in the UDF. |
Class FlowMsg
API |
Description |
|---|---|
Constructs and destructs an object of class FlowMsg. |
|
Obtains the message type of FlowMsg. |
|
Obtains the tensor pointer in 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. |
|
Obtains the list of all tensor pointers in FlowMsg. |
|
Obtains the data pointer and data size of the RawData type. |
|
Sets the message type of FlowMsg. |
|
Sets the transaction ID in the FlowMsg message. |
Class Tensor
API |
Description |
|---|---|
Constructs and destructs an object of class Tensor. |
|
Obtains the shape of a tensor. |
|
Obtains the data type of a tensor. |
|
Obtains the data of a tensor. |
|
Obtains the size of data in a tensor. |
|
Obtains the number of elements in a tensor. |
|
Obtains the aligned data size of a tensor. |
|
Reshapes a tensor without changing the tensor content. |
Class MetaFlowFunc
API |
Description |
|---|---|
Compile the user-defined single-func processing function. The MetaMultiFunc destructor releases resources. |
|
Sets the context of FlowFunc. |
|
Defines the user-defined FlowFunc initialization function. |
|
Defines the user-defined FlowFunc processing function. |
|
Registers FlowFunc. You are advised to use MetaFlowFunc registration function macro to register FlowFunc. |
|
In the fault recovery scenario, the FlowFunc is quickly reset to the initial state. |
|
REGISTER_FLOW_FUNC_INNER(name, ctr, clazz) and REGISTER_FLOW_FUNC_IMPL(name, ctr, clazz) are implemented in MetaFlowFunc Registration Function Macro. You are advised not to call them directly. |
Class MetaMultiFunc
API |
Description |
|---|---|
Compile the user-defined multi-func processing function. The MetaMultiFunc destructor releases resources. |
|
Defines the user-defined FlowFunc initialization function. |
|
Defines the user-defined multi-FlowFunc processing function. |
|
Registers multiple FlowFunc. You are advised to use MetaMultiFunc Registration Function Macro to register FlowFunc. |
|
In the fault recovery scenario, quickly resets FlowFunc to the initial state. |
Class FlowFuncRegistrar
API |
Description |
|---|---|
Registers the multi-FlowFunc processing function by using MetaMultiFunc Registration Function Macro. |
|
Creates the multi-func processing object and processing function. This command is internally called by the function. You are advised not to use it directly. |
Class MetaParams
API |
Description |
|---|---|
Constructs and destructs an object of class MetaParams. |
|
Obtains the instance name of FlowFunc. |
|
Obtains the pointer to the AttrValue type based on the attribute name. This function is called by Init. |
|
Obtains the attribute value based on the attribute name. This function is called by Init. |
|
Obtains the number of FlowFunc inputs. This function is called by Init. |
|
Obtains the number of FlowFunc outputs. This function is called by Init. |
|
Obtains the working path of FlowFunc. This function is called by Init. |
|
Obtains the ID of the running device. |
Class MetaRunContext
API |
Description |
|---|---|
Constructs and destructs an object of class MetaRunContext. |
|
Allocates a message of the tensor type based on the shape and data type. This function is called by Proc. |
|
Sets the tensor of the output with a specified index. This function is called by Proc. |
|
Runs a specified model synchronously. This function is called by Proc. |
|
Allocates the message of the MsgType type of empty data. |
|
Obtains user data. This function is called by Proc. |
|
Sets the output of the specified index and options. This function is called by the func function. |
|
Sets the output of the specified index and options in batches. This function is called by the func function. |
|
Allocates FlowMsg of the tensor type based on the shape, data type, and alignment size. The difference between this function and AllocTensorMsg is that AllocTensorMsg is 64-byte aligned by default. This function can be used to specify the alignment size, to facilitate performance optimization. |
|
Allocates a continuous memory block based on the input dtype shapes array to carry the tensor array. |
|
A UDF proactively reports an exception, which can be captured by other UDFs in the same scope. |
|
UDF obtaining exception. If the exception capture function is enabled, try to capture the exception at the start position of the Proc function in the UDF. |
|
Allocates a continuous memory block based on the input size to carry data of the RawData type. |
|
Converts the input tensor to FlowMsg used to carry the tensor. |
Class OutOptions
API |
Description |
|---|---|
Constructs and destructs an object of class OutOptions. |
|
Obtains or creates BalanceConfig. |
|
Obtains BalanceConfig. |
Class BalanceConfig
API |
Description |
|---|---|
Constructs and destructs an object of class BalanceConfig. |
|
Sets balanced distribution affinity. |
|
Obtains affinity. |
|
Sets the weight of balanced distribution. |
|
Obtains the weight of balanced distribution. |
|
Sets the position of the output data in the weight matrix. |
|
Obtains the position of the output data in the weight matrix. |
Class FlowBufferFactory
API |
Description |
|---|---|
Allocates tensors based on the shape, data type, and alignment size. By default, the tensor is 64-byte aligned. You can specify the alignment size to optimize performance. |
Class FlowMsgQueue
API |
Description |
|---|---|
Constructs and destructs an object of class FlowMsgQueue. |
|
Sets balanced distribution affinity. |
|
Obtains the queue depth, that is, the maximum number of elements in a queue. |
|
Obtains the number of current elements in a queue. |
Registering Macros
API |
Description |
|---|---|
Registers the implementation class of MetaFlowFunc. |
|
Registers the implementation class of MetaMultiFunc. |
UDF Log APIs
API |
Description |
|---|---|
Constructs and destructs an object of class FlowFuncLogger. |
|
Obtains the log implementation class. |
|
Obtains log extension header information. |
|
Checks whether logs of the corresponding level and type are enabled. |
|
Records error-level logs. |
|
Records warn-level logs. |
|
Records info-level logs. |
|
Records debug-level logs. |
|
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. |