TDLS 0.4.0
Tiny Device-callable Linear Solvers
Loading...
Searching...
No Matches
math.hpp File Reference

Scalar math helpers usable in constant expressions. More...

#include <cmath>
#include <tdls/core/macros.hpp>
#include <tdls/core/target.hpp>
Include dependency graph for math.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

template<typename T >
TDLS_HOST_DEVICE TDLS_FORCE_INLINE_GPU constexpr T tdls::detail::abs (const T x) noexcept
 Absolute value usable in constant expressions.
 
TDLS_HOST_DEVICE TDLS_FORCE_INLINE_GPU constexpr int tdls::detail::runtime_dimension (int v) noexcept
 A dimension hidden from the optimizer of nvcc when it compiles device code for Blackwell (sm_100 and later), the identity elsewhere.
 

Detailed Description

Scalar math helpers usable in constant expressions.

Author
Tristan Chenaille

Function Documentation

◆ abs()

template<typename T >
TDLS_HOST_DEVICE TDLS_FORCE_INLINE_GPU constexpr T tdls::detail::abs ( const T x)
nodiscardconstexprnoexcept

Absolute value usable in constant expressions.

std::fabs is not constexpr before C++23, so constant evaluation falls back to a ternary, indistinguishable from std::fabs in the magnitude comparisons of the solvers (signed zeros compare equal, NaNs propagate either way). At run time the function IS std::fabs: the naive ternary alone would forbid the single sign-bit instruction (it must preserve -0.0) and was measured 3% heavier in device code on the pivot search.

Template Parameters
Tscalar type
Parameters
[in]xvalue
Returns
the absolute value of x

◆ runtime_dimension()

TDLS_HOST_DEVICE TDLS_FORCE_INLINE_GPU constexpr int tdls::detail::runtime_dimension ( int v)
constexprnoexcept

A dimension hidden from the optimizer of nvcc when it compiles device code for Blackwell (sm_100 and later), the identity elsewhere.

nvcc miscompiles TiledLUppSolverDynamic for these targets when a dimension passed by the caller is a compile-time constant and propagates into its loops (TDLS issue #16). Every entry point of that solver passes its dimensions through this function first, so that the solver is compiled for a runtime dimension, as it is meant to be. The runtime solvers of CooperativeLUpp and ArrowheadLUpp were found correct; ArrowheadLUpp reaches TiledLUpp through these entry points. nvc++ compiles the solver correctly for these targets (checked with -stdpar=gpu for cc120), so the statement is limited to nvcc. The empty assembly statement costs no instruction.

Parameters
[in]vdimension
Returns
v