简体   繁体   English

Python multiprocessing.cpu_count() 在 4 核 Nvidia Jetson TK1 上返回“1”

[英]Python multiprocessing.cpu_count() returns '1' on 4-core Nvidia Jetson TK1

Can anyone tell me why Python's multiprocessing.cpu_count() function would return 1 when called on a Jetson TK1 with four ARMv7 processors?谁能告诉我为什么 Python 的multiprocessing.cpu_count()函数在具有四个 ARMv7 处理器的 Jetson TK1 上调用时会返回1

>>> import multiprocessing
>>> multiprocessing.cpu_count()
1

The Jetson TK1 board is more or less straight out of the box, and no one has messed with cpusets. Jetson TK1 开发板或多或少是直接开箱即用的,没有人弄乱过 cpuset。 From within the same Python shell I can print the contents of /proc/self/status and it tells me that the process should have access to all four cores:在同一个 Python shell 中,我可以打印/proc/self/status ,它告诉我该进程应该可以访问所有四个核心:

>>> print open('/proc/self/status').read()
----- (snip) -----
Cpus_allowed:   f
Cpus_allowed_list:      0-3
----- (snip) -----

What else could be causing this behavior from cpu_count() ?还有什么可能导致cpu_count()出现这种行为?

Edit:编辑:

To test Klaus's hypothesis, I used the following code to run a very simple experiment:为了检验 Klaus 的假设,我使用以下代码运行了一个非常简单的实验:

import multiprocessing

def f(x):
    n = 0
    for i in xrange(10000):
        n = max(n, multiprocessing.cpu_count())
    return n

p = multiprocessing.Pool(5)
for i in range(10):
    print p.map(f, [1,2,3,4,5])

Which produced the following output:这产生了以下输出:

[3, 3, 3, 3, 1]
[4, 3, 3, 3, 3]
[4, 3, 3, 3, 3]
[3, 3, 4, 3, 3]
[4, 3, 3, 3, 3]
[3, 3, 4, 3, 3]
[4, 3, 3, 3, 3]
[3, 3, 4, 3, 3]
[3, 3, 3, 4, 3]
[4, 3, 3, 3, 3]

Running just a single iteration of p.map(f, [1,2,3,4,5]) usually produces [1, 1, 1, 1, 1] , although occasionally a 2 will appear as one of the list elements.仅运行p.map(f, [1,2,3,4,5])的单次迭代通常会产生[1, 1, 1, 1, 1] ,尽管偶尔会出现2作为列表元素之一.

On Linux systems multiprocessing.cpu_count() relies on a sysconf (_SC_NPROCESSORS_ONLN) call, which returns the number of online CPUs in contrast to sysconf (_SC_NPROCESSORS_CONF) which returns the number of configured CPUs.在 Linux 系统上, multiprocessing.cpu_count()依赖于sysconf (_SC_NPROCESSORS_ONLN)调用,它返回在线CPU 的数量,而sysconf (_SC_NPROCESSORS_CONF)则返回已配置的CPU 的数量。

The values might differ in systems with advanced CPU power management functionality that sets CPU cores offline to save energy or with similar dynamic CPU activation functionality.在具有高级 CPU 电源管理功能(将 CPU 内核设置为离线以节省能源)或具有类似动态 CPU 激活功能的系统中,这些值可能会有所不同。

The documentation for os.cpu_count() (which declares that it returns the total number of CPUS, not the number of usable CPUs) provides a means to count usable CPUs: os.cpu_count() 的文档(声明它返回 CPU 总数,而不是可用 CPU 的数量)提供了一种计算可用 CPU 的方法:

len(os.sched_getaffinity(0))

see https://docs.python.org/3/library/os.html#os.cpu_counthttps://docs.python.org/3/library/os.html#os.cpu_count

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如果在python multiprocessing.cpu_count()中返回64,我是否可以从gcloud计算引擎的96个vCPU中受益? - Do I benefit from the 96 vCPUs of a gcloud Compute Engine if in python multiprocessing.cpu_count() returns 64? 为什么我的 CPU 核心数是 2,但使用 multiprocessing.cpu_count() 得到 4? - Why my CPU core number is 2, but use multiprocessing.cpu_count() get 4? multiprocessing.cpu_count和os.cpu_count之间的区别 - Difference between multiprocessing.cpu_count and os.cpu_count 在Jetson Tk1板上将CULA密集库加载到python中 - Load CULA dense library into python on jetson tk1 board multiprocessing.cpu_count返回错误的内核数量 - multiprocessing.cpu_count returning wrong number of cores 带有线程的4核PC的高效Python编程? - Efficient Python programming for 4-core PC with threading? Python 多线程/多处理和限制 CPU 内核关联性 - Python multithreading/multiprocessing & limiting CPU core affinity 用于 Nvidia Jetson Nano 的 Yocto Bitbake Recipes for Python whl 文件不在 PyPi 上 - Yocto Bitbake Recipes for Nvidia Jetson Nano for Python whl files not on PyPi python 多处理导入池,cpu_count:导致永远循环 - python multiprocessing import Pool, cpu_count: causes forever loop Nvidia Jetson 上的 Tensorflow Lite - Tensorflow Lite on Nvidia Jetson
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM