Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v2 init error on MAC #5821

Closed
guoshengCS opened this issue Nov 22, 2017 · 7 comments · Fixed by #5828 or #5952
Closed

v2 init error on MAC #5821

guoshengCS opened this issue Nov 22, 2017 · 7 comments · Fixed by #5828 or #5952

Comments

@guoshengCS
Copy link
Contributor

guoshengCS commented Nov 22, 2017

when executing paddle.init on MAC, following errors occurred:

Traceback (most recent call last):
  File "paddle_demo_final.py", line 63, in <module>
    paddle.init(use_gpu=False, trainer_count=1)
  File "/Users/baidu/build_doc/build_env/lib/python2.7/site-packages/paddle/v2/__init__.py", line 133, in init
    set_omp_mkl_env_vars(kwargs.get('trainer_count', 1))
  File "/Users/baidu/build_doc/build_env/lib/python2.7/site-packages/paddle/v2/__init__.py", line 105, in set_omp_mkl_env_vars
    num_cores = num_physical_cores()
  File "/Users/baidu/build_doc/build_env/lib/python2.7/site-packages/paddle/v2/__init__.py", line 95, in num_physical_cores
    return int(os.popen(cmds.get(platform.system(), "expr 1")).read())
ValueError: invalid literal for int() with base 10: 'hw.physicalcpu: 2\n'

It seems that os.popen(cmds.get(platform.system(), "expr 1") returns hw.physicalcpu: 2\n rather than an integer.

@luotao1
Copy link
Contributor

luotao1 commented Nov 22, 2017

related with #5801, @tensor-tang can you help to see it?

@NHZlX
Copy link
Contributor

NHZlX commented Nov 27, 2017

 File "infer.py", line 78, in <module>
    out = main()
  File "infer.py", line 26, in main
    paddle.init(use_gpu=False)
  File "/home/xingzhaolong/.jumbo/lib/python2.7/site-packages/paddle/v2/__init__.py", line 133, in init
    set_omp_mkl_env_vars(kwargs.get('trainer_count', 1))
  File "/home/xingzhaolong/.jumbo/lib/python2.7/site-packages/paddle/v2/__init__.py", line 105, in set_omp_mkl_env_vars
    num_cores = num_physical_cores()
  File "/home/xingzhaolong/.jumbo/lib/python2.7/site-packages/paddle/v2/__init__.py", line 86, in num_physical_cores
    os.popen("lscpu |grep \"Socket\" |awk -F':' '{print $2}'|xargs")
ValueError: invalid literal for int() with base 10: ''

i meet this on my develop machine(linux).

@Yancey1989
Copy link
Contributor

What's the output with execute the command lscpu in the terminal?

@NHZlX
Copy link
Contributor

NHZlX commented Nov 27, 2017

Architecture:          x86_64
CPU op-mode(s):        32-bit, 64-bit
Byte Order:            Little Endian
CPU(s):                12
On-line CPU(s) list:   0-11
Thread(s) per core:    1
Core(s) per socket:    6
CPU socket(s):         2
NUMA node(s):          2
Vendor ID:             GenuineIntel
CPU family:            6
Model:                 62
Stepping:              4
CPU MHz:               2100.178
BogoMIPS:              4206.46
Virtualization:        VT-x
L1d cache:             32K
L1i cache:             32K
L2 cache:              256K
L3 cache:              15360K
NUMA node0 CPU(s):     0-5
NUMA node1 CPU(s):     6-11

@luotao1
Copy link
Contributor

luotao1 commented Nov 27, 2017

This is that socket in CPU socket(s) is lowercase letter, but in lscpu |grep \"Socket\" |awk -F':' '{print $2}'|xargs is uppercase letter.

@luotao1
Copy link
Contributor

luotao1 commented Nov 27, 2017

 num_sockets = int(
                os.popen("lscpu |grep \"Socket\" |awk -F':' '{print $2}'|xargs")
                .read())
 num_cores_per_socket = int(
                os.popen(
                    "lscpu |grep \"per socket\" |awk -F':' '{print $2}'|xargs")
                .read())
            return num_sockets * num_cores_per_socket

由于num_sockets和num_cores_per_socket都只用了一次,因此在使用grep的时候可以不区分大小写:

num_sockets, num_cores_per_socket = os.popen("lscpu | grep -i \"socket\" |awk -F':' '{print $2}'|xargs").read().strip('\n').split(" ")
return int(num_sockets) * int(num_cores_per_socket)

@tensor-tang
Copy link
Contributor

写反了,应该是 num_cores_per_socket, num_sockets = os.popen(...)
或者这里就不用区分这个名字了。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants