Closed f696ba87-9642-4a12-9763-41e0d269dfe0 closed 2 years ago
With Intel Compiler's default options or GCC with -mfpmath=sse, the built Python failed at float related test.
For failures in test_strtod:
Traceback (most recent call last):
File ".\test_strtod.py", line 190, in test_boundaries
self.check_strtod(s)
File ".\test_strtod.py", line 104, in check_strtod
"expected {}, got {}".format(s, expected, got))
AssertionError: '0x0.fffffffffffffp-1022' != '0x0.0p+0'
- 0x0.fffffffffffffp-1022
+ 0x0.0p+0
: Incorrectly rounded str->float conversion for 22250738585072008690e-327: expected 0x0.fffffffffffffp-1022, got 0x0.0p+0
22250738585072008690e-327 is less than positive normalize float 2250738585072014e-308 in sys.float_info, that is denormal float
With SSE optimization opened on current compilers, Denormal Flush to Zero feature will flush all denormal float to 0 to avoid hardware unsupport and increase performance.
The tests here better be skipped on DFZ opened binaries. http://bugs.python.org/issue1672332 is related to this problem.
What operating system and hardware is this on? Is there a good reason for wanting to compile with optimisations that break IEEE 754 behaviour?
If Python's configure script isn't using the right options, then that's a build problem rather than a problem with the tests. I'm rather surprised if these optimizations are turned on by default on mainstream systems.
By the way, what do you mean by DFZ? It's not a TLA that I'm familiar with. Do you mean FTZ (subnormal *results get replaced by zero)? Or DAZ (subnormal *inputs get replaced by zero)?
I'm not able to reproduce the error on my system
$ CFLAGS="-mfpmath=sse" ./configure --config-cache --with-pydebug
$ make
$ ./python -m test test_strtod
[1/1] test_strtod
1 test OK.
Linux 3.5.0-28 X86_64 gcc-Version 4.7.2 Intel(R) Core(TM) i7-2860QM CPU @ 2.50GHz
With gcc I cannot reproduce this either. For icc perhaps we should just set "-fp-model strict" in ./configure.
Hi Mark,
Sorry for unclear DFZ abbreviation, that is when compiler opened with FTZ and DAZ feature. My operating system is Linux X64, I only tried Intel Compiler. In default optimization mode, the FTZ option is opened. Don't known why Intel make it the default option, maybe they think performance handling Subnormal number values and compatibility with some hardware. https://en.wikipedia.org/wiki/Subnormal_number#Disabling_denormal_floats_at_the_code_level
The configure script of Python may not have precise detection on Intel Compiler, that feature can be closed with -no-ftz options.
Hi Christian,
I've not test GCC's DFZ/FTZ options, I'd like to test it myself and report here. Maybe '-ffast-math' is the right option.
Hi Stefan,
Tried to change the mode, but not work, seems the right options is '-no-ftz'.
Regards, V.E.O
Hi All,
From my test, GCC will not enforce DFZ/FTZ only by compiler options. It needs code modify register flag.
I think it's a problem with Intel Compiler. Maybe from platform.python_compiler(), these tests can identify the compiler and be skipped. But the identification is ambiguous, for in Linux it's "GCC Intel(R) C++ gcc x.x mode", in Windows it's like "MSC v.1600 32 bit (Intel)"
If the support for Intel Compiler is not OK, we can pending these issues for future fix.
From my test, GCC will not enforce DFZ/FTZ only by compiler options. It > needs code modify register flag.
But in normal use, the Python process should be starting in a sensible default state, with the DAZ and FTZ flags disabled, so I'm confused about how the DAZ / FTZ flags ever get set in the first place. Are you embedding Python in another app?
Hi Mark,
If these flag is opened by code running in Python, DAZ FTZ flags should be opened. With Intel Compiler, in default, they add code opening the flag for you.
Note that icc is not supported as per PEP 11 and python requires a C11 compiler since Python 3.11. If this issue still exists on supported python versions, create a new issue with a reproducer.
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields: ```python assignee = None closed_at = None created_at =
labels = ['type-bug', 'tests']
title = 'float related test has problem with Denormal Flush to Zero compiler options'
updated_at =
user = 'https://bugs.python.org/VEO'
```
bugs.python.org fields:
```python
activity =
actor = 'skrah'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = ['Tests']
creation =
creator = 'V.E.O'
dependencies = []
files = []
hgrepos = []
issue_num = 18340
keywords = []
message_count = 8.0
messages = ['192134', '192137', '192153', '192158', '192174', '192179', '192180', '192185']
nosy_count = 5.0
nosy_names = ['mark.dickinson', 'vstinner', 'eric.smith', 'christian.heimes', 'V.E.O']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'open'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue18340'
versions = ['Python 3.3']
```