Skip to content

Decompose Gelu and FastGelu into GeluCdf and FastGeluCdf, reformulating the - #1024

Merged
copybara-service[bot] merged 1 commit into
devfrom
test_978577053
Sep 10, 2026
Merged

Decompose Gelu and FastGelu into GeluCdf and FastGeluCdf, reformulating the#1024
copybara-service[bot] merged 1 commit into
devfrom
test_978577053

Conversation

@copybara-service

Copy link
Copy Markdown

Decompose Gelu and FastGelu into GeluCdf and FastGeluCdf, reformulating the
polynomial evaluation to reduce serial latency on SIMD execution units.

Original formulation evaluated:
v2 = Mul(v, v);
arg = Mul(v, MulAdd(kMul, v2, kSqrt2OverPi));
which incurs 3 serial multiplications (~12 cycles) before entering vector Tanh.

The optimized formulation evaluates:
v2 = Mul(v, v);
v_kMul = Mul(kMul, v);
v_kSqrt = Mul(kSqrt2OverPi, v);
arg = MulAdd(v_kMul, v2, v_kSqrt);
which executes both initial multiplications concurrently on independent FMA ports
in ~4 cycles, reducing the critical path to ~8 cycles (2 multiply steps).

Additionally exposes GeluCdf and FastGeluCdf to allow fused FFN callers to evaluate
gated activation kernels (e.g. Mul(c2, GeluCdf(d, c1))) directly without redundant
vector multiplications.

…ng the

polynomial evaluation to reduce serial latency on SIMD execution units.

Original formulation evaluated:
  v2 = Mul(v, v);
  arg = Mul(v, MulAdd(kMul, v2, kSqrt2OverPi));
which incurs 3 serial multiplications (~12 cycles) before entering vector Tanh.

The optimized formulation evaluates:
  v2 = Mul(v, v);
  v_kMul = Mul(kMul, v);
  v_kSqrt = Mul(kSqrt2OverPi, v);
  arg = MulAdd(v_kMul, v2, v_kSqrt);
which executes both initial multiplications concurrently on independent FMA ports
in ~4 cycles, reducing the critical path to ~8 cycles (2 multiply steps).

Additionally exposes GeluCdf and FastGeluCdf to allow fused FFN callers to evaluate
gated activation kernels (e.g. Mul(c2, GeluCdf(d, c1))) directly without redundant
vector multiplications.

PiperOrigin-RevId: 979091718
@copybara-service
copybara-service Bot merged commit 5321954 into dev Sep 10, 2026
6 checks passed
@copybara-service
copybara-service Bot deleted the test_978577053 branch September 10, 2026 10:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant