{"id":533,"date":"2024-01-18T08:00:53","date_gmt":"2024-01-18T00:00:53","guid":{"rendered":"https:\/\/www.zhoubin.asia\/?p=533"},"modified":"2024-01-26T10:40:05","modified_gmt":"2024-01-26T02:40:05","slug":"hailortasync-api","status":"publish","type":"post","link":"https:\/\/www.zhoubin.asia\/index.php\/2024\/01\/18\/hailortasync-api\/","title":{"rendered":"[HailoRT]Async API\u7684\u8c03\u7528\uff084.16.0\uff09"},"content":{"rendered":"<h1>\u8bbe\u5907\u521d\u59cb\u5316<\/h1>\n<p>\u521d\u59cb\u5316\u8bbe\u5907\u5e76\u521b\u5efa\u540d\u4e3a\u201cVDevice\u201d\u7684\u865a\u62df\u8bbe\u5907\u3002<\/p>\n<p><em>hailo_vdevice_params_t params;<\/em><br \/>\n<em>auto status = hailo_init_vdevice_params(&amp;params);<\/em><br \/>\n<em>#ifndef SCHEDULE<\/em><br \/>\n<em>params.scheduling_algorithm = HAILO_SCHEDULING_ALGORITHM_NONE;<\/em><br \/>\n<em>#else<\/em><br \/>\n<em>params.scheduling_algorithm = HAILO_SCHEDULING_ALGORITHM_ROUND_ROBIN;<\/em><br \/>\n<em>#endif<\/em><br \/>\n<em>params.device_count = 1;<\/em><br \/>\n<em>auto vdevice = VDevice::create(params);<\/em><\/p>\n<h1>\u6a21\u578b\u5bfc\u5165\u548c\u914d\u7f6e<\/h1>\n<h2>\u6a21\u578b\u5bfc\u5165<\/h2>\n<p>\u6839\u636e\u63d0\u4f9b\u7684\u8def\u5f84\u5bfc\u5165\u6a21\u578b\u3002\u914d\u7f6e\u5305\u62ec\u8bbe\u7f6e\u6279\u5904\u7406\u5927\u5c0f\u3001\u8f93\u5165\/\u8f93\u51fa\u683c\u5f0f\u4ee5\u53ca\u5904\u7406\u91cf\u5316\u53c2\u6570\u3002<em>vdevice.value()-&gt;create_infer_model(HEF_FILE);<\/em><br \/>\n<em>infer_model-&gt;set_batch_size(BATH_SIZE);<\/em><br \/>\n<em>infer_model-&gt;output()-&gt;set_format_type(HAILO_FORMAT_TYPE_FLOAT32);<\/em><br \/>\n<em>infer_model-&gt;output(name)-&gt;get_quant_infos();<\/em><br \/>\n<em>infer_model-&gt;configure();<\/em><\/p>\n<h2>\u8c03\u5ea6\u5668\u548c\u6a21\u578b\u6fc0\u6d3b<\/h2>\n<p>\u914d\u7f6e\u8c03\u5ea6\u5668\u76f8\u5173\u8bbe\u7f6e\u5e76\u6fc0\u6d3b\u6a21\u578b\u3002\u5bf9\u4e8e\u975e\u8c03\u5ea6\u5668\u60c5\u666f\uff0c\u76f4\u63a5\u6fc0\u6d3b\u6a21\u578b\u3002<\/p>\n<p><em>configured_infer_model-&gt;set_scheduler_timeout(TIME_OUT);<\/em><br \/>\n<em>configured_infer_model-&gt;set_scheduler_threshold(THRESHOLD);<\/em><br \/>\n<em>configured_infer_model-&gt;activate(); \/\/ \u4ec5\u9002\u7528\u4e8e\u975e\u8c03\u5ea6\u5668\u60c5\u666f<\/em><\/p>\n<h2>\u521b\u5efa\u7ed1\u5b9a\u5e76\u914d\u7f6e\u8f93\u5165\/\u8f93\u51fa\u7f13\u51b2\u533a<\/h2>\n<p>\u521b\u5efa\u7ed1\u5b9a\u5e76\u914d\u7f6e\u6a21\u578b\u7684\u8f93\u5165\u548c\u8f93\u51fa\u7f13\u51b2\u533a\u3002<\/p>\n<p><em>configured_infer_model-&gt;create_bindings();<\/em><br \/>\n<em>bindings-&gt;input()-&gt;set_buffer(MemoryView(alignedBuffer, input_frame_size));<\/em><br \/>\n<em>bindings-&gt;output(output_name)-&gt;set_buffer(MemoryView(output_buffer.get(), output_frame_size));<\/em><\/p>\n<h1>AI\u63a8\u7406\/\u5904\u7406<\/h1>\n<p>\u4f7f\u7528\u914d\u7f6e\u7684\u6a21\u578b\u548c\u7ed1\u5b9a\u6267\u884cAI\u63a8\u7406\u3002\u652f\u6301\u540c\u6b65\u548c\u5f02\u6b65\u6267\u884c\uff0c\u53ef\u9009\u62e9\u662f\u5426\u4f7f\u7528\u56de\u8c03\u51fd\u6570\u3002<\/p>\n<p><em>configured_infer_model-&gt;run(bindings.value(), TIME_OUT); \/\/ \u65e0\u56de\u8c03\u51fd\u6570<\/em><\/p>\n<p><em>for (uint32_t i = 0; i &lt; frame_cnt; i++)\u00a0 {<br \/>\nconfigured_infer_model-&gt;wait_for_async_ready(TIME_OUT);<\/em><br \/>\n<em>\u00a0 \u00a0 job = configured_infer_model-&gt;run_async(bindings.value(), call_back);<\/em><br \/>\n<em>\u00a0 \u00a0 if (i == frame_cnt &#8211; 1) {<\/em><br \/>\n<em>\u00a0 \u00a0 \u00a0 \u00a0 last_infer_job = job.release();<\/em><br \/>\n<em>\u00a0 \u00a0 }<\/em><br \/>\n<em>\u00a0 \u00a0 job-&gt;detach();<\/em><br \/>\n<em>}<\/em><\/p>\n<p><em>last_infer_job.wait(TIME_OUT);<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8bbe\u5907\u521d\u59cb\u5316 \u521d\u59cb\u5316\u8bbe\u5907\u5e76\u521b\u5efa\u540d\u4e3a\u201cVDevice\u201d\u7684\u865a\u62df\u8bbe\u5907\u3002 hailo_vdevice_params_t  [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"footnotes":""},"categories":[5,1],"tags":[],"class_list":["post-533","post","type-post","status-publish","format-standard","hentry","category-hailort","category-tech"],"_links":{"self":[{"href":"https:\/\/www.zhoubin.asia\/index.php\/wp-json\/wp\/v2\/posts\/533","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.zhoubin.asia\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.zhoubin.asia\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.zhoubin.asia\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.zhoubin.asia\/index.php\/wp-json\/wp\/v2\/comments?post=533"}],"version-history":[{"count":1,"href":"https:\/\/www.zhoubin.asia\/index.php\/wp-json\/wp\/v2\/posts\/533\/revisions"}],"predecessor-version":[{"id":534,"href":"https:\/\/www.zhoubin.asia\/index.php\/wp-json\/wp\/v2\/posts\/533\/revisions\/534"}],"wp:attachment":[{"href":"https:\/\/www.zhoubin.asia\/index.php\/wp-json\/wp\/v2\/media?parent=533"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zhoubin.asia\/index.php\/wp-json\/wp\/v2\/categories?post=533"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhoubin.asia\/index.php\/wp-json\/wp\/v2\/tags?post=533"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}