Skip to content

[Tile] Fix complex interop with extended floating point types - #10550

Merged
miscco merged 2 commits into
NVIDIA:mainfrom
miscco:tile_complex
Jul 30, 2026
Merged

[Tile] Fix complex interop with extended floating point types#10550
miscco merged 2 commits into
NVIDIA:mainfrom
miscco:tile_complex

Conversation

@miscco

@miscco miscco commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

While we are at it also mark some of the cmath functions that clipped through as host device

@miscco
miscco requested a review from a team as a code owner July 30, 2026 11:40
@miscco
miscco requested a review from griwes July 30, 2026 11:40
@github-project-automation github-project-automation Bot moved this to Todo in CCCL Jul 30, 2026
@cccl-authenticator-app cccl-authenticator-app Bot moved this from Todo to In Review in CCCL Jul 30, 2026
@coderabbitai

coderabbitai Bot commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • Added complex-number utilities for half and bfloat16 values, including real, imag, conj, and proj.
    • Improved construction and assignment support between complex types.
    • Expanded host and device availability for half-precision mathematical operations.
  • Bug Fixes

    • Improved compatibility and execution behavior for complex and mathematical operations across host and device code.
  • Tests

    • Expanded host/device test coverage and updated tile-compilation expectations across complex and math functionality.

Walkthrough

Changes

The library now provides host/device-qualified half and bfloat16 math and complex operations, applies execution-check suppression to selected complex operations, and separates extended-floating-point complex conversions. Tests add host/device annotations, update force-tile expectations, and avoid unsupported half/bfloat16 tile instantiations.

Complex and math library interfaces

Layer / File(s) Summary
Complex and math library interfaces
libcudacxx/include/cuda/..., libcudacxx/include/cuda/std/...
Complex conversions and half/bfloat16 overloads were updated with host/device API attributes, execution-check suppression, and real, imag, conj, and proj implementations.

Host/device test coverage

Layer / File(s) Summary
Test annotation infrastructure
libcudacxx/test/support/test_macros.h, libcudacxx/test/libcudacxx/cuda/complex/...
Added TEST_HOST_DEVICE_FUNC and applied it to half/bfloat16 complex construction, assignment, and macro tests.
Scalar math tests
libcudacxx/test/libcudacxx/std/numerics/c.math/...
Math test helpers now use host/device annotations, force-tile expectations were updated, and selected half/bfloat16 tests are excluded from tile compilation.
Complex operation tests
libcudacxx/test/libcudacxx/std/numerics/complex.number/...
Complex operation and transcendental tests now use host/device helpers and mark force-tile configurations as unsupported with updated diagnostics.

Possibly related PRs

Suggested reviewers: griwes, ericniebler, jacobfaib


Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 3710ac2e-2c40-49a9-9cc2-021f5f7441ce

📥 Commits

Reviewing files that changed from the base of the PR and between 4bdb281 and 7d54466.

📒 Files selected for processing (53)
  • libcudacxx/include/cuda/__complex/get_real_imag.h
  • libcudacxx/include/cuda/std/__cmath/logarithms.h
  • libcudacxx/include/cuda/std/__cmath/modulo.h
  • libcudacxx/include/cuda/std/__cmath/rounding_functions.h
  • libcudacxx/include/cuda/std/__complex/complex.h
  • libcudacxx/include/cuda/std/__complex/nvbf16.h
  • libcudacxx/include/cuda/std/__complex/nvfp16.h
  • libcudacxx/test/libcudacxx/cuda/complex/half_bfloat/complex.assign.pass.cpp
  • libcudacxx/test/libcudacxx/cuda/complex/half_bfloat/complex.bad_macros.pass.cpp
  • libcudacxx/test/libcudacxx/cuda/complex/half_bfloat/complex.cons.pass.cpp
  • libcudacxx/test/libcudacxx/std/numerics/c.math/error_functions.pass.cpp
  • libcudacxx/test/libcudacxx/std/numerics/c.math/exponential_functions.pass.cpp
  • libcudacxx/test/libcudacxx/std/numerics/c.math/fdim.pass.cpp
  • libcudacxx/test/libcudacxx/std/numerics/c.math/fma.pass.cpp
  • libcudacxx/test/libcudacxx/std/numerics/c.math/gamma.pass.cpp
  • libcudacxx/test/libcudacxx/std/numerics/c.math/hyperbolic_functions.pass.cpp
  • libcudacxx/test/libcudacxx/std/numerics/c.math/hypot.pass.cpp
  • libcudacxx/test/libcudacxx/std/numerics/c.math/inverse_hyperbolic_functions.pass.cpp
  • libcudacxx/test/libcudacxx/std/numerics/c.math/inverse_trigonometric_functions.pass.cpp
  • libcudacxx/test/libcudacxx/std/numerics/c.math/logarithms.pass.cpp
  • libcudacxx/test/libcudacxx/std/numerics/c.math/modulo.pass.cpp
  • libcudacxx/test/libcudacxx/std/numerics/c.math/rounding.pass.cpp
  • libcudacxx/test/libcudacxx/std/numerics/complex.number/cmplx.over/arg.pass.cpp
  • libcudacxx/test/libcudacxx/std/numerics/complex.number/cmplx.over/norm.pass.cpp
  • libcudacxx/test/libcudacxx/std/numerics/complex.number/cmplx.over/pow.pass.cpp
  • libcudacxx/test/libcudacxx/std/numerics/complex.number/cmplx.over/proj.pass.cpp
  • libcudacxx/test/libcudacxx/std/numerics/complex.number/complex.member.ops/divide_equal_complex.pass.cpp
  • libcudacxx/test/libcudacxx/std/numerics/complex.number/complex.ops/complex_divide_complex.pass.cpp
  • libcudacxx/test/libcudacxx/std/numerics/complex.number/complex.ops/scalar_divide_complex.pass.cpp
  • libcudacxx/test/libcudacxx/std/numerics/complex.number/complex.transcendentals/acos.pass.cpp
  • libcudacxx/test/libcudacxx/std/numerics/complex.number/complex.transcendentals/acosh.pass.cpp
  • libcudacxx/test/libcudacxx/std/numerics/complex.number/complex.transcendentals/asin.pass.cpp
  • libcudacxx/test/libcudacxx/std/numerics/complex.number/complex.transcendentals/asinh.pass.cpp
  • libcudacxx/test/libcudacxx/std/numerics/complex.number/complex.transcendentals/atan.pass.cpp
  • libcudacxx/test/libcudacxx/std/numerics/complex.number/complex.transcendentals/atanh.pass.cpp
  • libcudacxx/test/libcudacxx/std/numerics/complex.number/complex.transcendentals/cos.pass.cpp
  • libcudacxx/test/libcudacxx/std/numerics/complex.number/complex.transcendentals/cosh.pass.cpp
  • libcudacxx/test/libcudacxx/std/numerics/complex.number/complex.transcendentals/exp.pass.cpp
  • libcudacxx/test/libcudacxx/std/numerics/complex.number/complex.transcendentals/log.pass.cpp
  • libcudacxx/test/libcudacxx/std/numerics/complex.number/complex.transcendentals/log10.pass.cpp
  • libcudacxx/test/libcudacxx/std/numerics/complex.number/complex.transcendentals/pow_complex_complex.pass.cpp
  • libcudacxx/test/libcudacxx/std/numerics/complex.number/complex.transcendentals/pow_complex_scalar.pass.cpp
  • libcudacxx/test/libcudacxx/std/numerics/complex.number/complex.transcendentals/pow_scalar_complex.pass.cpp
  • libcudacxx/test/libcudacxx/std/numerics/complex.number/complex.transcendentals/sin.pass.cpp
  • libcudacxx/test/libcudacxx/std/numerics/complex.number/complex.transcendentals/sinh.pass.cpp
  • libcudacxx/test/libcudacxx/std/numerics/complex.number/complex.transcendentals/sqrt.pass.cpp
  • libcudacxx/test/libcudacxx/std/numerics/complex.number/complex.transcendentals/tan.pass.cpp
  • libcudacxx/test/libcudacxx/std/numerics/complex.number/complex.transcendentals/tanh.pass.cpp
  • libcudacxx/test/libcudacxx/std/numerics/complex.number/complex.value.ops/abs.pass.cpp
  • libcudacxx/test/libcudacxx/std/numerics/complex.number/complex.value.ops/arg.pass.cpp
  • libcudacxx/test/libcudacxx/std/numerics/complex.number/complex.value.ops/norm.pass.cpp
  • libcudacxx/test/libcudacxx/std/numerics/complex.number/complex.value.ops/polar.pass.cpp
  • libcudacxx/test/support/test_macros.h

Comment on lines +98 to +116
template <class _Up,
enable_if_t<!__is_extended_floating_point_v<_Up>, int> = 0,
enable_if_t<__cccl_internal::__is_non_narrowing_convertible<_Tp, _Up>::value, int> = 0>
_CCCL_API constexpr complex(const complex<_Up>& __c)
: __re_(static_cast<_Tp>(__c.real()))
, __im_(static_cast<_Tp>(__c.imag()))
{}

template <class _Up,
enable_if_t<!__is_extended_floating_point_v<_Up>, int> = 0,
enable_if_t<!__cccl_internal::__is_non_narrowing_convertible<_Tp, _Up>::value, int> = 0,
enable_if_t<is_constructible_v<_Tp, _Up>, int> = 0>
_CCCL_API explicit constexpr complex(const complex<_Up>& __c)
: __re_(static_cast<_Tp>(__c.real()))
, __im_(static_cast<_Tp>(__c.imag()))
{}

template <class _Up, enable_if_t<__is_extended_floating_point_v<_Up>, int> = 0>
_CCCL_HOST_DEVICE_API complex(const complex<_Up>& __c);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

rg -n -C2 '_CCCL_TEMPLATE|_CCCL_REQUIRES' libcudacxx/include/cuda/std/__complex
rg -n -C2 '__is_extended_floating_point_v' libcudacxx/include/cuda/std

Repository: NVIDIA/cccl

Length of output: 16671


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

sed -n '1,180p' libcudacxx/include/cuda/std/__complex/complex.h
printf '\n---- nearby complex overload patterns ----\n'
rg -n -C2 '_CCCL_TEMPLATE|_CCCL_REQUIRES|enable_if_t<.*__is_extended_floating_point_v' libcudacxx/include/cuda/std/__complex

Repository: NVIDIA/cccl

Length of output: 13902


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

rg -n -C3 '_CCCL_TEMPLATE\(class _[A-Za-z0-9_]+\).*constructor|_CCCL_REQUIRES.*complex<|_CCCL_HOST_DEVICE_API.*complex<|_CCCL_TEMPLATE\(class _Up\)' libcudacxx/include/cuda/std | sed -n '1,220p'

Repository: NVIDIA/cccl

Length of output: 20892


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

sed -n '1,170p' libcudacxx/include/cuda/std/__complex/complex.h | cat -n

Repository: NVIDIA/cccl

Length of output: 7610


important: Replace these overload constraints with _CCCL_TEMPLATE/_CCCL_REQUIRES to match the rest of libcudacxx/include/cuda/std/__complex/complex.h; keep the implicit/explicit split and apply the same change to the assignment overloads below.

Source: Coding guidelines

Comment on lines +292 to +306
[[nodiscard]] _CCCL_HOST_DEVICE_API inline complex<__nv_bfloat16> conj(const complex<__nv_bfloat16>& __c)
{
return complex<__nv_bfloat16>(__c.real(), ::__hneg(__c.imag()));
}

[[nodiscard]] _CCCL_HOST_DEVICE_API inline complex<__nv_bfloat16> proj(const complex<__nv_bfloat16>& __c)
{
complex<__nv_bfloat16> __r = __c;
if (::cuda::std::isinf(__c.real()) || ::cuda::std::isinf(__c.imag()))
{
__r = complex<__nv_bfloat16>(
numeric_limits<__nv_bfloat16>::infinity(), ::cuda::std::copysign(::__float2bfloat16(0.0f), __c.imag()));
}
return __r;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win

important: Make these non-throwing overloads noexcept and use brace initialization for constructed complex values.

  • libcudacxx/include/cuda/std/__complex/nvbf16.h#L292-L306: mark conj and proj noexcept; replace complex<__nv_bfloat16>(...) with brace initialization.
  • libcudacxx/include/cuda/std/__complex/nvfp16.h#L292-L305: mark conj and proj noexcept; replace complex<__half>(...) with brace initialization.

As per coding guidelines, “Functions that do not throw exceptions must be marked noexcept” and “Use uniform initialization for class constructors.”

📍 Affects 2 files
  • libcudacxx/include/cuda/std/__complex/nvbf16.h#L292-L306 (this comment)
  • libcudacxx/include/cuda/std/__complex/nvfp16.h#L292-L305

Source: Coding guidelines

@github-actions

Copy link
Copy Markdown
Contributor

🥳 CI Workflow Results

🟩 Finished in 4h 07m: Pass: 100%/115 | Total: 6d 05h | Max: 4h 03m | Hits: 44%/2435910

See results here.

@miscco
miscco enabled auto-merge (squash) July 30, 2026 16:05
@miscco
miscco merged commit 843217a into NVIDIA:main Jul 30, 2026
139 checks passed
@miscco
miscco deleted the tile_complex branch July 30, 2026 18:00
@github-project-automation github-project-automation Bot moved this from In Review to Done in CCCL Jul 30, 2026
davebayer pushed a commit to davebayer/cccl that referenced this pull request Aug 4, 2026
…#10550)

* [Tile] Fix complex interop with extended floating point types

* [Tile] Mark more math functions as host device
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

2 participants