Help Center/
Atlas 300 Application (Model 3000)/
Matrix API Reference/
Process Orchestration APIs/
API Usage Example/
Example of Using the C APIs
Updated on 2022-03-13 GMT+08:00
Example of Using the C APIs
/** * @file graph_c_api_example.cpp * * Copyright(C), 2017 - 2017, Huawei Tech. Co., Ltd. ALL RIGHTS RESERVED. * * @Source Files for HIAI Graph Orchestration * * @version 1.0 * */ #include <unistd.h> #include <stdlib.h> #include <string.h> #include "hiaiengine/c_api.h" #include "user_def_data_type.h" /************************************************************************** * Normally the mandatory steps to set up the whole HIAI graph include: * 1) Call the HIAI_Init() API to perform global system initialization; * 2) Call HIAI_CreateGraph to create and start a graph. * 3) Set profile config if necessary. * 4) Call HIAI_DestoryGraph to destroy the graph finally. * ***************************************************************************/ // Just define variables which are used in only this example // and are not required in real user case. #define MATRIX_USER_SPECIFY_ENGINE_PRIORITY (10) static uint32_t g_graph_id = 100; static uint32_t src_engine_id = 1000; // Defined in graph.prototxt static uint32_t dest_engine_id = 1002; // Defined in graph.prototxt static const char graph_config_proto_file[] = "llt/hiaiengine/st/examples/config/graph.prototxt"; static const char graph_config_len = sizeof(graph_config_proto_file); // Define End // Receive user-defined data (recv_data is automatically released by the framework). HIAI_StatusT UserDefDataRecvCallBack(void* recv_data) { // Process the received data. return HIAI_OK; } /************************************************************************* * HIAIEngine Example * Graph: * SrcEngine<-->Engine<-->DestEngine * *************************************************************************/ HIAI_StatusT HIAI_InitAndStartGraph() { // Step1: Global System Initialization before using Matrix HIAI_StatusT status = HIAI_Init(0); // Step2: Create and Start the Graph status = HIAI_CreateGraph(graph_config_proto_file, graph_config_len); if (status != HIAI_OK) { return status; } // Step3: Set the callback function to receive data. HIAI_PortID_t engine_id; engine_id.graph_id = g_graph_id; engine_id.engine_id = dest_engine_id; engine_id.port_id = 0; HIAI_SetDataRecvFunctor(engine_id, UserDefDataRecvCallBack); return HIAI_OK; } // User Application Main Example int main() { HIAI_StatusT ret = HIAI_OK; // Creation process ret = HIAI_InitAndStartGraph(); if (HIAI_OK != ret) { return -1; } // Read data and inject data into the process. HIAI_PortID_t engine_id; engine_id.graph_id = g_graph_id; engine_id.engine_id = src_engine_id; engine_id.port_id = 0; int is_end_of_data = 0; while (!is_end_of_data) { UserDefDataTypeT* user_def_msg = (UserDefDataTypeT*)malloc(sizeof(UserDefDataTypeT)); // Read data and pad UserDefDataType. For details about the data type registration, see the corresponding section in this document. const char * message_name = "UserDefDataType"; size_t msg_len = strlen(message_name); if (HIAI_OK != HIAI_C_SendData(engine_id, message_name, msg_len, user_def_msg)) { // When the queue is full, a message is returned indicating that sending data fails. The service logic determines whether to resend or discard the data. break; } free(user_def_msg); user_def_msg = nullptr; } // After the processing is complete, delete the entire graph. HIAI_DestroyGraph(g_graph_id); return 0; }
Parent topic: API Usage 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