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')
  • 相关阅读:
    access remote libvirtd
    python中获取当前所有的logger
    python标准库xml.etree.ElementTree的bug
    python Requests库在处理response时的一些陷阱
    Ubuntu12.04下安装Subversion并进行配置
    命令行打包war包
    Ubuntu12.04安装MariaDB并修改字符集为UTF-8
    Windows下Navicat远程连接Linux下MySQL服务器错误1130
    解决ubuntu下eth0不显示
    解决Ubuntu12.04下rpcbind: cannot open '/var/run/rpcbind/rpcbind.xdr' file for reading
  • 原文地址:https://www.cnblogs.com/supercxm/p/8640430.html
Copyright © 2011-2022 走看看