zoukankan      html  css  js  c++  java
  • 【每天学习一点点】Tensorflow2.X 运行问题:Could not create cudnn handle: CUDNN_STATUS_ALLOC_FAILED

    Tensorflow2.X 运行问题:Could not create cudnn handle: CUDNN_STATUS_ALLOC_FAILED

    Probably you're running out of GPU memory.


    If you're using TensorFlow 1.x:

    1st option) set allow_growth to true.

    import tensorflow as tf    
    config = tf.ConfigProto()
    config.gpu_options.allow_growth=True
    sess = tf.Session(config=config)
    

    2nd option) set memory fraction.

    # change the memory fraction as you want
    
    import tensorflow as tf
    gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=0.3)
    sess = tf.Session(config=tf.ConfigProto(gpu_options=gpu_options))
    

    If you're using TensorFlow 2.x:

    1st option) set set_memory_growth to true.

    # Currently the ‘memory growth’ option should be the same for all GPUs.
    # You should set the ‘memory growth’ option before initializing GPUs.
    
    import tensorflow as tf
    gpus = tf.config.experimental.list_physical_devices('GPU')
    if gpus:
      try:
        for gpu in gpus:
          tf.config.experimental.set_memory_growth(gpu, True)
      except RuntimeError as e:
        print(e)
    

    2nd option) set memory_limit as you want. Just change the index of gpus and memory_limit in this code below.

    import tensorflow as tf
    gpus = tf.config.experimental.list_physical_devices('GPU')
    if gpus:
      try:
        tf.config.experimental.set_virtual_device_configuration(gpus[0], [tf.config.experimental.VirtualDeviceConfiguration(memory_limit=1024)])
      except RuntimeError as e:
        print(e)

    使用方案:
    import tensorflow as tf
    gpus = tf.config.experimental.list_physical_devices('GPU')
    if gpus:
      try:
        for gpu in gpus:
          tf.config.experimental.set_memory_growth(gpu, True)
      except RuntimeError as e:
        print(e)
    问题解决。

    参考:https://stackoverflow.com/questions/48610132/tensorflow-crash-with-cudnn-status-alloc-failed

     
  • 相关阅读:
    时间戳 时间 相互转换
    CS Academy Remove Update
    一周水题集锦 2017 9.4
    计蒜客 16877 卡牌游戏
    计蒜客 16876 韩梅梅的抽象画
    九度OJ 题目1534:数组中第K小的数字
    CS Academy Switch the Lights
    CF AIM Tech Round 4 C. Sorting by Subsequences
    CF Round 430 C. Ilya And The Tree
    CS Academy Round 44 Check DFS
  • 原文地址:https://www.cnblogs.com/huangliujing/p/13406465.html
Copyright © 2011-2022 走看看