Skip to content

[Cherry-Pick][Operator Mechanism] Remove BLAS APIs only used on CPU - #79519

Merged
sneaxiy merged 2 commits into
PaddlePaddle:release/3.4from
feixi139:Paddle_release_removw_cpu_blas
Jul 22, 2026
Merged

[Cherry-Pick][Operator Mechanism] Remove BLAS APIs only used on CPU#79519
sneaxiy merged 2 commits into
PaddlePaddle:release/3.4from
feixi139:Paddle_release_removw_cpu_blas

Conversation

@feixi139

Copy link
Copy Markdown
Contributor

PR Category

Operator Mechanism

PR Types

Bug fixes

Description

本次移除了只在 CPU 侧使用的部分 BLAS wrapper API,并将对应调用点替换为 Eigen 或直接实现。

API 调用点数 替换方式
VSUB 1 EigenVector::Flatten 后使用 eigen_x - eigen_y
VDIV 1 EigenVector::Flatten 后使用 eigen_x / eigen_y
VEXP 2 Eigen::Map 后使用 array().exp()
VSQUARE 2 Eigen::Map 后使用 cwiseAbs2()
VPOW 1 Eigen::Map 后使用 array().pow()
VMUL 17 Eigen::Map 后使用 array() * array(),部分封装为 EigenVecMul
VINV 1 合并为 Eigen array().exp().cwiseInverse()
VMERF 2 改为 Eigen array().erf()
ASUM 0 无调用点,仅删除 wrapper 声明和实现

主要修改

paddle/phi/kernels/funcs/blas/blas.h

删除上述 CPU-only API 的 Blas 成员声明和 BlasT 转发接口。

paddle/phi/kernels/funcs/blas/blas_impl.h

删除上述 API 在 CPU BLAS wrapper 中的实现。

paddle/phi/kernels/cpu/elementwise.h

  • VSUBeigen_z.device(place) = eigen_x - eigen_y
  • VDIVeigen_z.device(place) = eigen_x / eigen_y
  • VMULeigen_z.device(place) = eigen_x * eigen_y

paddle/phi/kernels/cpu/attention_lstm_kernel.cc

  • 3 处 VMUL 替换为 Eigen::Map + array() * array()
  • 用于 forget gate、input gate、hidden output 的逐元素乘法

paddle/phi/kernels/cpu/gelu_grad_kernel.cc

  • VMERFEigen array().erf()
  • VSQUAREVEXPVMUL 合并为一个 Eigen 表达式:
exp(-0.5 * x.square()) * x

最后的 dout * first 也改为 Eigen 逐元素乘法。

paddle/phi/kernels/cpu/gelu_kernel.cc

  • VMERFEigen array().erf()
  • VMUL(x, out) 改为:
out_map = x_map * (1 + out_map) * 0.5;

paddle/phi/kernels/cpu/hsigmoid_loss_grad.h

VEXPVINV 合并为:

pre_out_grad_map = pre_out_map.array().exp().cwiseInverse();

paddle/phi/kernels/cpu/lrn_kernel.cc

  • VSQUAREinput_src.cwiseAbs2()

VPOWVMUL 合并为:

o_map = m_map.array().pow(-beta) * i_map.array();

paddle/phi/kernels/fusion/cpu/fused_embedding_fc_lstm_kernel.cc

  • 9 处 VMUL 提取为 EigenVecMul
  • EigenVecMul 内部实现:
x_map.array() * y_map.array()

devPR:#79513

是否引起精度变化

@paddle-bot

paddle-bot Bot commented Jul 21, 2026

Copy link
Copy Markdown

你的PR提交成功,感谢你对开源项目的贡献!
请关注后续CI自动化测试结果,详情请参考Paddle-CI手册
Your PR has been submitted. Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

@paddle-bot paddle-bot Bot added the contributor External developers label Jul 21, 2026
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (release/3.4@139d8ce). Learn more about missing BASE report.

Additional details and impacted files
@@               Coverage Diff               @@
##             release/3.4    #79519   +/-   ##
===============================================
  Coverage               ?   100.00%           
===============================================
  Files                  ?         3           
  Lines                  ?        33           
  Branches               ?         0           
===============================================
  Hits                   ?        33           
  Misses                 ?         0           
  Partials               ?         0           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sneaxiy sneaxiy left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@sneaxiy
sneaxiy merged commit 422f548 into PaddlePaddle:release/3.4 Jul 22, 2026
226 of 237 checks passed
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.

5 participants