Skip to content

Commit 54b1611

Browse files
authored
[onert] Ensure proper pipeline cleanup on exceptions and shutdown (#16379)
These changes ensure that pipeline resources are properly released even in error scenarios or when the pipeline was not fully initialized, preventing potential resource leaks. ONE-DCO-1.0-Signed-off-by: Jonghwa Lee <jonghwa3.lee@samsung.com>
1 parent bef4b9e commit 54b1611

File tree

4 files changed

+10
-10
lines changed

4 files changed

+10
-10
lines changed

runtime/onert/backend/trix/ops/BulkPipelineLayer.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ void BulkPipelineLayer::run()
6161
}
6262
catch (const std::exception &e)
6363
{
64+
_pipeline_manager->shutdown();
6465
std::cerr << "BulkPipelineLayer execution failed: " << e.what() << std::endl;
6566
throw;
6667
}

runtime/onert/backend/trix/ops/BulkPipelineManager.cc

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,6 @@ bool BulkPipelineManager::initialize()
5959

6060
void BulkPipelineManager::shutdown()
6161
{
62-
if (!_initialized.load())
63-
{
64-
return;
65-
}
66-
6762
_initialized = false;
6863

6964
// Wait until all executions are finished

runtime/onert/backend/trix/ops/BulkPipelineModel.cc

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,6 @@ bool BulkPipelineModel::prepare()
7979

8080
void BulkPipelineModel::release()
8181
{
82-
if (!_prepared.load())
83-
{
84-
return;
85-
}
86-
8782
// Cancel a asynchronous job
8883
if (_async_fill_future.valid())
8984
{

runtime/onert/backend/trix/ops/test/BulkPipelineManager.test.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ class BulkPipelineManagerTest : public ::testing::Test
6161
void TearDown() override {}
6262

6363
std::unique_ptr<BulkPipelineManager> manager;
64+
const int nr_models = 1;
6465
};
6566

6667
TEST_F(BulkPipelineManagerTest, test_initilize)
@@ -71,9 +72,17 @@ TEST_F(BulkPipelineManagerTest, test_initilize)
7172

7273
TEST_F(BulkPipelineManagerTest, test_shutdown)
7374
{
75+
int nr_fclose_calls = 0;
7476
EXPECT_TRUE(manager->initialize());
77+
// This hook will checking the number of fclose() calls
78+
MockSyscallsManager::getInstance().setFcloseHook([&nr_fclose_calls](FILE *) -> int {
79+
nr_fclose_calls++;
80+
return 0;
81+
});
7582
manager->shutdown();
7683
EXPECT_FALSE(manager->isInitialized());
84+
// fclose() should be called as the same number of models
85+
EXPECT_EQ(nr_fclose_calls, nr_models);
7786
}
7887

7988
TEST_F(BulkPipelineManagerTest, test_execute)

0 commit comments

Comments
 (0)