optimize_aop.hdev对sobel边缘检测算子 AOP的对不同大小图像并行加速效果 相关例程学习

index:.../System/Parallelization/optimize_aop.hdev


* This example program shows the difference of AOP (automatic
* operator parallelization) models that can be trained using
* optimize_aop. The speed-up of the sobel_amp operator for
* various image sizes is measured for different aop optimizations
* and the results are plotted. The example program is optimized
* for machines with more than 16 Processors.

dev_update_off ()
dev_close_window ()

WindowWidth := 500
WindowHeight := 500
dev_open_window (0, 0, WindowWidth, WindowHeight, 'black', WindowHandle1)
dev_set_line_width (2)
set_display_font (WindowHandle1, 14, 'mono', 'true', 'false')

* Initialization
get_system ('processor_num', NumCPUs)
read_image (Image, 'monkey')

ImageSize := [32,48,64,96,128,192,256,372,512]

这里搞了很多图像大小,以便后面直接zoom猴子照片来做运算
Threads := [1:NumCPUs]
Speedup := [1:max([2,NumCPUs / 2])]

Loops := 50
OperatorName := 'sobel_amp'
Method := 'sum_abs'
Mask := 3
Param := 'false'
InputControl := [Method,Mask]

Message := 'This program shows the effect of \'optimize_aop\''
Message[1] := 'using the example of \'sobel_amp\'.'
Message[2] := ' '
Message[3] := 'Therefore, \'optimize_aop\' is called'
Message[4] := 'with four different training modes:'
Message[5] := '- \'nil\' (no optimization)'
Message[6] := '- \'threshold\' (either use only one or all cores)'
Message[7] := '- \'linear\' (# cores proportional to image size)'
Message[8] := '- \'mlp\' (classifier-based).'
Message[9] := ' '
Message[10] := 'After that, the execution times of \'sobel_amp\''
Message[11] := 'are measured for different image sizes.'
disp_message (WindowHandle1, Message, 'window', 12, 12, 'white', 'false')

* Clear AOP information
disp_message (WindowHandle1, 'Measure \'nil\' ... ', 'window', 250, 12, 'yellow', 'false')
count_seconds (S1)
optimize_aop (OperatorName, 'byte', 'no_file', ['file_mode','system_mode'], ['nil','remove'])

help说是检测硬件做并行运算的潜能,总之它后面用的就是下面两个算子了

get_system ('parallelize_operators', Information)
get_aop_info (OperatorName, ['iconic_type','parameter:0'], ['byte',''], 'max_threads', Value)

得到了最大线程数的值max_threads

* Use no AOP model
measure_speedup_on_size (Image, InputControl, Loops, ImageSize, SpeedupNil, UsedThreadsNil)

这是一个自定义跳进去的函数,在里面对各种大小的图像做了运算并看运行效率
count_seconds (S2)
TimeNil := S2 - S1
disp_message (WindowHandle1, 'Measure \'nil\' ... done in ' + TimeNil$'.2' + ' s', 'window', 250, 12, 'green', 'false')

* Use threshold AOP model
disp_message (WindowHandle1, 'Measure \'threshold\' ...', 'window', 280, 12, 'yellow', 'false')
count_seconds (S1)
optimize_aop (OperatorName, 'byte', 'no_file', ['file_mode','model','parameters'], ['nil','threshold',Param])
measure_speedup_on_size (Image, InputControl, Loops, ImageSize, SpeedupThresh, UsedThreadsThresh)
count_seconds (S2)
TimeThresh := S2 - S1
disp_message (WindowHandle1, 'Measure \'threshold\' ... done in ' + TimeThresh$'.2' + ' s', 'window', 280, 12, 'green', 'false')

* Use linear AOP model
disp_message (WindowHandle1, 'Measure \'linear\' ...', 'window', 310, 12, 'yellow', 'false')
count_seconds (S1)
optimize_aop (OperatorName, 'byte', 'no_file', ['file_mode','model','parameters'], ['nil','linear',Param])
measure_speedup_on_size (Image, InputControl, Loops, ImageSize, SpeedupLinear, UsedThreadsLinear)
count_seconds (S2)
TimeLinear := S2 - S1
disp_message (WindowHandle1, 'Measure \'linear\' ... done in ' + TimeThresh$'.2' + ' s', 'window', 310, 12, 'green', 'false')

* Use MLP AOP model
disp_message (WindowHandle1, 'Measure \'mlp\' ...', 'window', 340, 12, 'yellow', 'false')
count_seconds (S1)
optimize_aop (OperatorName, 'byte', 'no_file', ['file_mode','model','parameters'], ['nil','mlp',Param])
measure_speedup_on_size (Image, InputControl, Loops, ImageSize, SpeedupMLP, UsedThreadsMLP)
count_seconds (S2)
TimeMLP := S2 - S1
disp_message (WindowHandle1, 'Measure \'mlp\' ... done in ' + TimeThresh$'.2' + ' s', 'window', 340, 12, 'green', 'false')
disp_continue_message (WindowHandle1, 'black', 'true')
stop ()

* Display results
dev_clear_window ()
dev_open_window (0, WindowWidth + 13, WindowWidth, WindowHeight, 'black', WindowHandle2)
dev_set_line_width (2)
set_display_font (WindowHandle2, 14, 'mono', 'true', 'false')
Legend := ['\'nil\'','\'threshold\'','\'linear\'','\'mlp\'']
Colors := ['red','orange','yellow','green']

* Plot results

这是一组画图的函数,用的时候可以拿来直接用
plot_tuple (WindowHandle1, ImageSize$'d', [SpeedupNil,SpeedupThresh,SpeedupLinear,SpeedupMLP], 'Image Size', ' Speedup factor', Colors, ['grid_y','ticks_y','start_y'], [1,1,0])
disp_message (WindowHandle1, Legend, 'window', 280, 300, Colors, 'false')
plot_tuple (WindowHandle2, ImageSize$'d', [UsedThreadsNil,UsedThreadsThresh,UsedThreadsLinear,UsedThreadsMLP], 'Image Size', '# Threads', Colors, ['grid_y','ticks_y','start_y'], [1,1,0])
disp_message (WindowHandle2, Legend, 'window', 280, 300, Colors, 'false')

从图上看,图像大时用mlp合适,但是mlp也是高级插值方法。线程数都还是很智能的调节的。



做处理的猴子图片

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
optimize_aop是HALCON中的一个函数,用于优化AOP(automatic operator parallelization)模型。它可以根据线程号优化AOP,并检查给定硬件的并行处理能力。optimize_aop会检查每个运算符,并通过在tuple元组、channel通道或domain level域级别上的自动并行化来加快操作速度。它会执行多次运算符,并根据输入参数的变化来评估并行处理的效率。对于正确的优化,需要确保在计算机上没有同时运行其他计算密集型应用程序,以避免影响硬件检查的时间测量。如果程序员不想使用AOP,而是自己实现并行化,那么需要使用多线程技术,将图像进行拆分处理,最后再合并。这需要更多的专业知识,可以参考HALCON的官方例程simulate_aop.hdev和官方说明书parallel_programming.pdf。\[2\]\[3\] #### 引用[.reference_title] - *1* [optimize_aop.hdevsobel边缘检测算子 AOP的对不同大小图像并行加速效果 相关例程学习](https://blog.csdn.net/u013404374/article/details/48996877)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* *3* [关于实现Halcon算法加速的基础知识(CPU多核并行/GPU)](https://blog.csdn.net/libaineu2004/article/details/104202063)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值