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 have some code that can not run on mac #5801

Closed
jacquesqiao opened this issue Nov 21, 2017 · 14 comments · Fixed by #5808
Closed

v2 init have some code that can not run on mac #5801

jacquesqiao opened this issue Nov 21, 2017 · 14 comments · Fixed by #5808
Assignees

Comments

@jacquesqiao
Copy link
Member

jacquesqiao commented Nov 21, 2017

https://github.com/PaddlePaddle/Paddle/blob/develop/python/paddle/v2/__init__.py#L88

 ht = os.popen("lscpu |grep \"per core\"|awk -F':' '{print $2}'|xargs")

Mac中不支持lscpu这个指令

@tensor-tang
Copy link
Contributor

可以在docker里面直接使用。

@jacquesqiao
Copy link
Member Author

mac里边现在无法运行book,这个还是需要支持一下

@tensor-tang
Copy link
Contributor

tensor-tang commented Nov 21, 2017

这几句话的目的是获取机器状态,用于绑核和设置环境变量。

#5671

Code可以在docker里面直接使用。

如果需要支持mac的话, @luotao1 我只能在Mac环境下注释掉这几句了。

因为目前我们还没有考虑直接在Mac中跑的情况。

@jacquesqiao
Copy link
Member Author

@wangkuiyi do we need to support running book chapters directly in MacOS or we just support running in Docker container?

@luotao1
Copy link
Contributor

luotao1 commented Nov 21, 2017

@jacquesqiao mac在docker环境下可以运行book的。mac本地环境下,这行代码确实运行不了,有其他替代这行功能的代码么?

@typhoonzero
Copy link
Contributor

我理解还是需要支持下mac,原因是文档中说明支持了在mac中pip install。

可以按照 @tensor-tang 的方法,mac下不走这个分支。

@tensor-tang
Copy link
Contributor

tensor-tang commented Nov 21, 2017

如果有更加上层的命令获取,可以直接从python获取系统超线程状态和系统可用的processor个数,是可以完全替代的。这里的code写的确实不够抽象。

@wangkuiyi
Copy link
Collaborator

这里不支持mac的原因是什么呢?如果只是某些命令和Linux下用法不兼容,是不是稍微判断一下就可以支持mac和linux了?如果是这样,就加一个判断吧。

@tensor-tang
Copy link
Contributor

tensor-tang commented Nov 21, 2017

原因是我直接采用了
lscpu |grep \"per core\"|awk -F':' '{print $2}'|xargs
grep \"processor\" /proc/cpuinfo|sort -u|wc -l这样的hard code。

当时没有找到比较上层、通用的做法。

不知道大家有没有好的建议。

@wangkuiyi
Copy link
Collaborator

wangkuiyi commented Nov 21, 2017

ht = os.popen("lscpu |grep \"per core\"|awk -F':' '{print $2}'|xargs")
ht = int(ht.read())
if ht == 1: # ht is off
set_env("OMP_DYNAMIC", "false")
set_env("KMP_AFFINITY", "granularity=fine,compact,0,0")
else:
set_env("OMP_DYNAMIC", "true")
set_env("KMP_AFFINITY", "granularity=fine,compact,1,0")

这里为什么如果开启了hyperthreading就应该设置 OMP_DYNAMIC 呢?

我问这个问题是想说,如果不是特别必要的逻辑,是不是可以简化,不要导致mac和linux的不兼容?

@wangkuiyi
Copy link
Collaborator

wangkuiyi commented Nov 21, 2017

If it is really necessary to know if hyper-threading is enabled, we can use the following commands with Mac:

sysctl -n hw.physicalcpu
sysctl -n hw.logicalcpu

where sysctl is a BSD-native program.

Given above information, we can defined a Python function like the following:

import platform

def is_hyperthreading_enabled() :
  if platform.system() == "Darwin":
    return ...
  elif platform.system() == "Linux":
    return ...
  else ...

@wangkuiyi
Copy link
Collaborator

之前廖刚和其他几个人花了很多时间确保 PaddlePaddle 可以在 Mac 上编译和运行。希望我们不要因为不重要的原因,损失了这个功能。

@tensor-tang
Copy link
Contributor

因为当开启超线程之后,有的机器上可用的线程数会比较多(特别是server上),让OMP自己根据实际需要的并行程度自动调整,一般会带来比较好的性能。当然这个也不是绝对的,也是需要跟着workload走的,只不过通常情况下这样的配置比较好。

所以,还留了个接口,让用户在外面也可以改掉这个值,

envset = os.environ.get(key)
if envset is None:
os.environ[key] = value

@tensor-tang
Copy link
Contributor

好的thx,稍后我来加上。

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