Thanks to visit codestin.com
Credit goes to github.com

Skip to content

BUG: AVX-512 path for ufunc.accumulate is broken #15597

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

Closed
bashtage opened this issue Feb 18, 2020 · 7 comments · Fixed by #15612
Closed

BUG: AVX-512 path for ufunc.accumulate is broken #15597

bashtage opened this issue Feb 18, 2020 · 7 comments · Fixed by #15612
Labels
00 - Bug component: SIMD Issues in SIMD (fast instruction sets) code or machinery Priority: high High priority, also add milestones for urgent issues

Comments

@bashtage
Copy link
Contributor

We use np.minimum.accumulate in statsmodels. Recent pre-release tests have started failing on after calls to np.minimum.accumulate.

This code only fails on systems with AVX-512. Passes on systems with AVX and AVX2.

Reproducing code example:

import numpy as np
ntests = 10
pvals = np.random.random_sample(10)
pvals_corrected_raw = np.arange(ntests, 0, -1) * pvals
pvals_corrected = np.minimum.accumulate(pvals_corrected_raw[::-1])[::-1]

Failing job:

https://travis-ci.org/statsmodels/statsmodels/jobs/651893167

Error message:

No error, but wrong results. Likely strides are off since we often seem empty-like values in places.

Numpy/Python version information:

Python: 3.7.5.final.0
cython: 3.0a0
numpy: 1.19.0.dev0+4d2b585
scipy: 1.5.0.dev0+f614064 
pandas: 1.1.0.dev0+500.g06eb8db97 
@bashtage
Copy link
Contributor Author

xref statsmodels/statsmodels#6524

@bashtage
Copy link
Contributor Author

cc @josef-pkt @kshedden

@josef-pkt
Copy link

here's a maximum example from the unit tests

pvals = np.array([0.002, 0.004, 0.006, 0.008, 0.01 , 0.012])
ntests = len(pvals)

pvals_corrected_raw = pvals * np.arange(ntests, 0, -1)
pvals_corrected = np.maximum.accumulate(pvals_corrected_raw)
pvals_corrected

# expected array([0.012, 0.02 , 0.024, 0.024, 0.024, 0.024])
# in failing test array([0.012, 0.02 , 0.024, 0.024, 0.02 , 0.012])

the original pvals in the test is a view, but pvals_corrected_raw shouldn't be

(Pdb) pval.flags
C_CONTIGUOUS : True
F_CONTIGUOUS : True
OWNDATA : False
WRITEABLE : True
ALIGNED : True
WRITEBACKIFCOPY : False
UPDATEIFCOPY : False

@seberg
Copy link
Member

seberg commented Feb 18, 2020

@r-devulap can you ave a look?

@seberg seberg added 00 - Bug component: SIMD Issues in SIMD (fast instruction sets) code or machinery Priority: high High priority, also add milestones for urgent issues labels Feb 18, 2020
@seberg seberg modified the milestones: 1.18.2 release, 1.19.0 release Feb 18, 2020
@r-devulap
Copy link
Member

yup, taking a look ..

@r-devulap
Copy link
Member

Found the bug, np.maximum.accumulate results in input and output arrays being overlapped in memory in the maximum/minimum function. Added a pre-check to prevent vectorized code in such a scenario in PR #15612

@r-devulap
Copy link
Member

I brought up this question when I submitted the patch (see comments #14867 (comment)). There are no tests covering np.maximum.accumulate. Can someone help me understand under what scenarios do we expect input and output arrays to overlap in memory to ensure we haven't missed all the use cases.

r-devulap added a commit to r-devulap/numpy that referenced this issue Feb 23, 2020
…m and np.minimum

Fixes bug in np.maximum.accumulate and np.minimum.accumulate
See numpy#15597
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
00 - Bug component: SIMD Issues in SIMD (fast instruction sets) code or machinery Priority: high High priority, also add milestones for urgent issues
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants