關於Haclon使用GPU加速的代碼實例


關於Haclon使用GPU加速的代碼實例

read_image(Image, 'T20170902014819_58_2_1.bmp')
*沒有加加速並行處理
count_seconds(T1)
for i:=1 to 4 by 1
    rotate_image(Image, Image1, 90, 'constant')
endfor
count_seconds(T2)
Time1:=(T2-T1)*1000
stop()

*以下兩種加速只能選一種

*GPU加速,支持GPU加速的算子Halcon10只有56個
query_available_compute_devices(DeviceIdentifiers)
DeviceHandle:=0
for i:=0 to |DeviceIdentifiers|-1 by 1
    get_compute_device_info(DeviceIdentifiers[i], 'name', Nmae)
    if(Nmae='Geoforce GTX 1070')//根據GPU名稱打開GPU
        open_compute_device(DeviceIdentifiers[i], DeviceHandle)
        break
    endif
endfor
if(DeviceHandle#0)
    set_compute_device_param (DeviceHandle, 'asynchronous_execution', 'false')
    init_compute_device(DeviceHandle, 'rotate_image')
    activate_compute_device(DeviceHandle)
endif
count_seconds(T3)
for i:=1 to 4 by 1
    rotate_image(Image, Image1, 90, 'constant')
endfor
count_seconds(T4)
Time2:=(T4-T3)*1000
if(DeviceHandle#0)
    deactivate_compute_device(DeviceHandle)
endif
stop()


*自動加速並行處理
optimize_aop ('rotate_image', 'byte', 'no_file', ['file_mode','model','parameters'], ['nil','threshold','false'])
set_system ('parallelize_operators', 'true')//只需開一次
count_seconds(T5)
for i:=1 to 4 by 1
    rotate_image(Image, Image1, 90, 'constant')
endfor
count_seconds(T6)
Time3:=(T6-T5)*1000
set_system ('parallelize_operators', 'false')//只需最后關一次
stop()

set_display_font (3600, 14, 'mono', 'true', 'false')
dev_clear_window()
Message:='CPU only Time1='+Time1+'ms, '
disp_message (3600, Message, 'window', 12, 12, 'red', 'false')
stop()
dev_clear_window()
Message:='GPU use Time2='+Time2+'ms, '
disp_message (3600, Message, 'window', 12, 12, 'red', 'false')
stop()
dev_clear_window()
Message:='optimize Time3='+Time3+'ms, '
disp_message (3600, Message, 'window', 12, 12, 'red', 'false')

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM