-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
123 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
__kernel void bitonic(__global float *as) { | ||
// TODO | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
// TODO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
#include <libgpu/context.h> | ||
#include <libgpu/shared_device_buffer.h> | ||
#include <libutils/misc.h> | ||
#include <libutils/timer.h> | ||
#include <libutils/fast_random.h> | ||
|
||
// Этот файл будет сгенерирован автоматически в момент сборки - см. convertIntoHeader в CMakeLists.txt:18 | ||
#include "cl/prefix_sum_cl.h" | ||
|
||
|
||
template<typename T> | ||
void raiseFail(const T &a, const T &b, std::string message, std::string filename, int line) | ||
{ | ||
if (a != b) { | ||
std::cerr << message << " But " << a << " != " << b << ", " << filename << ":" << line << std::endl; | ||
throw std::runtime_error(message); | ||
} | ||
} | ||
|
||
#define EXPECT_THE_SAME(a, b, message) raiseFail(a, b, message, __FILE__, __LINE__) | ||
|
||
|
||
int main(int argc, char **argv) | ||
{ | ||
int benchmarkingIters = 10; | ||
unsigned int max_n = (1 << 24); | ||
|
||
for (unsigned int n = 4096; n <= max_n; n *= 4) { | ||
std::cout << "______________________________________________" << std::endl; | ||
unsigned int values_range = std::min<unsigned int>(1023, std::numeric_limits<int>::max() / n); | ||
std::cout << "n=" << n << " values in range: [" << 0 << "; " << values_range << "]" << std::endl; | ||
|
||
std::vector<unsigned int> as(n, 0); | ||
FastRandom r(n); | ||
for (int i = 0; i < n; ++i) { | ||
as[i] = r.next(0, values_range); | ||
} | ||
|
||
std::vector<unsigned int> bs(n, 0); | ||
{ | ||
for (int i = 0; i < n; ++i) { | ||
bs[i] = as[i]; | ||
if (i) { | ||
bs[i] += bs[i-1]; | ||
} | ||
} | ||
} | ||
const std::vector<unsigned int> reference_result = bs; | ||
|
||
{ | ||
{ | ||
std::vector<unsigned int> result(n); | ||
for (int i = 0; i < n; ++i) { | ||
result[i] = as[i]; | ||
if (i) { | ||
result[i] += result[i-1]; | ||
} | ||
} | ||
for (int i = 0; i < n; ++i) { | ||
EXPECT_THE_SAME(reference_result[i], result[i], "CPU result should be consistent!"); | ||
} | ||
} | ||
|
||
std::vector<unsigned int> result(n); | ||
timer t; | ||
for (int iter = 0; iter < benchmarkingIters; ++iter) { | ||
for (int i = 0; i < n; ++i) { | ||
result[i] = as[i]; | ||
if (i) { | ||
result[i] += result[i-1]; | ||
} | ||
} | ||
t.nextLap(); | ||
} | ||
std::cout << "CPU: " << t.lapAvg() << "+-" << t.lapStd() << " s" << std::endl; | ||
std::cout << "CPU: " << (n / 1000.0 / 1000.0) / t.lapAvg() << " millions/s" << std::endl; | ||
} | ||
|
||
{ | ||
// TODO: implement on OpenCL | ||
} | ||
} | ||
} |