zoukankan      html  css  js  c++  java
  • python开启GPU加速

    看了好多教程都提到了使用 os.environ["CUDA_VISIBLE_DEVICES"] = "1" 或者export CUDA_VISIBLE_DEVICES=1
    但是我加进代码里面速度并没有提高,查了很久才找到问题所在,当你的电脑有两块以上GPU时,上面这两句代码才起作用!

    因为我的电脑只有一块GPU,所以需要将参数的“1”改成“0”才可以,否则找不到“1”号设备,它就会默认使用CPU,速度不会提高。

    如果是在终端中运行python程序,使用命令:CUDA_VISIBLE_DEVICES=0 python filename.py即可

    -------------------------------------------------补充:---------------------------------------------
    如果有多块卡,想要指定多个gpu训练,可以这样设置:

    def set_gpus(gpu_index):
    if type(gpu_index) == list:
    gpu_index = ','.join(str(_) for _ in gpu_index)
    if type(gpu_index) ==int:
    gpu_index = str(gpu_index)
    os.environ["CUDA_VISIBLE_DEVICES"] = gpu_index
    1
    2
    3
    4
    5
    6
    通过调用set_gpu函数即可实现。

    Attention:
    一定要注意的是,CUDA_VISIBLE_DEVICES,每!一!个!字!母! 必须完全写对,如果不小心写成了 CUDA_VISIBLE_DIVICES 或者 CUDA_VISIABLE_DEVICES ,代码是不会报错的,但是GPU调用不会成功,排查问题浪费了我好几个小时。。。切记!
    ---------------------
    作者:aaon22357
    来源:CSDN
    原文:https://blog.csdn.net/aaon22357/article/details/82733218
    版权声明:本文为博主原创文章,转载请附上博文链接!

  • 相关阅读:
    tip
    tip
    paper clip 使用
    这个菜单有点cool
    jqueryoptiontree plugin introduce by frederick.mao
    ruby语法不理解
    近来心得,心不可太贪,见好就收
    XPCOM的有关链接
    rails router
    rails3高端observer模式
  • 原文地址:https://www.cnblogs.com/jfdwd/p/11130766.html
Copyright © 2011-2022 走看看