Skip to content

mir: lower f32::atan{,2} / f64::atan{,2} via libdevice - #78

Closed
paulzhng wants to merge 1 commit into
NVIDIA:mainfrom
studio-vaai:feature/atan-support
Closed

paulzhng wants to merge 1 commit into
NVIDIA:mainfrom
studio-vaai:feature/atan-support

Conversation

@paulzhng

Copy link
Copy Markdown
Contributor

Closes #77

After this change, kernels can now write y.atan2(x) / x.atan() directly.
Before that, using these functions lead to a kernel compilation failure.

Kernels can now write `y.atan2(x)` / `x.atan()` directly.

Signed-off-by: Paul Zhang <[email protected]>
@nihalpasham

Copy link
Copy Markdown
Collaborator

Thanks for this, @paulzhng, LGTM.

Once #62 merged it overlapped the same RustFloatMathIntrinsic block, and your fork didn't have maintainer-edit enabled, so I rebased your commit onto main, verified it (GPU math_atan passes within 2 ULP; reverting the collector change reproduces the FORBIDDEN CRATE: std::sys::cmath::atanf failure), and brought it in as #109 with your commit preserved as-authored.

Closing in favor of #109. Appreciate it.

@nihalpasham nihalpasham closed this Jun 4, 2026
nihalpasham added a commit that referenced this pull request Jun 4, 2026
mir: lower f32::atan{,2} / f64::atan{,2} via libdevice (rebased #78)
@paulzhng
paulzhng deleted the feature/atan-support branch June 4, 2026 12:36
ianrgraham added a commit to ianrgraham/cuda-oxide that referenced this pull request Jun 4, 2026
…cbrt/hypot/…) to libdevice

f64/f32 methods like sqrt/sin/exp are core::intrinsics and already lower to __nv_*, but
the inverse-trig / hyperbolic / cbrt / hypot family are libm calls, not intrinsics:
- atan2/atan/asin/acos/sinh/cosh/tanh/asinh/acosh/atanh/expm1/log1p/hypot route through
  `std::sys::cmath` (extern "C") — which tripped the std-forbidden collector panic;
- cbrt (and other core_float_math) route through the bundled pure-Rust
  `core::num::imp::libm` — which was never collected ("symbol not found").

Fix, mirroring the existing core::intrinsics → __nv_ path:
1. collector: whitelist `std::sys::cmath::*` (SkipIntentional instead of the std-forbidden
   panic) — the wrapper isn't compiled; the call is redirected during lowering.
2. mir-lower call.rs: RustFloatMathIntrinsic::from_libm_symbol matches the legalized
   `std__sys__cmath__<fn>` and `core__num__imp__libm__<fn>` callees (prefix-stripped) and
   maps them to the corresponding `__nv_*` libdevice function, with f32/f64 + arg-count
   handling. Closes the atan2 gap (issues NVIDIA#77/NVIDIA#78).

Validated by gale's probe-libm (atan2/atan/asin/acos/sinh/cosh/tanh/hypot/cbrt vs host
std, worst rel 6.9e-15 on sm_70 Titan V).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
meefs pushed a commit to meefs/cuda-oxide that referenced this pull request Sep 30, 2026
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.

Add support for {f32,f64}::atan{,2}

2 participants