Help Center/
Atlas 300 Application (Model 3000)/
Matrix API Reference/
Engine Implementation APIs (C++ Language)/
Calling Example
Updated on 2022-03-13 GMT+08:00
Calling Example
/** * @file multi_input_output_engine_example.h * * Copyright(c)<2018>, <Huawei Technologies Co.,Ltd> * * @version 1.0 * * @date 2018-4-25 */ #ifndef MULTI_INPUT_OUTPUT_ENGINE_EXAMPLE_H_ #define MULTI_INPUT_OUTPUT_ENGINE_EXAMPLE_H_ #include "hiaiengine/engine.h" #include "hiaiengine/data_type.h" #include "hiaiengine/multitype_queue.h" #define MULTI_INPUT_OUTPUT_ENGINE_EXAMPLE_INPUT_SIZE 3 #define MULTI_INPUT_OUTPUT_ENGINE_EXAMPLE_OUTPUT_SIZE 2 namespace hiai { // Define New Engine class HIAIMultiEngineExample : public Engine { public: HIAIMultiEngineExample() : input_que_(MULTI_INPUT_OUTPUT_ENGINE_EXAMPLE_INPUT_SIZE) {} // Overload the Init of the parent engine. HIAI_StatusT Init(const AIConfig& config, const std::vector<AIModelDescription>& model_desc) { return HIAI_OK; } /** * @ingroup hiaiengine * @brief HIAI_DEFINE_PROCESS * @[in]: Defines an input port and an output port. */ HIAI_DEFINE_PROCESS(MULTI_INPUT_OUTPUT_ENGINE_EXAMPLE_INPUT_SIZE, MULTI_INPUT_OUTPUT_ENGINE_EXAMPLE_OUTPUT_SIZE) private: // Implement a member variable in a private manner to cache the input queue. hiai::MultiTypeQueue input_que_; }; } #endif //MULTI_INPUT_OUTPUT_ENGINE_EXAMPLE_H_
/** * @file multi_input_output_engine_example.h * * Copyright(c)<2018>, <Huawei Technologies Co.,Ltd> * * @version 1.0 * * @date 2018-4-25 */ #include "multi_input_output_engine_example.h" #include "use_def_data_type.h" #include "use_def_errorcode.h" namespace hiai { /** * @ingroup hiaiengine * @brief HIAI_DEFINE_PROCESS: implements the input and output processing flow of multiple ports. * @[in]: Defines an input port and an output port, * The engine is registered and named "HIAIMultiEngineExample". */ HIAI_IMPL_ENGINE_PROCESS("HIAIMultiEngineExample", HIAIMultiEngineExample, MULTI_INPUT_OUTPUT_ENGINE_EXAMPLE_INPUT_SIZE) { // This Engine has three input args and two output // Each port may receive data at different time points. Therefore, some input ports may be empty. input_que_.PushData(0,arg0); input_que_.PushData(1,arg1); input_que_.PushData(2,arg2); std::shared_ptr<void> input_arg1; std::shared_ptr<void> input_arg2; std::shared_ptr<void> input_arg3; // The subsequent processing is performed only when all the three ports have input data. Method 1: if (!input_que_.PopAllData(input_arg1, input_arg2, input_arg3)) { HIAI_ENGINE_LOG(this, HIAI_INVALID_INPUT_MSG, "fail to process"); return HIAI_INVALID_INPUT_MSG; } // The subsequent processing is performed only when all the three ports have input data. Method 2: /* if (!(input_que_.FrontData(0, input_arg1) && input_que_.FrontData(1, input_arg2) && input_que_.FrontData(2, input_arg3))) { HIAI_ENGINE_LOG(this, HIAI_INVALID_INPUT_MSG, "fail to process"); return HIAI_INVALID_INPUT_MSG; } else { input_que_.PopData(0, input_arg1); input_que_.PopData(1, input_arg2); input_que_.PopData(2, input_arg3); } */ // // Intermediate service logic can directly call the DVPP API or AIModelManger API for processing. // // Allocate memory to save results. std::shared_ptr<UseDefDataTypeT> output1 = std::make_shared<UseDefDataTypeT>(); std::shared_ptr<UseDefTemplateDataType<uint64_t, uint64_t, uint64_t>> output2 = std::make_shared<UseDefTemplateDataType<uint64_t, uint64_t, uint64_t>>(); // Fill in the output data structure, for example, assign a value. *output1 = *input_arg2; *output2 = *input_arg3; // Send data to output port 0. hiai::Engine::SendData(0, "UseDefDataTypeT", std::static_pointer_cast<void>(output1)); // Send data to output port 1. hiai::Engine::SendData(1, "UseDefTemplateDataType_uint64_t_uint64_t_uint64_t", std::static_pointer_cast<void>(output2)); return HIAI_OK; } }
Parent topic: Engine Implementation APIs (C++ Language)
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