Skip to content

Add pushforwards for the Kokkos:: math functions. - #1899

Open
vgvassilev wants to merge 1 commit into
masterfrom
kokkos-math-pushforwards
Open

Add pushforwards for the Kokkos:: math functions.#1899
vgvassilev wants to merge 1 commit into
masterfrom
kokkos-math-pushforwards

Conversation

@vgvassilev

Copy link
Copy Markdown
Owner

Kokkos ships its own math functions (Kokkos::cos, Kokkos::sqrt, ...) so a kernel differentiates identically on host and device. clad has no registered derivatives for them, so it descends into the wrapper's body and trips an internal assertion instead of differentiating the call.

Register pushforwards for cos, sin, sqrt, and fabs in KokkosBuiltins.h, mirroring how BuiltinDerivatives.h handles the std:: math functions: clad now emits a call to the known derivative rather than cloning the wrapper. Reverse mode is synthesized from the same pushforward, so no pullback is added. The change is header-only: dispatch to clad::custom_derivatives::Kokkos::* is the path the View pushforwards in this header already use.

@vgvassilev
vgvassilev force-pushed the kokkos-math-pushforwards branch from c54e692 to f5b2d14 Compare July 17, 2026 10:41
@github-actions

Copy link
Copy Markdown
Contributor

clang-tidy review says "All clean, LGTM! 👍"

@codecov

codecov Bot commented Jul 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@vgvassilev
vgvassilev force-pushed the kokkos-math-pushforwards branch from f5b2d14 to 4c236ee Compare July 17, 2026 11:14
@github-actions

Copy link
Copy Markdown
Contributor

clang-tidy review says "All clean, LGTM! 👍"

Kokkos ships its own math functions (Kokkos::cos, Kokkos::sqrt, ...) so
a kernel differentiates identically on host and device. clad has no
registered derivatives for them, so it descends into the wrapper's body
and trips an internal assertion instead of differentiating the call.

Register pushforwards for cos, sin, and sqrt in KokkosBuiltins.h,
mirroring how BuiltinDerivatives.h handles the std:: math functions:
clad now emits a call to the known derivative rather than cloning the
wrapper. Reverse mode is synthesized from the same pushforward, so no
pullback is added. The change is header-only: dispatch to
clad::custom_derivatives::Kokkos::* is the path the View pushforwards in
this header already use. fabs is left out for now -- Kokkos::fabs is not
present in every supported Kokkos version.
@vgvassilev
vgvassilev force-pushed the kokkos-math-pushforwards branch from 4c236ee to 0370085 Compare July 17, 2026 11:24
@github-actions

Copy link
Copy Markdown
Contributor

clang-tidy review says "All clean, LGTM! 👍"

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