-
Notifications
You must be signed in to change notification settings - Fork 0
/
RDF_CU.cuh
211 lines (171 loc) · 3.82 KB
/
RDF_CU.cuh
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
#ifndef RDF_CU_CUH
#define RDF_CU_CUH
#include <npp.h>
#include <vector>
#include <random>
#include <rdf/feature.hpp>
#include <rdf/aggregator.hpp>
#include <rdf/node.hpp>
#include <thrust/sort.h>
#include <thrust/extrema.h>
#include <thrust/device_vector.h>
#include <thrust/execution_policy.h>
#include "../../include/rdf/depthImage.hpp"
#include "../../include/rdf/rgbImage.hpp"
#define NODE_NUM_LABELS 4
typedef struct {
// RDF Default Parameters
int numTrees;
int numImages;
int numPerTree;
int maxDepth;
int numSamples;
int numLabels;
int maxSpan;
int spaceSize;
int numFeatures;
int numTresholds;
// Utility Parameters
int sample_per_tree;
} RDF_CU_Param;
// CUDA Node Class
typedef struct {
int isSplit;
float4 feature;
float threshold;
size_t aggregator[NODE_NUM_LABELS];
int leftChild;
int rightChild;
} Node_CU;
class RDF_CU
{
public:
RDF_CU() {};
~RDF_CU() {};
// Function Section
void setParam(
RDF_CU_Param& params_
);
//void cu_init(
// int2* sample_coords,
// int* sample_labels,
// int* sample_depID,
// float4* features
// );
//void cu_dataTransfer(
// int2* sample_coords,
// int* sample_labels,
// int* sample_depID,
// float4* features
// );
//void cu_depth_init(
// int depth_image_num,
// int width_,
// int height_,
// float* depth_array
// );
void cu_initialize(
);
void cu_depth_const_upload(
int depth_image_num,
int width_,
int height_
);
//void cu_depthTransfer(
// float* depth_array
// );
void cu_featureTransfer(
float4 *features_
);
void cu_curLevel(
std::vector<int>& idx,
std::vector<int>& idx_S,
std::vector<int>& idx_E,
int op_nodes,
std::vector<rdf::Node>& nodes,
int recurseDepth
);
void cu_trainLevel(
std::vector<int>& idx,
std::vector<int>& idx_S,
std::vector<int>& idx_E,
std::vector<rdf::Node>& nodes,
int op_nodes,
int recurseDepth
);
float entropy_compute(
size_t* stat,
int boundary
);
bool shouldTerminate(
float maxGain,
int recurseDepth
);
void cu_train(
std::vector<rdf::Node>& nodes
);
void compute_responses(
std::vector<rdf::Sample>& samples_per_tree
);
void cu_reset();
void cu_free();
void host_free();
// Data Section
public:
// GPU Streams
cudaStream_t execStream;
cudaStream_t copyStream;
// GPU Arrays
int* cu_sapID;
int* cu_labels;
int* cu_thresh_num; // Number of thresholds per feature: 1 x featureNum
float* cu_response_array;
float* cu_thresh; // Generated thresholds: 1 x featureNum x (thresholdNum_default + 1)
float* cu_gain; // Gain for each threshold: 1 x featureNum x (thresholdNum_default + 1)
size_t* cu_partitionStatistics;
float4* cu_features;
// Batch GPU arrays (two-stream architecture)
int* cu_depID1;
int* cu_depID2;
int* cu_sequence1;
int* cu_sequence2;
int2* cu_coords1;
int2* cu_coords2;
float* cu_depth_array1;
float* cu_depth_array2;
// Host Arrays
thrust::host_vector<int> host_labels;
thrust::host_vector<int> host_sapID;
thrust::host_vector<float> host_response_array;
size_t* parentStatistics;
// Host Variables
int nodes_size;
int depth_num;
int width;
int height;
RDF_CU_Param params;
};
// Device functions
int queryDeviceParams(
char* query
);
int createCuContext(
bool displayDeviceInfo
);
void destroyCuContext();
// Inference functions
void upload_TreeInfo_Inf(
int numTrees_,
int numLabels_,
int maxDepth_,
int labelIndex_,
float minProb_,
std::vector<std::vector<Node_CU>>& forest_
);
void control_Inf(
std::vector<rdf::DepthImage>& depth_vector,
std::vector<rdf::RGBImage>& rgb_vecotr,
std::vector<std::vector<Node_CU>>& forest_CU,
bool forestInSharedMem
);
#endif