This repository has been archived by the owner on Nov 9, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
hash_table.hpp
65 lines (52 loc) · 1.77 KB
/
hash_table.hpp
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
#ifndef PERMUTOHEDRAL_HASH_TABLE_HPP
#define PERMUTOHEDRAL_HASH_TABLE_HPP
#ifndef CPU_ONLY
#include "cuda_check.h"
#endif
namespace Permutohedral {
class HashTable
{
public:
int *table_entries;
unsigned int table_capacity;
signed short *table_keys;
bool create;
HashTable() : create(false) {}
void createHashTable(const int capacity, const int kd){
#ifndef CPU_ONLY
// TODO? use symbol to go in constant memory instead
// Initialize table_capacity
table_capacity = (unsigned int)capacity ;
// Initialize table_entries
CUDA_CHECK(cudaMalloc((void **) &table_entries, 2*capacity*sizeof(int)));
CUDA_CHECK(cudaMemset(table_entries, -1, 2*capacity*sizeof(int)));
// Initialize table_keys
CUDA_CHECK(cudaMalloc((void **) &table_keys, capacity*kd*sizeof(signed short)));
CUDA_CHECK(cudaMemset(table_keys, 0, capacity*kd*sizeof(signed short)));
// Set create to true
create = true;
#endif // CPU_ONLY
}
void resetHashTable(const int capacity, const int kd){
#ifndef CPU_ONLY
// TODO? use symbol to go in constant memory instead
// Initialize table_capacity
table_capacity = (unsigned int)capacity ;
// Reset table_entries
CUDA_CHECK(cudaMemset(table_entries, -1, 2*capacity*sizeof(int)));
// Resettable_keys
CUDA_CHECK(cudaMemset(table_keys, 0, capacity*kd*sizeof(signed short)));
#endif // CPU_ONLY
}
~HashTable(){
#ifndef CPU_ONLY
if(create){
// Free pointers allocated during
CUDA_CHECK(cudaFree(table_entries));
CUDA_CHECK(cudaFree(table_keys));
}
#endif //CPU_ONLY
}
};
}//namespace caffe
#endif //PERMUTOHEDRAL_HASH_TABLE_HPP