Skip to content

ENH: Add SIMD operation signbit #19748

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
wants to merge 1 commit into from
Closed

Conversation

howjmay
Copy link
Contributor

@howjmay howjmay commented Aug 24, 2021

No description provided.

@howjmay howjmay marked this pull request as draft August 24, 2021 18:10
@howjmay howjmay force-pushed the simd-signbit branch 12 times, most recently from 2a73080 to a7a5676 Compare August 24, 2021 19:38
@seberg
Copy link
Member

seberg commented Aug 24, 2021

Thanks! Can this vectorization deal with NaN?

In [1]: np.signbit(np.nan)
Out[1]: False

In [2]: np.signbit(-np.nan)
Out[2]: True

It looks a bit like using a comparison in the float case, and I am not sure that is correct there? I think you added signbit also for integers? np.signbit.types does not actually use these (they still work by casting to float, so I am not sure if we may be open to just adding it).

@howjmay howjmay force-pushed the simd-signbit branch 15 times, most recently from dda6f5e to f729b11 Compare August 25, 2021 19:00
@howjmay howjmay force-pushed the simd-signbit branch 10 times, most recently from 08fa7e6 to d04f3a1 Compare August 26, 2021 08:49
@howjmay howjmay changed the title ENH: Add SIMD operation signbit with cmplt ENH: Add SIMD operation signbit Aug 26, 2021
@howjmay howjmay force-pushed the simd-signbit branch 4 times, most recently from 3e6f831 to 4b4b98c Compare August 26, 2021 10:13
@howjmay
Copy link
Contributor Author

howjmay commented Aug 26, 2021

@seiko2plus I have removed the integer implementations. And test cases for ±nan and ± inf have been added too!

@howjmay howjmay marked this pull request as ready for review August 26, 2021 10:16
@howjmay
Copy link
Contributor Author

howjmay commented Aug 29, 2021

Hi @seiko2plus I recently want to finish some of lacking SIMD operations in numpy. However, I am meeting a problem that how can I find the mapping between names in https://github.com/numpy/numpy/blob/main/numpy/core/umath.py and the names under numpy/core/src/common/simd/. I saw some functions have been implemented (e.g. fmax and fmin), but there is no a explicit mapping between them

@seberg seberg added the component: SIMD Issues in SIMD (fast instruction sets) code or machinery label Sep 8, 2021
@InessaPawson
Copy link
Member

@seiko2plus Please respond to this comment when you get a chance.

@seiko2plus
Copy link
Member

I'm so sorry for taking forever, just get confused between this pr and pr #19770.

However, I am meeting a problem that how can I find the mapping between names in https://github.com/numpy/numpy/blob/main/numpy/core/umath.py and the names under numpy/core/src/common/simd/.

The universal intrinsics are completely independent of universal functions(ufunc) which we use within the umath module. You can follow the SIMD code within dispatch-able sources *.dispatch.c.src to discover how we implement the SIMD kernels of umath's operations.

I saw some functions have been implemented (e.g. fmax and fmin), but there is no a explicit mapping between them

Sometimes for future use or required by other kernels.

Regards to fmax, fmin, we had to implement three kinds of intrinsics for each datatype based on the NaN behavior:

  • npyv_max_[f32,f64] maps directly to the equivalent native instruction regardless of the NaN behavior.
  • npyv_maxp_[f32,f64] used by np.fmax which precisely respects IEC 60559.
  • npyv_maxn_[f32,f64] used by np.maximum for propagating NaNs

Again, I do not see any benefit in implementing a separate universal intrinsic for signbit, same case as copysign(#19770). The following code can fairly extract the signbit of both precision on all supported SIMD extensions:

npyv_shri_u32(npyv_reinterpret_u32_f32(v), 31);
npyv_shri_u64(npyv_reinterpret_u64_f64(v), 63);

@charris
Copy link
Member

charris commented Feb 20, 2023

@seiko2plus Should we pursue this?

@charris charris added the triage review Issue/PR to be discussed at the next triage meeting label Feb 20, 2023
@seiko2plus seiko2plus added the 57 - Close? Issues which may be closable unless discussion continued label Feb 21, 2023
@seiko2plus
Copy link
Member

@charris, no, my last comment was clear enough I guess. so it should be closed.

@charris charris closed this Feb 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
01 - Enhancement 57 - Close? Issues which may be closable unless discussion continued component: SIMD Issues in SIMD (fast instruction sets) code or machinery triage review Issue/PR to be discussed at the next triage meeting
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants