alpaka
Abstraction Library for Parallel Kernel Acceleration
Loading...
Searching...
No Matches
Traits.hpp
Go to the documentation of this file.
1/* Copyright 2023 Benjamin Worpitz, Bernhard Manfred Gruber, Jan Stephan
2 * SPDX-License-Identifier: MPL-2.0
3 */
4
5#pragma once
6
9
10#include <cstdint>
11#include <type_traits>
12
13namespace alpaka::rand
14{
16 {
17 };
18
19 //! The random number generator distribution specifics.
20 namespace distribution
21 {
22 //! The random number generator distribution trait.
23 namespace trait
24 {
25 //! The random number float normal distribution get trait.
26 template<typename TRand, typename T, typename TSfinae = void>
28
29 //! The random number float uniform distribution get trait.
30 template<typename TRand, typename T, typename TSfinae = void>
32
33 //! The random number integer uniform distribution get trait.
34 template<typename TRand, typename T, typename TSfinae = void>
36 } // namespace trait
37
38 //! \return A normal float distribution with mean 0.0f and standard deviation 1.0f.
40 template<typename T, typename TRand>
41 ALPAKA_FN_HOST_ACC auto createNormalReal(TRand const& rand)
42 {
43 static_assert(std::is_floating_point_v<T>, "The value type T has to be a floating point type!");
44
47 }
48
49 //! \return A uniform floating point distribution [0.0, 1.0).
51 template<typename T, typename TRand>
52 ALPAKA_FN_HOST_ACC auto createUniformReal(TRand const& rand)
53 {
54 static_assert(std::is_floating_point_v<T>, "The value type T has to be a floating point type!");
55
58 }
59
60 //! \return A uniform integer distribution [0, UINT_MAX].
62 template<typename T, typename TRand>
63 ALPAKA_FN_HOST_ACC auto createUniformUint(TRand const& rand)
64 {
65 static_assert(
66 std::is_integral_v<T> && std::is_unsigned_v<T>,
67 "The value type T has to be a unsigned integral type!");
68
71 }
72 } // namespace distribution
73
74 //! The random number generator engine specifics.
75 namespace engine
76 {
77 //! The random number generator engine trait.
78 namespace trait
79 {
80 //! The random number default generator engine get trait.
81 template<typename TRand, typename TSfinae = void>
83 } // namespace trait
84
85 //! \return A default random number generator engine. Its type is guaranteed to be trivially copyable.
86 //! Except HIP accelerator for HIP versions below 5.2 as its internal state was not trivially copyable.
87 //! The limitation was discussed in PR #1778.
89 template<typename TRand>
91 TRand const& rand,
92 std::uint32_t const& seed = 0,
93 std::uint32_t const& subsequence = 0,
94 std::uint32_t const& offset = 0)
95 {
97 return trait::CreateDefault<ImplementationBase>::createDefault(rand, seed, subsequence, offset);
98 }
99 } // namespace engine
100} // namespace alpaka::rand
#define ALPAKA_FN_HOST_ACC
Definition Common.hpp:39
#define ALPAKA_NO_HOST_ACC_WARNING
Disable nvcc warning: 'calling a host function from host device function.' Usage: ALPAKA_NO_HOST_ACC_...
Definition Common.hpp:82
typename detail::ImplementationBaseType< TInterface, TDerived >::type ImplementationBase
Returns the type that implements the given interface in the inheritance hierarchy.
Definition Interface.hpp:66
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC auto createNormalReal(TRand const &rand)
Definition Traits.hpp:41
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC auto createUniformUint(TRand const &rand)
Definition Traits.hpp:63
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC auto createUniformReal(TRand const &rand)
Definition Traits.hpp:52
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC auto createDefault(TRand const &rand, std::uint32_t const &seed=0, std::uint32_t const &subsequence=0, std::uint32_t const &offset=0)
Definition Traits.hpp:90
The random number float normal distribution get trait.
Definition Traits.hpp:27
The random number float uniform distribution get trait.
Definition Traits.hpp:31
The random number integer uniform distribution get trait.
Definition Traits.hpp:35
The random number default generator engine get trait.
Definition Traits.hpp:82