• 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
    版权声明:本文为博主原创文章,转载请附上博文链接!

  • 相关阅读:
    Android 70道面试题汇总不再愁面试
    TOMCAT用Https替换Http的方法
    Struts2+Spring3+Hibernate3配置全过程
    javac 无效标签
    hibernate
    数据库命令行启动
    Tomcat检测程序
    SQL
    Unsupported major.minor version 49.0的错误解决
    ImportError: No module named pysqlite2
  • 原文地址:https://www.cnblogs.com/jfdwd/p/11130766.html
Copyright © 2020-2023  润新知