Skip to content

Conversation

@zhangjian29
Copy link
Contributor

Description

This PR adds eltwise operation support for rvv_postops.hpp using a primitive-based approach according to previous proposal #4029.

Motivation

Following the successful integration of primitive-based binary post-ops into rvv_postops.hpp, our next step is to introduce eltwise type post-ops using the same primitive-based paradigm. This is crucial for establishing a general post_ops implementation for the RISC-V 64-bit architecture at this early stage.

Key Changes

  • Provided eltwise type of post-ops by integrating with rvv_eltwise in init and execute methods.
  • Kept the original post_ops_ok and apply methods unchanged in a fused way, making other implementation used original version still correct.
  • Added comments about the original post_ops_ok and apply methods for other future implementations.
  • Currently supported post-ops:
    1. relu without alpha/beta (via original methods)
    2. Any eltwise operations the rvv_eltwise supported: relu with alpha/beta, square, abs, sqrt, linear, clip, hardsigmoid, and hardswish.
    3. Any binary operations: add, div, max, min, mul, sub, ge, gt, le, lt, eq, ne, and the ternary select.
  • Demonstrated functionality by adding primitive-style eltwise postop support to rvv_nchw_pooling

Future Plans (on-going)

  1. Update post-ops support for rvv_matmul in this primitive-based approach.
  2. Update post-ops support for rvv_gemm_convolution in this primitive-based approach.
  3. Remove the original post_ops_ok and apply methods safely.
  4. Add support for sum operations
  5. Extend data type supports.

Checklist

General

  • Do all unit and benchdnn tests (make test and make test_benchdnn_*) pass locally for each commit?

  • Have you formatted the code using clang-format?

  • test_postops_eltwise_ctest.log

Performance improvements

  • Have you submitted performance data that demonstrates performance improvements?

We test the changes using the RISC-V GNU toolchain(14.2) and verify the functionality under the sg2044 platform with cmd:

./tests/benchdnn/benchdnn --pool --dir=FWD_I --attr-post-ops=relu,square,abs,sqrt,linear:0.5:-1,clip,hardsigmoid,hardswish,add:f32,div:f32,mul:f32,max:f32,min:f32,sub:f32,ge:f32,gt:f32,le:f32,lt:f32,eq:f32,ne:f32,select:f32 --batch=../inputs/pool/shapes_basic

All tests passed with proper dispatching confirmed.

@zhangjian29 zhangjian29 requested a review from a team as a code owner November 4, 2025 09:27
@zhangjian29 zhangjian29 changed the title add-rvv-postops-eltwise cpu: rv64: postops: add rvv postops eltwise op support Nov 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant