forked from komrad36/BoxBlur
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
83 lines (69 loc) · 2.38 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
/*******************************************************************
* main.cpp
* BoxBlur
*
* Author: Kareem Omar
* https://github.com/komrad36
*
* Last updated Nov 3, 2016
*******************************************************************/
//
// Fastest CPU (AVX/SSE) implementation of a 128-pixel Box Blur.
//
// For even more speed see the CUDA version:
// github.com/komrad36/CUDABoxBlur
//
// All functionality is contained in BoxBlur.h.
// 'main.cpp' is a demo and test harness.
//
#include <chrono>
#include <cstdio>
#include <iostream>
#include "BoxBlur.h"
using namespace std::chrono;
int main() {
constexpr int width = 1920;
constexpr int height = 1080;
constexpr int warmups = 300;
constexpr int runs = 300;
constexpr bool multithread = true;
FILE* fp = fopen("test.bin", "rb");
if (fp == nullptr) {
std::cerr << "Failed to open test.bin. Aborting." << std::endl;
return EXIT_FAILURE;
}
uint8_t* const img = new uint8_t[4*width*height];
int ret = static_cast<int>(fread(img, 1, 4 * width*height, fp));
if (ret != 4*width*height) {
std::cerr << "Failed to read image. Aborting." << std::endl;
return EXIT_FAILURE;
}
uint8_t* const ref = new uint8_t[4 * (width - 128)*height];
uint8_t* const result = new uint8_t[4 * (width-128)*height];
_boxBlurref(img, width, 0, height, ref);
for (int i = 0; i < warmups; ++i) boxBlur<multithread>(img, width, height, result);
auto start = high_resolution_clock::now();
for (int i = 0; i < runs; ++i) boxBlur<multithread>(img, width, height, result);
auto end = high_resolution_clock::now();
size_t checktotal = 0ULL;
for (int i = 0; i < 4 * (width - 128)*height; ++i) {
checktotal += ref[i];
}
size_t total = 0ULL;
for (int i = 0; i < 4 * (width - 128)*height; ++i) {
total += result[i];
}
std::cout << "Checksum: " << total << std::endl;
for (int i = 0; i < 4 * (width - 128)*height; ++i) {
if (ref[i] != result[i]) {
std::cerr << "Disagreement at " << i << ". Expected " << +ref[i] << ", got " << +result[i] << std::endl;
//return EXIT_FAILURE;
}
}
if (total != checktotal) {
std::cerr << "ERROR: BAD CHECKSUM!" << std::endl;
}
const double us = static_cast<double>(duration_cast<nanoseconds>(end - start).count()) / static_cast<double>(runs) * 1e-3;
std::cout << "Time: " << us << " us." << std::endl;
}