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

Skip to content

ENH: Convert unary_fp from C universal intrinsics to C++ using Highway #28718

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

amane-ame
Copy link

Based on #28622, merge it first.

@tylerjereddy tylerjereddy added the component: SIMD Issues in SIMD (fast instruction sets) code or machinery label Apr 15, 2025
@amane-ame amane-ame force-pushed the hwy-unary_fp branch 3 times, most recently from b26135f to 6ae6aef Compare April 24, 2025 14:55
seiko2plus and others added 2 commits May 18, 2025 20:35
A thin wrapper over Google's Highway SIMD library to simplify its interface.
This commit provides the implementation of that wrapper, consisting of:

- simd.hpp: Main header defining the SIMD namespaces and configuration
- simd.inc.hpp: Template header included multiple times with different namespaces

The wrapper eliminates Highway's class tags by:
- Using lane types directly which can be deduced from arguments
- Leveraging namespaces (np::simd and np::simd128) for different register widths

A README is included to guide usage and document design decisions.

SIMD: Update wrapper with improved docs and type support

  - Fix hardware/platform terminology in documentation for clarity
  - Add support for long double in template specializations
  - Add kMaxLanes constant to expose maximum vector width information
  - Follows clang formatting style for consistency with NumPy codebase.

SIMD: Improve isolation and constexpr handling in wrapper

  - Add anonymous namespace around implementation to ensure each
    translation unit gets its own constants based on local flags
  - Use HWY_LANES_CONSTEXPR for Lanes function to ensure proper
    constexpr evaluation across platforms

Update Highway submodule to latest master

SIMD: Fix compile error by using MaxLanes instead of Lanes for array size

  Replace hn::Lanes(f64) with hn::MaxLanes(f64) when defining the index array
  size to fix error C2131: "expression did not evaluate to a constant". This error
  occurs because Lanes() isn't always constexpr compatible, especially with
  scalable vector extensions. MaxLanes() provides a compile-time constant value
  suitable for static array allocation and should be used with non-scalable SIMD
  extensions when defining fixed-size arrays.

SIMD: Rename NPY_SIMDX to NPY_HWY

Rename Highway wrapper macros for clarity:
- NPY_SIMDX → NPY_HWY
- NPY_SIMDX_F16 → NPY_HWY_F16
- NPY_SIMDX_F64 → NPY_HWY_F64
- NPY_SIMDX_FMA → NPY_HWY_FMA

To avoids confusion with legacy SIMD macros.
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR converts the unary floating‐point operations from the legacy C universal intrinsics implementation to a modern C++ implementation using Google's Highway library. The key changes include:

  • Converting the core SIMD unary functions in loops_unary_fp.dispatch.cpp to use Highway intrinsics.
  • Removing the legacy loops_unary_fp.dispatch.c.src file.
  • Adjustments in several dispatch and build configuration files to support the new SIMD implementation and additional targets (e.g., RVV).

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.

Show a summary per file
File Description
numpy/_core/src/umath/loops_unary_fp.dispatch.cpp New C++ implementation using Highway intrinsics for unary floating‐point operations.
numpy/_core/src/umath/loops_unary_fp.dispatch.c.src Legacy implementation removed.
numpy/_core/src/umath/loops_trigonometric.dispatch.cpp Updated SIMD lane determination to use hn::MaxLanes instead of Lanes.
numpy/_core/src/umath/loops_hyperbolic.dispatch.cpp.src Updated SIMD lane determination for hyperbolic operations.
numpy/_core/src/highway Updated submodule commit for the Highway library.
numpy/_core/src/common/simd/simd.inc.hpp, simd.hpp, README.md Added and updated the new SIMD wrapper to support Highway.
numpy/_core/meson.build Adjusted file processing and added the RVV target to the build configuration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
01 - Enhancement component: SIMD Issues in SIMD (fast instruction sets) code or machinery
Projects
Status: Awaiting a code review
Development

Successfully merging this pull request may close these issues.

4 participants