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
24namespace alpaka::math::internal
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
59 ALPAKA_SIMD_MATH_UNARY_OP(Acosh, acosh);
60 ALPAKA_SIMD_MATH_UNARY_OP(Asinh, asinh);
61 ALPAKA_SIMD_MATH_UNARY_OP(Sinh, sinh);
62 ALPAKA_SIMD_MATH_UNARY_OP(Atan, atan);
66 ALPAKA_SIMD_MATH_UNARY_OP(Atanh, atanh);
67 ALPAKA_SIMD_MATH_UNARY_OP(Tanh, tanh);
74 ALPAKA_SIMD_MATH_UNARY_OP(Sqrt, sqrt);
76 ALPAKA_SIMD_MATH_UNARY_OP(Cosh, cosh);
81 ALPAKA_SIMD_MATH_UNARY_OP(Log10, log10);
83 ALPAKA_SIMD_MATH_UNARY_OP(Acos, acos);
84 ALPAKA_SIMD_MATH_UNARY_OP(Asin, asin);
86
87#undef ALPAKA_SIMD_MATH_UNARY_OP
88} // namespace alpaka::math::internal
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