Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 917544 - dev-python/numpy-1.26.2: Includes faulty float16 implementation on ppc64
Summary: dev-python/numpy-1.26.2: Includes faulty float16 implementation on ppc64
Status: CONFIRMED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: PPC64 Linux
: Normal normal (vote)
Assignee: Gentoo Science Related Packages
URL: https://github.com/numpy/numpy/issues...
Whiteboard:
Keywords: PATCH
Depends on:
Blocks:
 
Reported: 2023-11-18 08:22 UTC by Marcus Comstedt
Modified: 2023-11-26 14:40 UTC (History)
2 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Marcus Comstedt 2023-11-18 08:22:30 UTC
Whenever I import numpy, I get a warning about division by 0 from
/usr/lib/python3.11/site-packages/numpy/core/getlimits.py.

This turns out to be because it's trying to figure out the precision of float16, but float16 does not seem to be working.  It's possible to convert numbers to and from float16 (the conversion could be wrong, but it is at least bijective), but any attempt to do math with directly with float16 results in a 0.

Python 3.11.5 (main, Oct 21 2023, 17:50:00) [GCC 12.3.1 20230526] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
/usr/lib/python3.11/site-packages/numpy/core/getlimits.py:52: RuntimeWarning: divide by zero encountered in log10
  self.precision = int(-log10(self.eps))
>>> np.float16(1.0)
1.0
>>> np.float16(1.0)+0.0    # operand is widened before addition
1.0
>>> np.float16(1.0)+np.float16(0.0)
0.0
>>> 


Reproducible: Always

Steps to Reproduce:
1.in python on ppc64 (POWER9, big endian, in case it matters), import numpy
2.
3.
Actual Results:  
numpy complains due to not being able to calculate the precision of float16.
numpy contains a broken float16 class.

Expected Results:  
No complaints from numpy.
Either a working float16 class or none at all.

Portage 3.0.51 (python 3.11.5-final-0, default/linux/ppc64/17.0/desktop, gcc-13, glibc-2.37-r7, 5.4.249 ppc64)
=================================================================
System uname: Linux-5.4.249-ppc64-POWER9,_altivec_supported-with-glibc2.37
KiB Mem:   133525376 total,  59290560 free
KiB Swap:          0 total,         0 free
Timestamp of repository gentoo: Fri, 17 Nov 2023 17:00:01 +0000
Head commit of repository gentoo: 88485c0905b1c057025ed0d72010118a56203f44
Head commit of repository pike: 45ccd330ca143edc800640b3f87d430a17e9f7e0

Head commit of repository sawfish: bd1ce62b0af2428c55d379e826d34e69745b60f9

sh bash 5.1_p16-r6
ld GNU ld (Gentoo 2.40 p5) 2.40.0
app-misc/pax-utils:        1.3.7::gentoo
app-shells/bash:           5.1_p16-r6::gentoo
dev-java/java-config:      2.3.1-r1::gentoo
dev-lang/perl:             5.38.0-r1::gentoo
dev-lang/python:           3.11.5::gentoo, 3.12.0::gentoo
dev-lang/rust:             1.71.1::gentoo
dev-util/cmake:            3.27.7::gentoo
dev-util/meson:            1.2.2-r1::gentoo
sys-apps/baselayout:       2.14::gentoo
sys-apps/openrc:           0.48::gentoo
sys-apps/sandbox:          2.38::gentoo
sys-devel/autoconf:        2.13-r7::gentoo, 2.71-r6::gentoo
sys-devel/automake:        1.16.5-r1::gentoo
sys-devel/binutils:        2.40-r5::gentoo
sys-devel/binutils-config: 5.5::gentoo
sys-devel/clang:           15.0.7-r3::gentoo, 16.0.6::gentoo
sys-devel/gcc:             13.2.1_p20230826::gentoo
sys-devel/gcc-config:      2.11::gentoo
sys-devel/libtool:         2.4.7-r1::gentoo
sys-devel/llvm:            15.0.7-r3::gentoo, 16.0.6::gentoo
sys-devel/make:            4.4.1-r1::gentoo
sys-kernel/linux-headers:  6.1::gentoo (virtual/os-headers)
sys-libs/glibc:            2.37-r7::gentoo
Repositories:

gentoo
    location: /usr/portage
    sync-type: rsync
    sync-uri: rsync://rsync.gentoo.org/gentoo-portage
    priority: -1000
    volatile: True
    sync-rsync-extra-opts: 
    sync-rsync-verify-metamanifest: yes
    sync-rsync-verify-jobs: 1
    sync-rsync-verify-max-age: 24

zeldin
    location: /usr/local/portage
    masters: gentoo
    volatile: True

crossdev
    location: /usr/local/portage-crossdev
    masters: gentoo
    priority: 10
    volatile: True

pike
    location: /var/db/repos/pike
    sync-type: git
    sync-uri: git://pike-git.lysator.liu.se/pike-overlay.git
    masters: gentoo
    priority: 50
    volatile: False

sawfish
    location: /var/db/repos/sawfish-overlay
    sync-type: git
    sync-uri: https://gitlab.com/teika-gentoo/sawfish-overlay.git
    masters: gentoo
    priority: 90
    volatile: False

ACCEPT_KEYWORDS="ppc64"
ACCEPT_LICENSE="@FREE"
CBUILD="powerpc64-unknown-linux-gnu"
CFLAGS="-O2 -pipe -mcpu=power9"
CHOST="powerpc64-unknown-linux-gnu"
CONFIG_PROTECT="/etc /usr/lib64/libreoffice/program/sofficerc /usr/share/config /usr/share/gnupg/qualified.txt"
CONFIG_PROTECT_MASK="/etc/ca-certificates.conf /etc/dconf /etc/env.d /etc/fonts/fonts.conf /etc/gconf /etc/gentoo-release /etc/revdep-rebuild /etc/sandbox.d /etc/terminfo /etc/texmf/language.dat.d /etc/texmf/language.def.d /etc/texmf/updmap.d /etc/texmf/web2c"
CXXFLAGS="-O2 -pipe -mcpu=power9"
DISTDIR="/usr/portage/distfiles"
EMERGE_DEFAULT_OPTS="--autounmask"
ENV_UNSET="CARGO_HOME DBUS_SESSION_BUS_ADDRESS DISPLAY GDK_PIXBUF_MODULE_FILE GOBIN GOPATH PERL5LIB PERL5OPT PERLPREFIX PERL_CORE PERL_MB_OPT PERL_MM_OPT XAUTHORITY XDG_CACHE_HOME XDG_CONFIG_HOME XDG_DATA_HOME XDG_RUNTIME_DIR XDG_STATE_HOME"
FCFLAGS="-O2 -pipe"
FEATURES="assume-digests binpkg-docompress binpkg-dostrip binpkg-logs buildpkg-live config-protect-if-modified distlocks ebuild-locks fixlafiles ipc-sandbox merge-sync multilib-strict network-sandbox news parallel-fetch pid-sandbox preserve-libs protect-owned qa-unresolved-soname-deps sandbox sfperms strict unknown-features-warn unmerge-logs unmerge-orphans userfetch userpriv usersandbox usersync xattr"
FFLAGS="-O2 -pipe"
GENTOO_MIRRORS="http://distfiles.gentoo.org"
LANG="sv_SE.utf8"
LDFLAGS="-Wl,-O1 -Wl,--as-needed"
LEX="flex"
MAKEOPTS="-j50"
PKGDIR="/usr/portage/packages"
PORTAGE_CONFIGROOT="/"
PORTAGE_RSYNC_OPTS="--recursive --links --safe-links --perms --times --omit-dir-times --compress --force --whole-file --delete --stats --human-readable --timeout=180 --exclude=/distfiles --exclude=/local --exclude=/packages --exclude=/.git"
PORTAGE_TMPDIR="/tmp/"
SHELL="/bin/tcsh"
USE="X a52 aac acl alsa big-endian bluetooth branding bzip2 cairo cdda cdr ckj cli crypt cups dbus dri dts dvd dvdr elogind encode exif flac fortran gdbm gif gnutls gpm gtk gui ibm iconv icu idn ipv6 jpeg lcms libffi libnotify lua mad mng mp3 mp4 mpeg mule multitarget ncurses nis nls nptl offensive ogg opengl openmp pam pango pcre pdf png policykit ppc64 ppds qt5 readline sdl seccomp smp sound spell split-usr ssl startup-notification svg test-rust theora threads tiff truetype udev udisks unicode upower usb vorbis wxwidgets x264 xattr xcb xemacs xft xml xv xvid zlib" ADA_TARGET="gnat_2021" APACHE2_MODULES="authn_core authz_core socache_shmcb unixd actions alias auth_basic authn_alias authn_anon authn_dbm authn_default authn_file authz_dbm authz_default authz_groupfile authz_host authz_owner authz_user autoindex cache cgi cgid dav dav_fs dav_lock deflate dir disk_cache env expires ext_filter file_cache filter headers include info log_config logio mem_cache mime mime_magic negotiation rewrite setenvif speling status unique_id userdir usertrack vhost_alias" CALLIGRA_FEATURES="karbon sheets words" COLLECTD_PLUGINS="df interface irq load memory rrdtool swap syslog" CPU_FLAGS_PPC="altivec vsx vsx2 vsx3" ELIBC="glibc" GPSD_PROTOCOLS="ashtech aivdm earthmate evermore fv18 garmin garmintxt gpsclock greis isync itrax mtk3301 nmea ntrip navcom oceanserver oldstyle oncore rtcm104v2 rtcm104v3 sirf skytraq superstar2 timing tsip tripmate tnt ublox ubx" INPUT_DEVICES="libinput" KERNEL="linux" LCD_DEVICES="bayrad cfontz cfontz633 glk hd44780 lb216 lcdm001 mtxorb ncurses text" LIBREOFFICE_EXTENSIONS="presenter-console presenter-minimizer" LUA_SINGLE_TARGET="lua5-1" LUA_TARGETS="lua5-1" OFFICE_IMPLEMENTATION="libreoffice" PHP_TARGETS="php8-1" POSTGRES_TARGETS="postgres15" PYTHON_SINGLE_TARGET="python3_11" PYTHON_TARGETS="python3_11" RUBY_TARGETS="ruby31" VIDEO_CARDS="fbdev radeon r600" XTABLES_ADDONS="quota2 psd pknock lscan length2 ipv4options ipset ipp2p iface geoip fuzzy condition tee tarpit sysrq proto steal rawnat logmark ipmark dhcpmac delude chaos account"
Unset:  ADDR2LINE, AR, ARFLAGS, AS, ASFLAGS, CC, CCLD, CONFIG_SHELL, CPP, CPPFLAGS, CTARGET, CXX, CXXFILT, ELFEDIT, EXTRA_ECONF, F77FLAGS, FC, GCOV, GPROF, INSTALL_MASK, LC_ALL, LD, LFLAGS, LIBTOOL, LINGUAS, MAKE, MAKEFLAGS, NM, OBJCOPY, OBJDUMP, PORTAGE_BINHOST, PORTAGE_BUNZIP2_COMMAND, PORTAGE_COMPRESS, PORTAGE_COMPRESS_FLAGS, PORTAGE_RSYNC_EXTRA_OPTS, RANLIB, READELF, RUSTFLAGS, SIZE, STRINGS, STRIP, YACC, YFLAGS
Comment 1 matoro archtester 2023-11-18 18:53:29 UTC
Does not repro for me on stable clean chroot on BE...must be something flags-related or kernel maybe?

Python 3.11.5 (main, Aug 28 2023, 05:57:37) [GCC 12.3.1 20230526] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
>>> np.float16(1.0)
1.0
>>> np.float16(1.0) + 0.0
1.0
>>> np.float16(1.0) + np.float16(0.0)
1.0
>>> import platform ; platform.platform()
'Linux-6.6.1-gentoo-ppc64-ppc64-POWER9_-architected-,_altivec_supported-with-glibc2.37'
Comment 2 Marcus Comstedt 2023-11-18 21:31:20 UTC
The full cflags during compilation are:

-Inumpy/core/_multiarray_umath.cpython-311-powerpc64-linux-gnu.so.p -Inumpy/core -I../numpy-1.26.2/numpy/core -Inumpy/core/include -I../numpy-1.26.2/numpy/core/include -I../numpy-1.26.2/numpy/core/src/common -I../numpy-1.26.2/numpy/core/src/multiarray -I../numpy-1.26.2/numpy/core/src/npymath -I../numpy-1.26.2/numpy/core/src/umath -I/usr/include/python3.11 -I/tmp/portage/dev-python/numpy-1.26.2/work/numpy-1.26.2-python3_11/meson_cpu -fvisibility=hidden -fdiagnostics-color=always -Wall -Winvalid-pch -std=c99 -O3 -fno-strict-aliasing -mcpu=power9 -DNPY_HAVE_VSX -DNPY_HAVE_VSX_ASM -DNPY_HAVE_VSX2 -DNPY_HAVE_VSX3 -DNPY_HAVE_VSX3_HALF_DOUBLE -O2 -pipe -mcpu=power9 -fno-strict-aliasing -DNDEBUG -fPIC -DHAVE_CBLAS -DNPY_INTERNAL_BUILD -DHAVE_NPY_CONFIG_H -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE=1 -D_LARGEFILE64_SOURCE=1 

Of this "-O2 -pipe -mcpu=power9" comes from my make.conf, the rest is generated by the make system.

I'm wondering if the "-DNPY_HAVE_VSX3_HALF_DOUBLE" is perhaps a bad idea?
My P9:s are DD2.2, btw.

Python 3.11.5 (main, Oct 21 2023, 17:50:00) [GCC 12.3.1 20230526] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import platform ; platform.platform()
'Linux-5.4.249-ppc64-POWER9,_altivec_supported-with-glibc2.37'
>>>
Comment 3 matoro archtester 2023-11-18 21:34:49 UTC
Try apply this patch?  https://github.com/numpy/numpy/pull/25083
Comment 4 Marcus Comstedt 2023-11-18 21:37:37 UTC
That patch is already included in 1.26.2, AFAICT.
Comment 5 Marcus Comstedt 2023-11-18 21:49:22 UTC
I tried removing -DNPY_HAVE_VSX3_HALF_DOUBLE, but the behaviour is the same, so doesn't seem related...
Comment 6 matoro archtester 2023-11-18 21:55:00 UTC
OK, I got it.  This shows up with -mcpu=power9, and only on BE (does not repro on LE even with -mcpu=power9).  You can temporarily work around by removing -mcpu=power9 from CFLAGS.  In the meantime I will report upstream.
Comment 7 Marcus Comstedt 2023-11-18 22:04:57 UTC
I changed the cflags to say -mcpu=power8 for now, and that got me a working numpy (with VSX2 optimizations).  Thanks.
Comment 8 Marcus Comstedt 2023-11-20 06:43:20 UTC
The upstreams fix works for me.  I just had to change "_core" to "core" in the path name for the patch to apply.