Skip to content

Commit 172b9e2

Browse files
authored
Merge pull request #597 from ComputationalRadiationPhysics/release-0.3.3
Release 0.3.3
2 parents 847aed6 + 5c2263a commit 172b9e2

File tree

11 files changed

+771
-45
lines changed

11 files changed

+771
-45
lines changed

alpakaConfig.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,7 @@ LIST(APPEND _ALPAKA_LINK_LIBRARIES_PUBLIC "${_ALPAKA_LINK_LIBRARY}")
578578

579579
# Add all the source and include files in all recursive subdirectories and group them accordingly.
580580
append_recursive_files_add_to_src_group("${_ALPAKA_SUFFIXED_INCLUDE_DIR}" "${_ALPAKA_SUFFIXED_INCLUDE_DIR}" "hpp" _ALPAKA_FILES_HEADER)
581+
append_recursive_files_add_to_src_group("${_ALPAKA_SUFFIXED_INCLUDE_DIR}" "${_ALPAKA_SUFFIXED_INCLUDE_DIR}" "h" _ALPAKA_FILES_HEADER)
581582

582583
append_recursive_files_add_to_src_group("${_ALPAKA_ROOT_DIR}/script" "${_ALPAKA_ROOT_DIR}" "sh" _ALPAKA_FILES_SCRIPT)
583584
SET_SOURCE_FILES_PROPERTIES(${_ALPAKA_FILES_SCRIPT} PROPERTIES HEADER_FILE_ONLY TRUE)

appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ before_build:
138138
- cmd: if "%CONFIGURATION%"=="Release" set ALPAKA_BOOST_VARIANT=release
139139
# Select the libraries required.
140140
- cmd: set ALPAKA_BOOST_B2=--with-test
141-
- cmd: if "%ALPAKA_ACC_CPU_B_SEQ_T_FIBERS_ENABLE%"=="ON" set ALPAKA_BOOST_B2=%ALPAKA_BOOST_B2% --with-fiber --with-context --with-thread --with-system --with-atomic --with-chrono --with-date_time
141+
- cmd: if not "%ALPAKA_ACC_CPU_B_SEQ_T_FIBERS_ENABLE%"=="OFF" set ALPAKA_BOOST_B2=%ALPAKA_BOOST_B2% --with-fiber --with-context --with-thread --with-system --with-atomic --with-chrono --with-date_time
142142

143143
- cmd: if "%APPVEYOR_BUILD_WORKER_IMAGE%"=="Visual Studio 2017" set ALPAKA_BOOST_TOOLSET=msvc-14.1
144144
- cmd: b2 -j2 --toolset=%ALPAKA_BOOST_TOOLSET% --layout=versioned %ALPAKA_BOOST_B2% architecture=x86 address-model=%ALPAKA_BOOST_ADDRESS_MODEL% variant=%ALPAKA_BOOST_VARIANT% link=static threading=multi runtime-link=shared define=_CRT_NONSTDC_NO_DEPRECATE define=_CRT_SECURE_NO_DEPRECATE define=_SCL_SECURE_NO_DEPRECAT define=BOOST_USE_WINFIBERS --stagedir="%ALPAKA_B2_STAGE_DIR%"

include/alpaka/core/Unused.hpp

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/**
2+
* \file
3+
* Copyright 2018 Axel Huebl
4+
*
5+
* This file is part of alpaka.
6+
*
7+
* alpaka is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU Lesser General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* alpaka is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU Lesser General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Lesser General Public License
18+
* along with alpaka.
19+
* If not, see <http://www.gnu.org/licenses/>.
20+
*/
21+
22+
#pragma once
23+
24+
#include <alpaka/core/Common.hpp>
25+
26+
#include <boost/config.hpp>
27+
28+
namespace alpaka
29+
{
30+
ALPAKA_NO_HOST_ACC_WARNING
31+
template< typename... Ts >
32+
BOOST_FORCEINLINE
33+
BOOST_CXX14_CONSTEXPR
34+
ALPAKA_FN_HOST_ACC
35+
void
36+
ignore_unused( Ts const& ... )
37+
{}
38+
39+
ALPAKA_NO_HOST_ACC_WARNING
40+
template< typename... Ts >
41+
BOOST_FORCEINLINE
42+
BOOST_CXX14_CONSTEXPR
43+
ALPAKA_FN_HOST_ACC
44+
void
45+
ignore_unused()
46+
{}
47+
48+
} // namespace alpaka
49+

include/alpaka/rand/RandStl.hpp

Lines changed: 129 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@
2222
#pragma once
2323

2424
#include <alpaka/rand/Traits.hpp>
25+
#include <alpaka/rand/TinyMT/Engine.hpp>
2526

2627
#include <alpaka/core/Common.hpp>
28+
#include <alpaka/core/Unused.hpp>
2729

28-
#include <boost/core/ignore_unused.hpp>
29-
30+
#include <cstdint>
3031
#include <random>
3132
#include <type_traits>
3233

@@ -35,19 +36,38 @@ namespace alpaka
3536
namespace rand
3637
{
3738
//#############################################################################
38-
//! The standard library rand implementation.
39-
class RandStl
39+
//! "Tiny" state mersenne twister implementation
40+
class TinyMersenneTwister
4041
{
4142
public:
42-
using RandBase = RandStl;
43+
using RandBase = TinyMersenneTwister;
44+
};
45+
using RandStl = TinyMersenneTwister;
46+
47+
//#############################################################################
48+
//! The standard library mersenne twister implementation.
49+
class MersenneTwister
50+
{
51+
public:
52+
using RandBase = MersenneTwister;
53+
};
54+
55+
//#############################################################################
56+
//! The standard library rand device implementation.
57+
class RandomDevice
58+
{
59+
public:
60+
using RandBase = RandomDevice;
4361
};
4462

4563
namespace generator
4664
{
4765
namespace cpu
4866
{
4967
//#############################################################################
50-
//! The STL mersenne twister random number generator.
68+
//! The standard library mersenne twister random number generator.
69+
//!
70+
//! size of state: 19937 bytes
5171
class MersenneTwister
5272
{
5373
public:
@@ -68,6 +88,67 @@ namespace alpaka
6888
public:
6989
std::mt19937 m_State;
7090
};
91+
92+
//#############################################################################
93+
//! "Tiny" state mersenne twister implementation
94+
//!
95+
//! repository: github.com/MersenneTwister-Lab/TinyMT
96+
//!
97+
//! license: 3-clause BSD
98+
//!
99+
//! @author Mutsuo Saito (Hiroshima University)Tokio University.
100+
//! @author Makoto Matsumoto (The University of Tokyo)
101+
//!
102+
//! size of state: 28 bytes (127 bits?!)
103+
class TinyMersenneTwister
104+
{
105+
public:
106+
//-----------------------------------------------------------------------------
107+
TinyMersenneTwister() = default;
108+
109+
//-----------------------------------------------------------------------------
110+
ALPAKA_FN_ACC_NO_CUDA TinyMersenneTwister(
111+
std::uint32_t const & seed,
112+
std::uint32_t const & subsequence = 0,
113+
std::uint32_t const & offset = 0) :
114+
// NOTE: XOR the seed and the subsequence to generate a unique seed.
115+
m_State((seed ^ subsequence) + offset)
116+
{
117+
}
118+
119+
public:
120+
TinyMTengine m_State;
121+
};
122+
123+
//#############################################################################
124+
//! The standard library's random device based on the local entropy pool.
125+
//!
126+
//! Warning: the entropy pool on many devices degrates quickly and performance
127+
//! will drop significantly when this point occures.
128+
//!
129+
//! size of state: 1 byte
130+
class RandomDevice
131+
{
132+
public:
133+
//-----------------------------------------------------------------------------
134+
RandomDevice() = default;
135+
RandomDevice(RandomDevice&&) :
136+
m_State{}
137+
{
138+
}
139+
140+
//-----------------------------------------------------------------------------
141+
ALPAKA_FN_ACC_NO_CUDA RandomDevice(
142+
std::uint32_t const &,
143+
std::uint32_t const & = 0,
144+
std::uint32_t const & = 0) :
145+
m_State{}
146+
{
147+
}
148+
149+
public:
150+
std::random_device m_State;
151+
};
71152
}
72153
}
73154

@@ -166,7 +247,7 @@ namespace alpaka
166247
RandStl const & rand)
167248
-> rand::distribution::cpu::NormalReal<T>
168249
{
169-
boost::ignore_unused(rand);
250+
alpaka::ignore_unused(rand);
170251
return rand::distribution::cpu::NormalReal<T>();
171252
}
172253
};
@@ -185,7 +266,7 @@ namespace alpaka
185266
RandStl const & rand)
186267
-> rand::distribution::cpu::UniformReal<T>
187268
{
188-
boost::ignore_unused(rand);
269+
alpaka::ignore_unused(rand);
189270
return rand::distribution::cpu::UniformReal<T>();
190271
}
191272
};
@@ -204,7 +285,7 @@ namespace alpaka
204285
RandStl const & rand)
205286
-> rand::distribution::cpu::UniformUint<T>
206287
{
207-
boost::ignore_unused(rand);
288+
alpaka::ignore_unused(rand);
208289
return rand::distribution::cpu::UniformUint<T>();
209290
}
210291
};
@@ -218,21 +299,57 @@ namespace alpaka
218299
//! The CPU device random number default generator get trait specialization.
219300
template<>
220301
struct CreateDefault<
221-
RandStl>
302+
TinyMersenneTwister>
303+
{
304+
//-----------------------------------------------------------------------------
305+
ALPAKA_FN_ACC_NO_CUDA static auto createDefault(
306+
TinyMersenneTwister const & rand,
307+
std::uint32_t const & seed,
308+
std::uint32_t const & subsequence)
309+
-> rand::generator::cpu::TinyMersenneTwister
310+
{
311+
alpaka::ignore_unused(rand);
312+
return rand::generator::cpu::TinyMersenneTwister(
313+
seed,
314+
subsequence);
315+
}
316+
};
317+
318+
template<>
319+
struct CreateDefault<
320+
MersenneTwister>
222321
{
223322
//-----------------------------------------------------------------------------
224323
ALPAKA_FN_ACC_NO_CUDA static auto createDefault(
225-
RandStl const & rand,
324+
MersenneTwister const & rand,
226325
std::uint32_t const & seed,
227326
std::uint32_t const & subsequence)
228327
-> rand::generator::cpu::MersenneTwister
229328
{
230-
boost::ignore_unused(rand);
329+
alpaka::ignore_unused(rand);
231330
return rand::generator::cpu::MersenneTwister(
232331
seed,
233332
subsequence);
234333
}
235334
};
335+
336+
template<>
337+
struct CreateDefault<
338+
RandomDevice>
339+
{
340+
//-----------------------------------------------------------------------------
341+
ALPAKA_FN_ACC_NO_CUDA static auto createDefault(
342+
RandomDevice const & rand,
343+
std::uint32_t const & seed,
344+
std::uint32_t const & subsequence)
345+
-> rand::generator::cpu::RandomDevice
346+
{
347+
alpaka::ignore_unused(rand);
348+
return rand::generator::cpu::RandomDevice(
349+
seed,
350+
subsequence);
351+
}
352+
};
236353
}
237354
}
238355
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/**
2+
* \file
3+
* Copyright 2018 Axel Huebl
4+
*
5+
* This file is part of alpaka.
6+
*
7+
* alpaka is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU Lesser General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* alpaka is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU Lesser General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Lesser General Public License
18+
* along with alpaka.
19+
* If not, see <http://www.gnu.org/licenses/>.
20+
*/
21+
22+
#pragma once
23+
24+
#include <alpaka/rand/TinyMT/tinymt32.h>
25+
26+
#include <cstdint>
27+
28+
29+
namespace alpaka
30+
{
31+
namespace rand
32+
{
33+
namespace generator
34+
{
35+
namespace cpu
36+
{
37+
//! Implementation of std::UniformRandomBitGenerator for TinyMT32
38+
struct TinyMTengine
39+
{
40+
using result_type = std::uint32_t;
41+
42+
static constexpr result_type default_seed()
43+
{
44+
return 42u;
45+
}
46+
47+
void seed( result_type value = default_seed() )
48+
{
49+
// parameters from TinyMT/jump/sample.c
50+
prng.mat1 = 0x8f7011ee;
51+
prng.mat2 = 0xfc78ff1f;
52+
prng.tmat = 0x3793fdff;
53+
54+
tinymt32_init( &prng, value );
55+
}
56+
57+
TinyMTengine( std::uint32_t const & seedValue )
58+
{
59+
seed( seedValue );
60+
}
61+
62+
TinyMTengine()
63+
{
64+
std::uint32_t const magicSeed = 42u;
65+
seed( magicSeed );
66+
}
67+
68+
result_type operator()()
69+
{
70+
return tinymt32_generate_uint32( &prng );
71+
}
72+
73+
static constexpr result_type min()
74+
{
75+
return 0u;
76+
}
77+
78+
static constexpr result_type max()
79+
{
80+
return UINT32_MAX;
81+
}
82+
83+
void discard( unsigned long long ) // z
84+
{
85+
// not implemented
86+
// tinymt32_jump( &prng, z, z );
87+
}
88+
89+
tinymt32_t prng;
90+
};
91+
92+
} // namespace cpu
93+
} // namespace generator
94+
} // namespace rand
95+
} // namespace alpaka

0 commit comments

Comments
 (0)