forked from facebookarchive/fbcuda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
WarpReductionsTest.cpp
91 lines (70 loc) · 1.73 KB
/
WarpReductionsTest.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
// Copyright 2004-present Facebook. All Rights Reserved.
#include "cuda/WarpReductionsTestBindings.cuh"
#include <gtest/gtest.h>
#include <iterator>
#include <stdlib.h>
#include <vector>
using namespace std;
namespace facebook { namespace cuda {
TEST(WarpReductions, collision) {
for (int numDups = 0; numDups < 32; ++numDups) {
vector<int> v;
for (int i = 0; i < 32 - numDups; ++i) {
int r = 0;
while (true) {
r = rand();
// C++11 std::find doesn't work with nvcc now
bool found = false;
for (int j = 0; j < v.size(); ++j) {
if (v[j] == r) {
found = true;
break;
}
}
if (!found) {
break;
}
}
v.push_back(r);
}
for (int i = 0; i < numDups; ++i) {
v.push_back(v[0]);
}
EXPECT_EQ(32, v.size());
auto dupCheck = hostCheckDuplicates(v);
for (auto dup : dupCheck) {
ASSERT_EQ((numDups > 0), dup);
}
}
}
TEST(WarpReductions, collisionMask) {
for (int numDups = 0; numDups < 32; ++numDups) {
vector<int> v;
for (int i = 0; i < 32 - numDups; ++i) {
int r = 0;
while (true) {
r = rand();
// C++11 std::find doesn't work with nvcc now
bool found = false;
for (int j = 0; j < v.size(); ++j) {
if (v[j] == r) {
found = true;
break;
}
}
if (!found) {
break;
}
}
v.push_back(r);
}
for (int i = 0; i < numDups; ++i) {
v.push_back(v[0]);
}
EXPECT_EQ(32, v.size());
auto mask = hostCheckDuplicateMask(v);
auto expected = numDups > 0 ? 0xffffffffU << (32 - numDups) : 0;
ASSERT_EQ(expected, mask);
}
}
} }