ONE - On-device Neural Engine
Loading...
Searching...
No Matches
onert::backend::trix::ops::BulkPipelineManager Class Reference

#include <BulkPipelineManager.h>

Data Structures

struct  PipelineConfig
 

Public Member Functions

 BulkPipelineManager (const PipelineConfig &config)
 
 ~BulkPipelineManager ()
 
 BulkPipelineManager (const BulkPipelineManager &)=delete
 
BulkPipelineManageroperator= (const BulkPipelineManager &)=delete
 
bool initialize ()
 
void shutdown ()
 
bool isInitialized () const
 
void execute (const std::vector< const IPortableTensor * > &inputs, std::vector< IPortableTensor * > &outputs)
 

Detailed Description

Definition at line 33 of file BulkPipelineManager.h.

Constructor & Destructor Documentation

◆ BulkPipelineManager() [1/2]

onert::backend::trix::ops::BulkPipelineManager::BulkPipelineManager ( const PipelineConfig config)
explicit

Definition at line 28 of file BulkPipelineManager.cc.

28 : _config(config)
29{
30 // DO NOTHING
31}

◆ ~BulkPipelineManager()

onert::backend::trix::ops::BulkPipelineManager::~BulkPipelineManager ( )

◆ BulkPipelineManager() [2/2]

onert::backend::trix::ops::BulkPipelineManager::BulkPipelineManager ( const BulkPipelineManager )
delete

Member Function Documentation

◆ execute()

void onert::backend::trix::ops::BulkPipelineManager::execute ( const std::vector< const IPortableTensor * > &  inputs,
std::vector< IPortableTensor * > &  outputs 
)

Definition at line 82 of file BulkPipelineManager.cc.

84{
85 if (!_initialized.load())
86 {
87 throw std::runtime_error("Pipeline is not initialized");
88 }
89
90 if (_models.empty())
91 {
92 throw std::runtime_error("No models in pipeline");
93 }
94
95 _executing = true;
96
97 try
98 {
99 auto current_inputs = inputs;
100 auto current_outputs = outputs;
101
102 for (size_t i = 0; i < _models.size(); ++i)
103 {
104 auto &model = _models[i];
105 if (!model || !model->isPrepared())
106 {
107 throw std::runtime_error("Model at index " + std::to_string(i) + " is not prepared");
108 }
109
110 // Wait for buffer ready before execution
111 model->waitForBufferReady();
112
113 // Execute model
114 model->run(current_inputs, current_outputs);
115
116 // The input of the next model is the output of the current model
117 if (i < _models.size() - 1)
118 {
119 current_inputs.clear();
120 for (const auto &output : current_outputs)
121 {
122 current_inputs.push_back(const_cast<IPortableTensor *>(output));
123 }
124 }
125
126 // Prepare next shared neighbor model
127 if (_use_buffer_sharing)
128 {
129 if (auto next = model->getNextModel())
130 {
131 next->startAsyncBufferFill();
132 }
133 }
134 }
135 }
136 catch (...)
137 {
138 _executing = false;
139 throw;
140 }
141
142 _executing = false;
143}

◆ initialize()

bool onert::backend::trix::ops::BulkPipelineManager::initialize ( )

Definition at line 35 of file BulkPipelineManager.cc.

36{
37 if (_initialized.load())
38 {
39 // Already initialized
40 return true;
41 }
42
43 try
44 {
45 createModels();
46 verifyModels();
47 prepareModels();
48 linkModels();
49
50 _initialized = true;
51 return true;
52 }
53 catch (const std::exception &e)
54 {
55 std::cerr << "Failed to initialize pipeline: " + std::string(e.what()) << std::endl;
56 shutdown();
57 return false;
58 }
59}

References shutdown().

◆ isInitialized()

bool onert::backend::trix::ops::BulkPipelineManager::isInitialized ( ) const
inline

Definition at line 55 of file BulkPipelineManager.h.

55{ return _initialized; }

◆ operator=()

BulkPipelineManager & onert::backend::trix::ops::BulkPipelineManager::operator= ( const BulkPipelineManager )
delete

◆ shutdown()

void onert::backend::trix::ops::BulkPipelineManager::shutdown ( )

Definition at line 61 of file BulkPipelineManager.cc.

62{
63 _initialized = false;
64
65 // Wait until all executions are finished
66 while (_executing.load())
67 {
68 std::this_thread::sleep_for(std::chrono::milliseconds(1));
69 }
70
71 // Release models and clear buffer pool
72 for (auto &model : _models)
73 {
74 if (model)
75 {
76 model->release();
77 }
78 }
79 _models.clear();
80}

Referenced by initialize(), and ~BulkPipelineManager().


The documentation for this class was generated from the following files: