-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
90 lines (72 loc) · 3.04 KB
/
main.cpp
File metadata and controls
90 lines (72 loc) · 3.04 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include <bitset>
#include <iostream>
#include <iomanip>
#include <Kokkos_Core.hpp>
int main() {
Kokkos::initialize();
{
double values[] = {1.0, 1.1, 1.12, 1.123, 1.1234, 1.12345, 1.123456, 1.1234567, 1.12345678, 1.123456789,
0.1, 0.01, 0.001, 0.0001, 0.00001, 0.000001, 0.0000001, 0.00000001, 0.000000001, 0.0000000001,
10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000, 10000000000};
using double_t = Kokkos::View<double[30]>;
using float_t = Kokkos::View<float[30]>;
auto A = double_t("double_view");
auto B = float_t("float_view");
auto h_A = Kokkos::create_mirror_view(A);
auto h_B = Kokkos::create_mirror_view(B);
for (int i=0; i<30; ++i)
{
h_A(i) = values[i];
h_B(i) = values[i];
}
Kokkos::deep_copy(A, h_A);
Kokkos::deep_copy(B, h_B);
Kokkos::fence();
auto exp_A = double_t("exp_double");
auto h_exp_A = Kokkos::create_mirror_view(exp_A);
auto exp_B = float_t("exp_float");
auto h_exp_B = Kokkos::create_mirror_view(exp_B);
Kokkos::parallel_for("exp", 30, KOKKOS_LAMBDA (const int i)
{
exp_A(i) = exp( A(i) );
exp_B(i) = exp( B(i) );
});
Kokkos::fence();
Kokkos::deep_copy(h_exp_A, exp_A);
Kokkos::deep_copy(h_exp_B, exp_B);
Kokkos::fence();
std::cout << "* * * EXP DOUBLE / FLOAT * * *" << std::endl;
std::cout << "------------------------------" << std::endl;
for (int i=0; i<30; ++i)
{
std::cout << std::setprecision(17) << "exp(" << values[i] << ")=" << h_exp_A(i) << std::endl;
std::cout << std::setprecision(17) << "exp(" << values[i] << ")=" << h_exp_B(i) << std::endl;
std::cout << "exp(" << values[i] << ")=" << std::bitset<64>( *reinterpret_cast<std::uint64_t *> (&h_exp_A(i)) ) << std::endl;
std::cout << "exp(" << values[i] << ")=" << std::bitset<32>( *reinterpret_cast<std::uint32_t *> (&h_exp_B(i)) ) << std::endl;
}
auto sin_A = double_t("sin_double");
auto h_sin_A = Kokkos::create_mirror_view(sin_A);
auto sin_B = float_t("sin_float");
auto h_sin_B = Kokkos::create_mirror_view(sin_B);
Kokkos::parallel_for("sin", 30, KOKKOS_LAMBDA (const int i)
{
sin_A(i) = sin( A(i) );
sin_B(i) = sin( B(i) );
});
Kokkos::fence();
Kokkos::deep_copy(h_sin_A, sin_A);
Kokkos::deep_copy(h_sin_B, sin_B);
Kokkos::fence();
std::cout << "* * * SIN DOUBLE / FLOAT * * *" << std::endl;
std::cout << "------------------------------" << std::endl;
for (int i=0; i<30; ++i)
{
std::cout << std::setprecision(17) << "sin(" << values[i] << ")=" << h_sin_A(i) << std::endl;
std::cout << std::setprecision(17) << "sin(" << values[i] << ")=" << h_sin_B(i) << std::endl;
std::cout << "sin(" << values[i] << ")=" << std::bitset<64>( *reinterpret_cast<std::uint64_t *> (&h_sin_A(i)) ) << std::endl;
std::cout << "sin(" << values[i] << ")=" << std::bitset<32>( *reinterpret_cast<std::uint32_t *> (&h_sin_B(i)) ) << std::endl;
}
}
Kokkos::finalize();
return 0;
}