alpaka
Abstraction Library for Parallel Kernel Acceleration
Loading...
Searching...
No Matches
math.hpp
Go to the documentation of this file.
1/* Copyright 2025 René Widera
2 * SPDX-License-Identifier: MPL-2.0
3 */
4
5/** @file This file provides a basic implementation of a SIMD vector.
6 *
7 * The implementation is based on the class Vec:
8 * - the storge policy should become the native SIMD implementation e.g. std::simd
9 * - load/ store and simd specifis should be implemented in the storage policy
10 * - the name of storage policy should be changed
11 *
12 * The current operator operations relay on compilers auto vectorization.
13 */
14
15#pragma once
16
17#include "alpaka/Simd.hpp"
20
21#include <concepts>
22#include <type_traits>
23
25{
26
27 /** Specialize unary math function for SIMD types
28 *
29 * The implementation evaluates if the STL defines a math function for the native type used in the SIMD pack, if
30 * there is no STL math specialization available the alpaka math function will be called for each SIMD lane.
31 *
32 * @param className class name of the math trait within alpaka
33 * @param funcName math function name within STL
34 * @return SIMD pack with result of the math function for each lane
35 */
36#define ALPAKA_SIMD_MATH_UNARY_OP(className, funcName) \
37 template<typename T_MathImpl, alpaka::concepts::Simd T_Arg> \
38 struct className::Op<T_MathImpl, T_Arg> \
39 { \
40 constexpr auto operator()(T_MathImpl mathImpl, T_Arg const& arg) const -> T_Arg \
41 { \
42 using std::funcName; \
43 if constexpr(requires { funcName(arg.asNativeType()); }) \
44 { \
45 return T_Arg{funcName(arg.asNativeType())}; \
46 } \
47 else \
48 { \
49 T_Arg ret{}; \
50 for(uint32_t i = 0u; i < T_Arg::width(); i++) \
51 ret[i] = className::Op<T_MathImpl, ALPAKA_TYPEOF(arg[i])>{}(mathImpl, arg[i]); \
52 return ret; \
53 } \
54 } \
55 }
56
86
87#undef ALPAKA_SIMD_MATH_UNARY_OP
88} // namespace alpaka::math::internal
constexpr Complex< T > log(Complex< T > const &x)
Natural logarithm.
Definition Complex.hpp:462
constexpr Complex< T > acosh(Complex< T > const &x)
Arc hyperbolic cosine.
Definition Complex.hpp:392
constexpr Complex< T > sqrt(Complex< T > const &x)
Square root.
Definition Complex.hpp:535
constexpr Complex< T > tan(Complex< T > const &x)
Tangent.
Definition Complex.hpp:542
constexpr Complex< T > sinh(Complex< T > const &x)
Hyperbolic sine.
Definition Complex.hpp:528
constexpr Complex< T > tanh(Complex< T > const &x)
Hyperbolic tangent.
Definition Complex.hpp:549
constexpr T abs(Complex< T > const &x)
Host-only math functions matching std::complex<T>.
Definition Complex.hpp:378
constexpr Complex< T > atanh(Complex< T > const &x)
Arc hyperbolic tangent.
Definition Complex.hpp:427
constexpr Complex< T > sin(Complex< T > const &x)
Sine.
Definition Complex.hpp:521
constexpr Complex< T > atan(Complex< T > const &x)
Arc tangent.
Definition Complex.hpp:420
constexpr Complex< T > cos(Complex< T > const &x)
Cosine.
Definition Complex.hpp:441
constexpr Complex< T > asinh(Complex< T > const &x)
Arc hyperbolic sine.
Definition Complex.hpp:413
constexpr Complex< T > acos(Complex< T > const &x)
Arc cosine.
Definition Complex.hpp:385
constexpr Complex< T > exp(Complex< T > const &x)
Exponential.
Definition Complex.hpp:455
constexpr Complex< T > asin(Complex< T > const &x)
Arc sine.
Definition Complex.hpp:406
constexpr Complex< T > log10(Complex< T > const &x)
Base 10 logarithm.
Definition Complex.hpp:469
constexpr Complex< T > cosh(Complex< T > const &x)
Hyperbolic cosine.
Definition Complex.hpp:448
constexpr auto floor(auto const &arg)
Definition math.hpp:196
constexpr auto ceil(auto const &arg)
Definition math.hpp:87
constexpr auto isnan(auto const &arg)
Definition math.hpp:259
constexpr auto lround(auto const &arg)
Computes the nearest integer value to arg (in in integer format), rounding halfway cases away from ze...
Definition math.hpp:105
constexpr auto cbrt(auto const &arg)
Definition math.hpp:81
constexpr auto isinf(auto const &arg)
Definition math.hpp:57
constexpr auto log2(auto const &arg)
Computes the natural (base 2) logarithm of arg.
Definition math.hpp:220
constexpr auto trunc(auto const &arg)
Definition math.hpp:51
constexpr auto round(auto const &arg)
Computes the nearest integer value to arg (in floating-point format), rounding halfway cases away fro...
Definition math.hpp:96
constexpr auto erf(auto const &arg)
Definition math.hpp:190
constexpr auto isfinite(auto const &arg)
Definition math.hpp:63
constexpr auto llround(auto const &arg)
Computes the nearest integer value to arg (in in integer format), rounding halfway cases away from ze...
Definition math.hpp:114
#define ALPAKA_SIMD_MATH_UNARY_OP(className, funcName)
Specialize unary math function for SIMD types.
Definition math.hpp:36