-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbasic.cu
55 lines (49 loc) · 1.75 KB
/
basic.cu
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <nvbench/nvbench.cuh>
#include <thrust/device_vector.h>
#include <thrust/execution_policy.h>
#include <thrust/random.h>
#include <thrust/sequence.h>
#include <thrust/shuffle.h>
template <typename T>
void basic(nvbench::state &state, nvbench::type_list<T>)
{
const auto elements = static_cast<std::size_t>(state.get_int64("Elements"));
thrust::device_vector<T> data(elements);
thrust::sequence(data.begin(), data.end());
state.add_element_count(elements);
state.add_global_memory_reads<T>(elements);
state.add_global_memory_writes<T>(elements);
auto do_engine = [&state, &data](auto &&engine) {
using namespace nvbench::exec_tag;
state.exec(sync, // thrust::shuffle syncs internally
[&engine, &data](nvbench::launch &launch) {
const auto policy = thrust::device.on(launch.get_stream());
thrust::shuffle(policy, data.begin(), data.end(), engine);
});
};
const auto rng_engine = state.get_string("Engine");
if (rng_engine == "minstd")
{
do_engine(thrust::random::minstd_rand{});
}
else if (rng_engine == "ranlux24")
{
do_engine(thrust::random::ranlux24{});
}
else if (rng_engine == "ranlux48")
{
do_engine(thrust::random::ranlux48{});
}
else if (rng_engine == "taus88")
{
do_engine(thrust::random::taus88{});
}
}
using types = nvbench::type_list<nvbench::uint8_t,
nvbench::uint16_t,
nvbench::uint32_t,
nvbench::uint64_t>;
NVBENCH_BENCH_TYPES(basic, NVBENCH_TYPE_AXES(types))
.set_name("thrust::shuffle")
.add_int64_power_of_two_axis("Elements", nvbench::range(16, 30, 2))
.add_string_axis("Engine", {"minstd", "ranlux24", "ranlux48", "taus88"});