Configuring Data Transmission
Based on service applications, data transmission defined by the Matrix framework is classified into the following types (The used APIs are similar and the transmitted objects are shared pointers, but the API usage varies according to scenarios):
- Input API for transmitting data outside a graph to engines. For details, see "Graph::SendData" in the Matrix API Reference.
- Output API for transmitting data of engines in a graph to the outside of the graph. For details, see "Graph::SetDataRecvFunctor" and "Engine::SetDataRecvFunctor" in the Matrix API Reference.
- Data is transmitted between engines in a graph. For details, see "Engine::SendData" in the Matrix API Reference.
Data Transmission Between Engines
The Matrix framework divides service software into the software on the host side (x86/Arm server) and the software on the device side (Ascend 310 chip). Therefore, data transmission between engines is classified into cross-side transmission and intra-side transmission.
- Cross-side transmission: The data to be transmitted needs to be serialized into binary data. After the data is transmitted by using hardware such as PCIe or DMA, the data is deserialized into valid data. Therefore, you need to customize serialization and deserialization functions for custom data structures. The Matrix framework allows you to define serialization and deserialization functions using either a common or a high-speed interface. The common interface is applicable to data transmission at a rate below 256 kbit/s, whereas the high-speed interface is applicable to data transmission at a rate of 256 kbit/s or higher. The high-speed interface operates at a speed similar to that of a common interface when transmitting small memory blocks. For details, see "Data Type Serialization and Deserialization (C++ Language)" in the Matrix API Reference.
- Intra-side transmission: The transferred data is the address of the shared pointer and is not copied. As the Process() function of engines is instantiated into threads, intra-side transmission implements data transmission in memory-sharing mode. Ensure that there is no unauthorized access. The Matrix framework recommends that the local engine does not modify the shared pointer after transmitting it to the next engine.
- After the serialization and deserialization functions are implemented for cross-side transmission, the API used in the service application is the same as that used in intra-side transmission.
HIAI_StatusT Engine::SendData(uint32_t portId, const std::string& messageName, const shared_ptr<void>& dataPtr, uint32_t timeOut = TIME_OUT_VALUE);
Input API for Transmitting Data Outside a Graph to Engines
- The service flow composed of engines is driven by data. This API allows data outside a graph to be sent to engines in the graph.
- The following APIs can be called to implement cross-side and intra-side transmission, with similar requirements to those for data transmission between engines. For details, see "Graph::SendData" in the Matrix API Reference.
HIAI_StatusT Graph::SendData(const EnginePortID& targetPortConfig, const std::string& messageName, const std::shared_ptr<void>& dataPtr,const uint32_t timeOut = 500)
Output API for Transmitting Data of Engines in a Graph to the Outside of the Graph
- The Matrix framework transmits the data of engines in a graph to the outside of the graph using either of the following callback functions:
- Callback on the output API for an engine (node of a service flow). For details, see "Graph::SetDataRecvFunctor" in the Matrix API Reference.
- For details about the callback on the output API in other scenarios, see "Engine::SetDataRecvFunctor" in the Matrix API Reference.
- The framework provides the template class DataRecvInterface of callback functions.
- The framework requires that the callback function and the output engine run on the same side. That is, only intra-side data transmission is supported.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot