Help Center/
Atlas 300 Application (Model 3000)/
Matrix API Reference/
Appendix/
Example/
Example of Data Transmission Based on Optimized Performance
Updated on 2022-03-13 GMT+08:00
Example of Data Transmission Based on Optimized Performance
(1) When the performance optimization solution is used to send data, the data must be manually serialized and deserialized. // Note: The serialization function is used at the transmit end, while the deserialization function is used at the receive end. Therefore, the registration function must be registered at both the receive and transmit ends. Data structure typedef struct { uint32_t frameId; uint8_t bufferId; uint8_t* image_data; uint8_t image_size; }TEST_STR; // Serialize the TEST_STR structure. This function needs to be registered only by calling the registration function. The parameters are described as follows: // Input: inputPtr, pointer to the TEST_STR structure // Output: ctrlStr, control information address imageData, data information pointer imageLen, data information size void GetTestStrSearPtr(void* inputPtr, std::string& ctrlStr, uint8_t*& imageData, uint32_t& imageLen) { // Obtain the structure buffer. TEST_STR* test_str = (TEST_STR*)inputPtr; ctrlStr = std::string((char*)inputPtr, sizeof(TEST_STR)); // Obtain data information and assign a value to the data pointer of the structure. imageData = (uint8_t*)test_str->image_data; imageLen = test_str->image_size; } // Deserialization structure. The returned data is the structure buffer and data block buffer. // Input: ctrlPtr, control information address ctrlLen, control information size imageData, data information pointer imageLen, data information size // Output: std::shared_ptr<void>, smart pointer to the structure std::shared_ptr<void> GetTestStrDearPtr(const char* ctrlPtr, const uint32_t& ctrlLen,const uint8_t* imageData, const uint32_t& imageLen) { // Obtain the structure. TEST_STR* test_str = (TEST_STR*)ctrlPtr; // Obtain the transferred large memory data. // Note: For large memory data, assign a value to the smart pointer and register the deleter. If the smart pointer is not used or the deleter is not registered, manually invoke hiai::Graph::ReleaseDataBuffer(void* ptr) when releasing the memory. std::shared_ptr<TEST_STR<uint8_t>> shared_data = std::make_shared<TEST_STR<uint8_t>>(); shared_data->frameId = test_str->frame_ID; shared_data->bufferId= test_str->bufferId; shared_data->image_size = imageLen; shared_data->image_data.reset(imageData, hiai::Graph::ReleaseDataBuffer); // The smart pointer is returned to the engine on the device. return std::static_pointer_cast<void>(shared_data); } // Register the serialiation and deserialization functions. HIAI_REGISTER_SERIALIZE_FUNC("TEST_STR", TEST_STR, GetTestStrSearPtr, GetTestStrDearPtr); (2) When sending data, you must use a registered data type together with HIAI_DMalloc which is used to allocate data memory to improve the performance. Note: During data transfer from the host to the device, you are advised to use HIAI_DMalloc, which can greatly improve the transmission efficiency. The HIAI_DMalloc interface supports the size of 0 to (256 MB – 96 bytes). If the data exceeds this range, use the malloc interface to allocate memory. // Use the Dmalloc interface to allocate the data memory. 10000 indicates the delay (in milliseconds), that is, if the memory is insufficient, wait for 10000 milliseconds. HIAI_StatusT get_ret = HIAIMemory::HIAI_DMalloc(width*align_height*3/2,(void*&)align_buffer, 10000); // Send data. After this interface is called, the HIAI_Dfree interface does not need to be called. The dealy 10000 indicates the delay. graph->SendData(engine_id_0, "TEST_STR", std::static_pointer_cast<void>(align_buffer), 10000);
Parent topic: Example
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.
The system is busy. Please try again later.
For any further questions, feel free to contact us through the chatbot.
Chatbot