【问题标题】:Is there a pytorch method to check the number of cpus?有没有pytorch方法来检查cpu的数量?
【发布时间】:2019-08-20 01:40:05
【问题描述】:

我可以使用这个torch.cuda.device_count() 来检查 GPU 的数量。我想知道是否有类似的东西可以检查 CPU 的数量。

【问题讨论】:

    标签: python neural-network deep-learning pytorch


    【解决方案1】:

    就用这个吧:

    os.cpu_count()
    

    【讨论】:

      【解决方案2】:

      目前pytorch在DistributedDataParallel实现中不支持多cpu集群。所以,我假设你的意思是 CPU 核心数。

      gpu count 方法没有直接等效的方法,但您可以使用 pytorch 获取可用于计算的线程数

      torch.get_num_threads()

      【讨论】:

      • 聚会有点晚了,但值得注意的是get_num_threads并没有真正得到用户可用的线程数,而是用户设置的线程数。它被初始化为正确的数字,但是如果你运行torch.set_num_threads(1024); print(torch.get_num_threads()),它将显示1024,无论你的处理器可以支持多少线程......更好的方法是os.cpu_count()
      猜你喜欢
      • 1970-01-01
      • 2017-09-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-28
      • 2011-03-22
      • 1970-01-01
      相关资源
      最近更新 更多