forked from facebookarchive/fbcuda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
WarpReductionsTestBindings.cu
61 lines (45 loc) · 1.56 KB
/
WarpReductionsTestBindings.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
// Copyright 2004-present Facebook. All Rights Reserved.
#include "cuda/WarpReductionsTestBindings.cuh"
#include "cuda/WarpReductions.cuh"
#include <cuda.h>
#include <stdio.h>
using namespace std;
namespace facebook { namespace cuda {
__device__ int hasDuplicate[32];
__global__ void checkDuplicates(int num, int* v) {
hasDuplicate[threadIdx.x] = (int) warpHasCollision(v[threadIdx.x]);
}
__device__ unsigned int duplicateMask;
__global__ void checkDuplicateMask(int num, int* v) {
unsigned int mask = warpCollisionMask(v[threadIdx.x]);
if (threadIdx.x == 0) {
duplicateMask = mask;
}
}
vector<int> hostCheckDuplicates(const vector<int>& v) {
int* devSet = NULL;
cudaMalloc(&devSet, v.size() * sizeof(int));
cudaMemcpy(devSet, v.data(), v.size() * sizeof(int),
cudaMemcpyHostToDevice);
checkDuplicates<<<1, 32>>>(v.size(), devSet);
vector<int> hasDuplicates(32, false);
cudaMemcpyFromSymbol(hasDuplicates.data(),
hasDuplicate, sizeof(int) * 32, 0,
cudaMemcpyDeviceToHost);
cudaFree(devSet);
return hasDuplicates;
}
unsigned int hostCheckDuplicateMask(const vector<int>& v) {
int* devSet = NULL;
cudaMalloc(&devSet, v.size() * sizeof(int));
cudaMemcpy(devSet, v.data(), v.size() * sizeof(int),
cudaMemcpyHostToDevice);
checkDuplicateMask<<<1, 32>>>(v.size(), devSet);
unsigned int mask = 0;
cudaMemcpyFromSymbol(&mask,
duplicateMask, sizeof(unsigned int), 0,
cudaMemcpyDeviceToHost);
cudaFree(devSet);
return mask;
}
} }