task_manager: verify graph just once 65/315365/5
authorInki Dae <inki.dae@samsung.com>
Fri, 29 Nov 2024 07:44:50 +0000 (16:44 +0900)
committerInki Dae <inki.dae@samsung.com>
Wed, 4 Dec 2024 06:26:47 +0000 (06:26 +0000)
Verify graph just once. Now every time run function is called,
graph is verified but it's enough just once before calling run().

Change-Id: I91169cd9b1140cb49ae4776fef864278510e587e
Signed-off-by: Inki Dae <inki.dae@samsung.com>
services/auto_zoom/src/AutoZoom.cpp
services/task_manager/include/TaskManager.h
services/task_manager/src/TaskManager.cpp
test/services/test_task_manager.cpp

index df9653e8900c907b927531a3c5a330b7bcbaed59..ddfa149805bdeaaa2b18162cd4621a2ed4091737 100644 (file)
@@ -130,6 +130,8 @@ AutoZoom::AutoZoom()
 
        _taskManager->addEdge("startpoint", "face_detection");
        _taskManager->addEdge("face_detection", "endpoint");
+
+       _taskManager->verify();
 }
 
 void AutoZoom::configure(InputConfigBase &config)
index 29bbf58f998384da107160040e26934729bc96cc..95aeefc1ad0ba72d50f1c39b18a6b04cd3efd1cf 100644 (file)
@@ -41,6 +41,7 @@ private:
        std::vector<std::shared_ptr<BaseResultType> > _results;
        std::queue<std::shared_ptr<std::thread> > _threads;
        std::unordered_set<INode *> _is_thread_created;
+       bool _is_graph_verifed { false };
 
        std::mutex _thread_mutex;
 
@@ -57,6 +58,7 @@ public:
        void addInput(BaseDataType &input);
        void setBypass(const std::string &node_name, bool bypass = true, bool clearResult = false);
        std::vector<std::shared_ptr<BaseDataType> > &getInputs();
+       void verify();
        void run();
        std::vector<std::shared_ptr<BaseResultType> > &output();
        void clear();
index 9c18fb93f5493ca89e3a8973332109d6ad1dff0e..a56c2902132e02be1ef52ff80894257781a11c1f 100644 (file)
@@ -272,6 +272,13 @@ void TaskManager::verifyGraph()
                SINGLEO_LOGE("Invalid graph.(%zu!= %zu)", visitedCount, _nodes.size());
                throw InvalidOperation("Invalid graph.");
        }
+
+       _is_graph_verifed = true;
+}
+
+void TaskManager::verify()
+{
+       verifyGraph();
 }
 
 void TaskManager::run()
@@ -281,8 +288,10 @@ void TaskManager::run()
                throw InvalidOperation("No input source.");
        }
 
-       // TODO. move below function to other API. It isn't needed to call them every time run is called.
-       verifyGraph();
+       if (!_is_graph_verifed) {
+               SINGLEO_LOGE("Graph is not verified.");
+               throw InvalidOperation("Graph is not verified.");
+       }
 
        auto inputBuffer = make_shared<SharedBuffer>();
 
@@ -366,6 +375,11 @@ void TaskManager::resetPipeline()
 
 void TaskManager::addEdge(const string &node_a_name, const string &node_b_name)
 {
+       if (_is_graph_verifed) {
+               SINGLEO_LOGE("Graph has been freezed.");
+               throw InvalidOperation("Graph has been freezed.");
+       }
+
        auto &node_a = _nodes_map[node_a_name];
        auto &node_b = _nodes_map[node_b_name];
 
@@ -396,6 +410,7 @@ void TaskManager::clear()
        _nodes.clear();
        _results.clear();
        _is_thread_created.clear();
+       _is_graph_verifed = false;
 
        SharedBuffer::checkMemoryLeak();
 }
index 99795f97cc358819a29ced160c75163680e45626..adb3d4711c13bd84696846d95d42bd06fba7910f 100644 (file)
@@ -106,6 +106,8 @@ TEST(SingloTaskManager, MultipleNodesBasedGraphAShouldWork)
        taskManager->addEdge("bridge", "face_landmark");
        taskManager->addEdge("face_landmark", "endpoint");
 
+       taskManager->verify();
+
        for (unsigned int cnt = 0; cnt < maxIteration; ++cnt) {
                taskManager->addInput(image_data);
                taskManager->run();
@@ -173,6 +175,8 @@ TEST(SingloTaskManager, MultipleNodesBasedGraphBShouldWork)
        taskManager->addEdge("bridge", "face_landmark");
        taskManager->addEdge("face_landmark", "endpoint");
 
+       taskManager->verify();
+
        for (unsigned int cnt = 0; cnt < maxIteration; ++cnt) {
                taskManager->addInput(image_data);
                taskManager->run();
@@ -249,6 +253,8 @@ TEST(SingloTaskManager, MultipleNodesBasedGraphCShouldWork)
        taskManager->addEdge("face_detection", "endpoint");
        taskManager->addEdge("face_landmark", "endpoint");
 
+       taskManager->verify();
+
        for (unsigned int cnt = 0; cnt < maxIteration; ++cnt) {
                taskManager->addInput(image_data);
                taskManager->run();
@@ -327,6 +333,8 @@ TEST(SingloTaskManager, MultipleNodesBasedGraphDShouldWork)
        taskManager->addEdge("face_detection_b", "endpoint");
        taskManager->addEdge("face_landmark", "endpoint");
 
+       taskManager->verify();
+
        for (unsigned int cnt = 0; cnt < maxIteration; ++cnt) {
                taskManager->addInput(image_data);
                taskManager->run();
@@ -469,6 +477,8 @@ TEST(SingloTaskManager, MultipleNodesBasedGraphEShouldWork)
        taskManager->addEdge("object_detection", "endpoint");
        taskManager->addEdge("image_classification_2", "endpoint");
 
+       taskManager->verify();
+
        for (unsigned int cnt = 0; cnt < maxIteration; ++cnt) {
                taskManager->addInput(image_data);
                taskManager->run();
@@ -585,6 +595,8 @@ TEST(SingloTaskManager, MultipleNodesBasedGraphFShouldWork)
                taskManager->addEdge("face_landmark", "endpoint");
                taskManager->addEdge("image_classification", "endpoint");
 
+               taskManager->verify();
+
                for (unsigned int cnt = 0; cnt < maxIteration; ++cnt) {
                        taskManager->addInput(image_data);
                        taskManager->run();