This repository has been archived by the owner on Dec 17, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
161 lines (125 loc) · 6.07 KB
/
main.cpp
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#include <bench_ntt.hpp>
#include <iomanip>
#include <iostream>
#include <test.hpp>
int main(int argc, char **argv) {
sycl::device d{sycl::default_selector{}};
sycl::queue q{d};
std::cout << "running on " << d.get_info<sycl::info::device::name>() << "\n"
<< std::endl;
#if defined TEST // only run test cases !
test_two_adic_root_of_unity();
test_get_root_of_unity();
std::cout << "passed prime field tests !" << std::endl;
// check with rectangular matrix
test_matrix_transposed_initialise(q, 1ul << 15, 1ul << 6);
std::cout << "passed matrix transposed initialisation tests ! [rectangular]" << std::endl;
// check with square matrix
test_matrix_transposed_initialise(q, 1ul << 16, 1ul << 6);
std::cout << "passed matrix transposed initialisation tests ! [square]" << std::endl;
// takes square matrix of dim x dim size, transposes twice
// finally asserts with original matrix
test_matrix_transpose(q, 1ul << 10, 1ul << 6);
std::cout << "passed matrix transposition tests !" << std::endl;
test_twiddle_multiplication(q, 1ul << 15, 1ul << 6);
std::cout << "passed twiddle multiplication tests ! [rectangular]" << std::endl;
test_twiddle_multiplication(q, 1ul << 16, 1ul << 6);
std::cout << "passed twiddle multiplication tests ! [square]" << std::endl;
test_six_step_fft_ifft(q, 1ul << 17, 1ul << 6);
std::cout << "passed fft/ifft tests !" << std::endl;
#elif defined BENCHMARK // only run benchmarks !
// FFT benchmark variations ( based on whether data transfer cost is included
// or not )
std::cout << "\nSix-Step FFT (without data transfer cost)\n" << std::endl;
std::cout << std::setw(11) << "dimension"
<< "\t\t" << std::setw(15) << "total" << std::endl;
for (uint dim = 16; dim <= 23; dim++) {
int64_t tm =
benchmark_six_step_fft(q, 1ul << dim, 1 << 6, data_transfer_t::none);
std::cout << std::setw(9) << std::right << (1ul << dim) << "\t\t"
<< std::setw(15) << std::right << (float)tm / 1000.f << " ms"
<< std::endl;
}
std::cout << "\nSix-Step FFT (with host -> device data transfer cost)\n"
<< std::endl;
std::cout << std::setw(11) << "dimension"
<< "\t\t" << std::setw(15) << "total" << std::endl;
for (uint dim = 16; dim <= 23; dim++) {
int64_t tm = benchmark_six_step_fft(q, 1ul << dim, 1 << 6,
data_transfer_t::only_host_to_device);
std::cout << std::setw(9) << std::right << (1ul << dim) << "\t\t"
<< std::setw(15) << std::right << (float)tm / 1000.f << " ms"
<< std::endl;
}
std::cout << "\nSix-Step FFT (with device -> host data transfer cost)\n"
<< std::endl;
std::cout << std::setw(11) << "dimension"
<< "\t\t" << std::setw(15) << "total" << std::endl;
for (uint dim = 16; dim <= 23; dim++) {
int64_t tm = benchmark_six_step_fft(q, 1ul << dim, 1 << 6,
data_transfer_t::only_device_to_host);
std::cout << std::setw(9) << std::right << (1ul << dim) << "\t\t"
<< std::setw(15) << std::right << (float)tm / 1000.f << " ms"
<< std::endl;
}
std::cout << "\nSix-Step FFT (with host <-> device data transfer cost)\n"
<< std::endl;
std::cout << std::setw(11) << "dimension"
<< "\t\t" << std::setw(15) << "total" << std::endl;
for (uint dim = 16; dim <= 23; dim++) {
int64_t tm =
benchmark_six_step_fft(q, 1ul << dim, 1 << 6, data_transfer_t::both);
std::cout << std::setw(9) << std::right << (1ul << dim) << "\t\t"
<< std::setw(15) << std::right << (float)tm / 1000.f << " ms"
<< std::endl;
}
// IFFT benchmark variations ( based on whether data transfer cost is included
// or not )
std::cout << "\nSix-Step IFFT (without data transfer cost)\n" << std::endl;
std::cout << std::setw(11) << "dimension"
<< "\t\t" << std::setw(15) << "total" << std::endl;
for (uint dim = 16; dim <= 23; dim++) {
int64_t tm =
benchmark_six_step_ifft(q, 1ul << dim, 1 << 6, data_transfer_t::none);
std::cout << std::setw(9) << std::right << (1ul << dim) << "\t\t"
<< std::setw(15) << std::right << (float)tm / 1000.f << " ms"
<< std::endl;
}
std::cout << "\nSix-Step IFFT (with host -> device data transfer cost)\n"
<< std::endl;
std::cout << std::setw(11) << "dimension"
<< "\t\t" << std::setw(15) << "total" << std::endl;
for (uint dim = 16; dim <= 23; dim++) {
int64_t tm = benchmark_six_step_ifft(q, 1ul << dim, 1 << 6,
data_transfer_t::only_host_to_device);
std::cout << std::setw(9) << std::right << (1ul << dim) << "\t\t"
<< std::setw(15) << std::right << (float)tm / 1000.f << " ms"
<< std::endl;
}
std::cout << "\nSix-Step IFFT (with device -> host data transfer cost)\n"
<< std::endl;
std::cout << std::setw(11) << "dimension"
<< "\t\t" << std::setw(15) << "total" << std::endl;
for (uint dim = 16; dim <= 23; dim++) {
int64_t tm = benchmark_six_step_ifft(q, 1ul << dim, 1 << 6,
data_transfer_t::only_device_to_host);
std::cout << std::setw(9) << std::right << (1ul << dim) << "\t\t"
<< std::setw(15) << std::right << (float)tm / 1000.f << " ms"
<< std::endl;
}
std::cout << "\nSix-Step IFFT (with host <-> device data transfer cost)\n"
<< std::endl;
std::cout << std::setw(11) << "dimension"
<< "\t\t" << std::setw(15) << "total" << std::endl;
for (uint dim = 16; dim <= 23; dim++) {
int64_t tm =
benchmark_six_step_ifft(q, 1ul << dim, 1 << 6, data_transfer_t::both);
std::cout << std::setw(9) << std::right << (1ul << dim) << "\t\t"
<< std::setw(15) << std::right << (float)tm / 1000.f << " ms"
<< std::endl;
}
#else // do nothing useful !
std::cout << "Check https://github.com/itzmeanjan/ff-p254-gpu/blob/288091435f7af607cf4681ebad54667effc4ecbc/Makefile#L8-L19" << std::endl;
#endif
return 0;
}