feat(cuda): fused scaledProdExp buffer op — exp((c·x)·y) in one kernel - #23
Open
NicolasRouquette wants to merge 2 commits into
Open
feat(cuda): fused scaledProdExp buffer op — exp((c·x)·y) in one kernel#23NicolasRouquette wants to merge 2 commits into
NicolasRouquette wants to merge 2 commits into
Conversation
NicolasRouquette
force-pushed
the
cuda-scaled-prod-exp
branch
2 times, most recently
from
August 3, 2026 18:01
74b09d3 to
bcebc07
Compare
Add `Buffer.scaledProdExp x y c = exp((c*x)*y)` as a single fused elementwise device kernel (`torchlean_scaled_prod_exp_f32`, exported via the existing binary+scalar macro) with the portable host-loop stub twin. It computes in fp32 with the same left-association as the composed `exp(mul(mul(full(c), x), y))`, so it is bit-identical to that four-op form while issuing one launch and allocating one result buffer instead of four. A *scaled product exponential* is the hot inner form of two-way extinction / propagation factors `exp(-2*κ*ℓ)` in computational electromagnetism and radar/optical remote sensing, and of Boltzmann-type weights `exp(-β*E*s)`; naming no problem domain, it is a portable primitive. Verified: nvcc compiles the kernel, cc compiles the stub, the `@[extern]` binding elaborates.
`Buffer.scaledProdExp x y c` is a single fused device kernel for `exp((c·x)·y)`. Add a CUDA kernel-coverage test asserting it is bit-identical — compared by `Float.toBits`, not a tolerance — to the composed form built from the `full` / `mul` / `exp` elementwise kernels, over signed/zero fixtures and a range of scalars. A fast-math `__expf`, a reassociated product, or a dropped float32 cast would fail it. Runs on the CPU stub (`lake build`) and on the GPU (`-K cuda`) alike; wired into the CUDA suite.
NicolasRouquette
force-pushed
the
cuda-scaled-prod-exp
branch
from
August 4, 2026 19:48
bcebc07 to
c84daa2
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Buffer.scaledProdExp x y ccomputesexp((c·x)·y)as a single fused elementwise device kernel (torchlean_scaled_prod_exp_f32, exported via the existing binary+scalar macro), with a portable host-loop stub twin. It computes in fp32 with the same left-association as the composedexp(mul(mul(full(c), x), y)), so it is bit-identical to that four-op form while issuing one launch and allocating one result buffer instead of four.Motivation
A scaled product exponential is the hot inner form of two-way extinction / propagation factors
exp(-2·κ·ℓ)in computational electromagnetism and radar/optical remote sensing, and of Boltzmann-type weightsexp(-β·E·s). It names no problem domain — a portable primitive a batched pipeline can fuse.Tests
NN/Tests/Runtime/Cuda/ScaledProdExp.lean(wired into the CUDA coverage suite) asserts the fused kernel is bit-identical to the composedexp(((full c)·x)·y)— compared byFloat.toBits, not a tolerance — across signed/zero fixtures and a range of scalars. A fast-math__expf, a reassociated product, or a dropped float32 cast would fail it. Like the rest of the suite it runs on the CPU stub (lake build) and on the GPU (-K cuda) alike.Verification
nvcccompiles the kernel;cccompiles the stub; the@[extern]binding elaborates.nn_tests_suite -K cuda=trueis green on an RTX A4500; the parity test above passes.