-
Notifications
You must be signed in to change notification settings - Fork 228
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
Fix ARM issues #1515
Fix ARM issues #1515
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1515 +/- ##
==========================================
- Coverage 87.17% 86.50% -0.68%
==========================================
Files 203 206 +3
Lines 28950 29009 +59
Branches 3910 3914 +4
==========================================
- Hits 25238 25094 -144
- Misses 3274 3469 +195
- Partials 438 446 +8
Continue to review full report at Codecov.
|
should the title be updated? |
c2894cf
to
29967fc
Compare
0b7e78d
to
b106ca2
Compare
devito/archinfo.py
Outdated
flags = [i for i in lines if i.startswith('flags')][0] | ||
# ARM Thunder X2 is using 'Features' instead of 'flags' | ||
flags = [i for i in lines if (i.startswith('Features') | ||
or i.startswith('flags'))][0] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpicking: the or i.startswith('flags)'
should be aligned with i.startswith('Featuers')
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But then flake8 complains (?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it will not
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
devito/archinfo.py
Outdated
@@ -64,12 +66,16 @@ def get_cpu_brand(): | |||
|
|||
cpu_info['flags'] = get_cpu_flags() | |||
cpu_info['brand'] = get_cpu_brand() | |||
if cpu_info['brand'] is None: | |||
cpu_info['brand'] = cpuinfo.get_cpu_info().get('raw_arch_string') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, this should be moved here in place of the return None
right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a new try-except pair I would say (?)
805fa2a
to
9cf091a
Compare
eb6eac8
to
a2cf2b3
Compare
devito/archinfo.py
Outdated
flags = [i for i in lines if i.startswith('flags')][0] | ||
# ARM Thunder X2 is using 'Features' instead of 'flags' | ||
flags = [i for i in lines if (i.startswith('Features') | ||
or i.startswith('flags'))][0] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it will not
devito/archinfo.py
Outdated
cpu_info['flags'] = ci.get('flags') | ||
cpu_info['brand'] = ci.get('brand') | ||
try: | ||
if 'flags' not in cpu_info: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it true that the only possibility for flags
not to be in cpu_info
is that lines
is empty? because if we enter the if lines:
at line 34, then we go through lines 70-71, hence cpu_info['flags']
should be defined?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the part where I do not know what happens in OSX, tests fail only there.
devito/archinfo.py
Outdated
if 'flags' not in cpu_info: | ||
# Fallback | ||
ci = cpuinfo.get_cpu_info() | ||
cpu_info['flags'] = ci.get('flags') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so going back to my original comment. What I was actually suggesting was to move the content of the try-except in place of current line 48 -- instead of returning None
, we return the cpuinfo.get_cpu_info().get('flags')
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
again, I did that the previous days and was failing on OSX
devito/archinfo.py
Outdated
|
||
# Detect number of logical cores | ||
try: | ||
if cpu_info['brand'] == 'aarch64': | ||
# In some ARM processors psutils and lscpu fail to detect cores correctly |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this comment doesn't make much sense does it? you say that lscpu
fails, but then you actually use it below?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
omg nice catch, I do not remember what I was thinking at that time.
devito/archinfo.py
Outdated
# In some ARM processors psutils and lscpu fail to detect cores correctly | ||
logical = psutil.cpu_count(logical=True) | ||
physical = psutil.cpu_count(logical=False) | ||
if physical != (lscpu()['Core(s) per socket'] * lscpu()['Socket(s)']): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if not A:
B = A
=>
B = A
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True. This is a leftover from using it to print a warning message thaty was later removed.
warning...core autodetection is not reliable....using lscpu....
9112899
to
8638a12
Compare
devito/archinfo.py
Outdated
try: | ||
physical = lscpu()['Core(s) per socket'] * lscpu()['Socket(s)'] | ||
physical = (lscpu()['Core(s) per socket'] * lscpu()['Socket(s)']) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why adding parentheses?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
devito/archinfo.py
Outdated
@@ -107,15 +119,16 @@ def get_cpu_brand(): | |||
# Fallback 1: it should now be fine to use psutil | |||
physical = psutil.cpu_count(logical=False) | |||
if not physical: | |||
# Fallback 2: we might end up here on more exotic platforms such a Power8 | |||
# Hopefully we can rely on `lscpu` | |||
# Fallback 2: we might end up here |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we avoid breaking this line into three?
also, typo: 'such a' -> 'such as'
should we now drop the "or due to erroneous autodetection" part?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes
devito/archinfo.py
Outdated
@@ -258,7 +271,8 @@ def lscpu(): | |||
if output: | |||
lines = output.decode("utf-8").strip().split('\n') | |||
mapper = {} | |||
for k, v in [tuple(i.split(':')) for i in lines]: | |||
# Using split(':', 1) to avoid splitting lines with security issues |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"with security issues" . Can you be more precise? Nobody will understand it
# Using split(.....
# Example: ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about:
# Using split(':', 1) to avoid splitting lines where lscpu shows vulnerabilities
# on some CPUs: https://askubuntu.com/questions/1248273/lscpu-vulnerabilities
devito/archinfo.py
Outdated
return flags.split(':')[1].strip().split() | ||
except: | ||
return None | ||
pass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why this change? this will return None
anyway, so it's clearer the other way
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why will this return None
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I get your point. TO my understanding if the last pair of try-except in each function
get_cpu_xxx
is returning None, then we are fine.
c3f3ddd
to
bd1202c
Compare
0040b64
to
0055eea
Compare
devito/archinfo.py
Outdated
cpu_info['flags'] = ci.get('flags') | ||
cpu_info['brand'] = ci.get('brand') | ||
try: | ||
if cpu_info['flags'] is None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see the point for this try-except. The following should suffice?
if not cpu_info.get('flags'):
cpu_info['flags'] = cpuinfo.get_cpu_info().get('flags')
same for the other try-except below
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
devito/archinfo.py
Outdated
except KeyError: | ||
cpu_info['brand'] = cpuinfo.get_cpu_info().get('brand') | ||
|
||
# Detect number of physical and logical cores |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Drop this comment and replace with the comment below "Special case: in ... " (note that "In" -> "in" . Colons don't want capital letters afterwards)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
devito/archinfo.py
Outdated
# correctly so we use lscpu() | ||
logical = psutil.cpu_count(logical=True) | ||
physical = (lscpu()['Core(s) per socket'] * lscpu()['Socket(s)']) | ||
cpu_info['logical'] = logical |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still think that the issue with ARM is the correct detection of number of physical cores, not the logical cores. So I would:
- drop the
logical
detection here - move this try-except after the "logical core detection" part, ie below line 110
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but getting the logical here helps as return cpu_info
and avoid all the other lines after 110
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was suggesting to move it right between lines 103 and 104, so you would still avoid "those other lines"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we do so, I think, it'd become a bit neater
ea61b62
to
b339bbf
Compare
devito/archinfo.py
Outdated
# correctly so we use lscpu() | ||
logical = psutil.cpu_count(logical=True) | ||
physical = (lscpu()['Core(s) per socket'] * lscpu()['Socket(s)']) | ||
cpu_info['logical'] = logical |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was suggesting to move it right between lines 103 and 104, so you would still avoid "those other lines"
devito/archinfo.py
Outdated
# correctly so we use lscpu() | ||
logical = psutil.cpu_count(logical=True) | ||
physical = (lscpu()['Core(s) per socket'] * lscpu()['Socket(s)']) | ||
cpu_info['logical'] = logical |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we do so, I think, it'd become a bit neater
Considering the amount of
|
devito/archinfo.py
Outdated
try: | ||
if 'arm' in cpu_info['brand']: | ||
physical = (lscpu()['Core(s) per socket'] * lscpu()['Socket(s)']) | ||
cpu_info['physical'] = physical |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can this be a single line or does it not fit the 90 chars limit?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually think I'm quite happy with the current state of this PR
9bceb52
to
3b1ab1a
Compare
devito/core/__init__.py
Outdated
CustomOperator) | ||
from devito.core.intel import (Intel64Operator, Intel64OpenMPOperator, | ||
Intel64FSGOperator, Intel64FSGOpenMPOperator) | ||
from devito.core.arm import (ArmOperator, ArmOpenMPOperator) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need for parentheses
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
devito/core/__init__.py
Outdated
from devito.core.intel import (Intel64Operator, Intel64OpenMPOperator, | ||
Intel64FSGOperator, Intel64FSGOpenMPOperator) | ||
from devito.core.arm import (ArmOperator, ArmOpenMPOperator) | ||
from devito.core.power import (PowerOperator, PowerOpenMPOperator) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
devito/core/arm.py
Outdated
__all__ = ['ArmOperator', 'ArmOpenMPOperator'] | ||
|
||
|
||
ArmOperator = CPU64Operator |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this really needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
HHmm... not needed but was it needed before?
devito/core/arm.py
Outdated
|
||
|
||
ArmOperator = CPU64Operator | ||
ArmOpenMPOperator = CPU64OpenMPOperator |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
devito/core/intel.py
Outdated
_specialize_iet = CPU64OpenMPOperator._specialize_iet | ||
|
||
|
||
PowerOperator = CPU64Operator |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dropped
devito/core/intel.py
Outdated
PowerOperator = CPU64Operator | ||
PowerOpenMPOperator = CPU64OpenMPOperator | ||
|
||
ArmOperator = CPU64Operator |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dropped
0ff18e1
to
9bd2e95
Compare
devito/core/arm.py
Outdated
optimize_halospots, hoist_prodders, relax_incr_dimensions) | ||
from devito.tools import timed_pass | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
one extra blank line?
df0acb2
to
f730bc5
Compare
f730bc5
to
2da5b8e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK now, thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, good now, thanks. Merging
Merged. |
Supersedes 1510
Fix ARM issue, improve platform autodetection.
lscpu
andpsutil
where possible:
due to https://askubuntu.com/questions/1248273/lscpu-vulnerabilitiesTODO:
Improve par-nested override for a global solution
Tested on Isambard's Marvell ThunderX2