Skip to content

Commit

Permalink
postprocessing: hailo: Add singeton for vdevice
Browse files Browse the repository at this point in the history
The vdevice is a singelton and multiple Hailo postprocessing stages
must use the same vdevice instance in order to acquire the hardware.

Signed-off-by: Naushir Patuck <[email protected]>
  • Loading branch information
naushir committed Oct 10, 2024
1 parent ba2c497 commit 673ee33
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 6 deletions.
44 changes: 39 additions & 5 deletions post_processing_stages/hailo/hailo_postprocessing_stage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,41 @@ using namespace hailort;
using Rectangle = libcamera::Rectangle;
using Size = libcamera::Size;

namespace
{

// Singleton class for the hardware virtual device.
class vdevice
{
public:
vdevice(vdevice &other) = delete;
void operator=(const vdevice &) = delete;

static VDevice *get_instance()
{
static std::unique_ptr<VDevice> _vdevice {};

if (!_vdevice)
{
Expected<std::unique_ptr<VDevice>> vdevice_exp = VDevice::create();
if (!vdevice_exp)
{
LOG_ERROR("Failed create vdevice, status = " << vdevice_exp.status());
return nullptr;
}
_vdevice = vdevice_exp.release();
}

return _vdevice.get();
}

private:
vdevice() {}
};

} // namespace


Allocator::Allocator()
{
}
Expand Down Expand Up @@ -111,13 +146,12 @@ void HailoPostProcessingStage::Configure()

int HailoPostProcessingStage::configureHailoRT()
{
Expected<std::unique_ptr<VDevice>> vdevice_exp = VDevice::create();
if (!vdevice_exp)
vdevice_ = vdevice::get_instance();
if (!vdevice_)
{
LOG_ERROR("Failed create vdevice, status = " << vdevice_exp.status());
return vdevice_exp.status();
LOG_ERROR("Failed to get a vdevice instance.");
return -1;
}
vdevice_ = vdevice_exp.release();

// Create infer model from HEF file.
Expected<std::shared_ptr<InferModel>> infer_model_exp = vdevice_->create_infer_model(hef_file_);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class HailoPostProcessingStage : public PostProcessingStage

Allocator allocator_;

std::unique_ptr<hailort::VDevice> vdevice_;
hailort::VDevice *vdevice_;
std::shared_ptr<hailort::InferModel> infer_model_;
std::shared_ptr<hailort::ConfiguredInferModel> configured_infer_model_;

Expand Down

0 comments on commit 673ee33

Please sign in to comment.