-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathminitest.cu
87 lines (78 loc) · 2.27 KB
/
minitest.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
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
// google test
#include "gtest/gtest.h"
// printf, scanf, puts, NULL
#include <stdio.h>
// std
#include <iostream>
// srand, rand
#include <stdlib.h>
// test helpers
#include "test_tools.h"
// gpu [log, exp, pow], cpu [log, ...], lib [log, ...]
#include "trans_functors.h"
// to use the functors on vectors
#include "functors.h"
// to use the cuda functors on vectors
#include "cufunctors.h"
// to use the tolerance checkers
#include "tolerance.h"
// to get infinity
#include <limits>
template<class G, class R>
void testCpuTolOn(
const std::vector<double> x,
const double tol,
G cpuFunctor,
R refFunctor
) {
std::vector<double> crClimValues = applyCpuOp1(x, cpuFunctor);
std::vector<double> expectedValues = applyCpuOp1(x, refFunctor);
verifyTol(expectedValues, crClimValues, x, tol);
}
template<class G, class R>
void testGpuTolOn(
const std::vector<double> x,
const double tol,
G gpuFunctor,
R refFunctor
) {
std::vector<double> crClimValues = applyGpuOp1(x, gpuFunctor);
std::vector<double> expectedValues = applyCpuOp1(x, refFunctor);
verifyTol(expectedValues, crClimValues, x, tol);
}
// =============================================================================
// THE TESTS
// =============================================================================
const size_t N = 1000*10;
const double TOL = 10E-10;
// =============================================================================
// TESTING THE LOGARITHM FUNCTIONS
// =============================================================================
void testCpuLogTolOn(
const std::vector<double> x,
const double tol
) {
testCpuTolOn(x, tol, CpuLog(), LibLog());
}
void testGpuLogTolOn(
const std::vector<double> x,
const double tol
) {
testGpuTolOn(x, tol, GpuLog(), LibLog());
}
TEST(LogCPUTest, PositiveValues) {
std::vector<double> x = randomFill(0, 100, N);
testCpuLogTolOn(x, TOL);
}
TEST(LogGPUTest, PositiveValues) {
std::vector<double> x = randomFill(0, 100, N);
testGpuLogTolOn(x, TOL);
}
// =============================================================================
// ENTRY POINT
// =============================================================================
int main(int argc, char **argv) {
//srand(time(NULL));
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}