Alex Blog

[HailoRT]Async API的调用(4.16.0)

设备初始化

初始化设备并创建名为“VDevice”的虚拟设备。

hailo_vdevice_params_t params;
auto status = hailo_init_vdevice_params(&params);
#ifndef SCHEDULE
params.scheduling_algorithm = HAILO_SCHEDULING_ALGORITHM_NONE;
#else
params.scheduling_algorithm = HAILO_SCHEDULING_ALGORITHM_ROUND_ROBIN;
#endif
params.device_count = 1;
auto vdevice = VDevice::create(params);

模型导入和配置

模型导入

根据提供的路径导入模型。配置包括设置批处理大小、输入/输出格式以及处理量化参数。vdevice.value()->create_infer_model(HEF_FILE);
infer_model->set_batch_size(BATH_SIZE);
infer_model->output()->set_format_type(HAILO_FORMAT_TYPE_FLOAT32);
infer_model->output(name)->get_quant_infos();
infer_model->configure();

调度器和模型激活

配置调度器相关设置并激活模型。对于非调度器情景,直接激活模型。

configured_infer_model->set_scheduler_timeout(TIME_OUT);
configured_infer_model->set_scheduler_threshold(THRESHOLD);
configured_infer_model->activate(); // 仅适用于非调度器情景

创建绑定并配置输入/输出缓冲区

创建绑定并配置模型的输入和输出缓冲区。

configured_infer_model->create_bindings();
bindings->input()->set_buffer(MemoryView(alignedBuffer, input_frame_size));
bindings->output(output_name)->set_buffer(MemoryView(output_buffer.get(), output_frame_size));

AI推理/处理

使用配置的模型和绑定执行AI推理。支持同步和异步执行,可选择是否使用回调函数。

configured_infer_model->run(bindings.value(), TIME_OUT); // 无回调函数

for (uint32_t i = 0; i < frame_cnt; i++)  {
configured_infer_model->wait_for_async_ready(TIME_OUT);

    job = configured_infer_model->run_async(bindings.value(), call_back);
    if (i == frame_cnt – 1) {
        last_infer_job = job.release();
    }
    job->detach();
}

last_infer_job.wait(TIME_OUT);


已发布

分类

,

来自

标签:

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注