zoukankan      html  css  js  c++  java
  • 关于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')
  • 相关阅读:
    PDF,仅支持英译中,可以下载后的pdf或者word版
    pip指定源安装【自用】
    【jQuery01】jQuery选择器
    【jQuery00】什么是jQuery,为什么要学jQuery,配置jQuery环境,解决冲突,大致使用流程
    什么是召回率??
    编程学习路线
    堆排序
    二叉插入排序
    每天算法一丁点(4)--递归算法应用:分书问题
    每天算法一丁点(3)--递归算法应用:半数集
  • 原文地址:https://www.cnblogs.com/supercxm/p/8640430.html
Copyright © 2011-2022 走看看