-
Notifications
You must be signed in to change notification settings - Fork 0
/
MWCNNLayerImpl.hpp
227 lines (179 loc) · 6.11 KB
/
MWCNNLayerImpl.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
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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
/* Copyright 2017-2018 The MathWorks, Inc. */
#ifndef CNN_API_IMPL
#define CNN_API_IMPL
#include <cudnn.h>
#include <cublas_v2.h>
#include <map>
#include <vector>
class MWTensor;
class MWCNNLayer;
class MWTargetNetworkImpl;
#define CUDA_CALL(status) cuda_call_line_file(status,__LINE__,__FILE__)
#define MALLOC_CALL(msize) malloc_call_line_file(msize,__LINE__,__FILE__)
#define CUDNN_CALL(status) cudnn_call_line_file(status,__LINE__,__FILE__)
#define CUBLAS_CALL(status) cublas_call_line_file(status,__LINE__,__FILE__)
//#define RANDOM
#ifdef RANDOM
#include <curand.h>
#define CURAND_CALL(status) curand_call_line_file(status,__LINE__,__FILE__)
#endif
void cuda_call_line_file(cudaError_t, const int, const char *);
void cudnn_call_line_file(cudnnStatus_t, const int, const char *);
float* malloc_call_line_file(size_t, const int, const char *);
const char* cublasGetErrorString(cublasStatus_t);
void cublas_call_line_file(cublasStatus_t, const int, const char *);
void call_cuda_free(float* mem);
void call_malloc(float* mem);
#ifdef RANDOM
void curand_call_line_file(curandStatus_t, const int, const char *);
#endif
class MWCNNLayerImpl
{
public :
MWCNNLayerImpl(MWCNNLayer* layer, MWTargetNetworkImpl* ntwk_impl);
virtual ~MWCNNLayerImpl();
virtual void predict() = 0;
virtual void cleanup() = 0;
void allocate(){}
virtual void postSetup() {}
float* getData() { return RAtlBpdedvgxUsgDTsch; }
MWCNNLayer* getLayer() { return dMxIKDGTITyhdLqIHBLA; }
protected:
MWCNNLayer* dMxIKDGTITyhdLqIHBLA;
std::map<int, cudnnTensorDescriptor_t*> lteHjcLsItGbVPMQtGDB; // output descriptor
MWTargetNetworkImpl* fYaOQTeunPwVjnhhTECh;
float SUleyRyvAggTFnSdxLru;
float SGsAudmgjmvcUXzzrUtf;
float SDWKEQTZaTFZByPlzUDR;
float* RAtlBpdedvgxUsgDTsch;
float* getZeroPtr(); // Get the pointer to a zero value parameter
float* getOnePtr(); // Get the pointer to a one value parameter
float* getNegOnePtr(); // Get the pointer to a negative one value parameter
protected:
cudnnTensorDescriptor_t* getOutputDescriptor(int index = 0); // Get the cuDNN descriptor for the output
cudnnTensorDescriptor_t* getCuDNNDescriptor(MWTensor* tensor); // get Descriptor from a tensor
void setData(float* data) {
RAtlBpdedvgxUsgDTsch = data;
}
public:
static void padInput(float* ,int ,int ,int ,int ,int ,int ,int ,float* ,int );
};
class MWInputLayerImpl : public MWCNNLayerImpl
{
private:
int dJcdBfQQLhIAYHPxwQeg;
float* IbSWJNMuIiKbocfQKqXb;
public:
MWInputLayerImpl(MWCNNLayer* layer,
MWTargetNetworkImpl* ntwk_impl,
int, int, int, int, int, const char* avg_file_name, int outbufIdx);
~MWInputLayerImpl();
void predict();
void cleanup();
private:
void createInputLayer(int, int, int, int, int, const char* avg_file_name, int outbufIdx);
void loadAvg(const char*, int);
private:
cudnnTensorDescriptor_t MIBnYCbKBdUrlfqlHdoo;
};
//ReLULayer
class MWReLULayerImpl: public MWCNNLayerImpl
{
public:
MWReLULayerImpl(MWCNNLayer* , MWTargetNetworkImpl*, int, int );
~MWReLULayerImpl();
void createReLULayer(int outbufIdx);
void predict();
void cleanup();
private:
cudnnActivationDescriptor_t olKGEIcsxmLSoMhRhEtP;
int XYbzSmRQGatVJtGmDZSo;
};
class MWNormLayerImpl: public MWCNNLayerImpl
{
public:
MWNormLayerImpl(MWCNNLayer*, MWTargetNetworkImpl*, unsigned, double, double, double, int outbufIdx);
~MWNormLayerImpl();
void createNormLayer(unsigned, double, double, double, int);
void predict();
void cleanup();
private:
cudnnLRNDescriptor_t fSbUUBgjKRbNXrHrlOLo;
};
//MaxPooling2DLayer
class MWMaxPoolingLayerImpl: public MWCNNLayerImpl
{
public:
//Create MaxPooling2DLayer with PoolSize = [ PoolH PoolW ]
// Stride = [ StrideH StrideW ]
// Padding = [ PaddingH_T PaddingH_B PaddingW_L PaddingW_R ]
MWMaxPoolingLayerImpl(MWCNNLayer *, MWTargetNetworkImpl*, int, int, int, int, int, int, int, int, bool, int, const std::vector<int>& bufIndices);
~MWMaxPoolingLayerImpl();
void predict();
void cleanup();
float* getIndexData();
private:
void createMaxPoolingLayer(int, int, int, int, int, int, int, int, int, const std::vector<int>& bufIndices );
private:
bool BRSPqxNffoBYKqpSVHne;
float* ZinudJuZuGitiNTsJpBR;
float* SIBpKtDURUWQaaenbwrC;
float* ZDWLzHUkuZuIUZHfbGDY;
cudnnPoolingDescriptor_t npGnQZLrEfVTQnEbwqij;
int enPbWLzEmxYCBmzGJutZ;
int euppfEoiaoCTcVgRPVhA;
};
//FullyConnectedLayer
class MWFCLayerImpl: public MWCNNLayerImpl
{
private:
int AzTsxYcYjIEJsGQbeYHm;
int BLjrjqvCcCommiXWQLjs;
int CpMjJjtGOeWOzwxpAAQP;
float* vjDFlBZzKvbpPseAtMBP;
float* MNuwXDSoGEYeABeVTwOh;
public:
MWFCLayerImpl(MWCNNLayer*, MWTargetNetworkImpl*, int, const char*, const char*, int);
~MWFCLayerImpl();
void createFCLayer(int, const char*, const char*, int);
void predict();
void cleanup();
private:
void loadWeights(int, const char*);
void loadBias(const char*);
private:
cudnnTensorDescriptor_t NMMfJylfQjiIUAKhXCJb;
};
//SoftmaxLayer
class MWSoftmaxLayerImpl: public MWCNNLayerImpl
{
public:
MWSoftmaxLayerImpl(MWCNNLayer* , MWTargetNetworkImpl*, int);
~MWSoftmaxLayerImpl();
void createSoftmaxLayer(int outbufIdx);
void predict();
void cleanup();
private:
cudnnLRNDescriptor_t fSbUUBgjKRbNXrHrlOLo;
};
//AvgPooling2DLayer
class MWAvgPoolingLayerImpl : public MWCNNLayerImpl
{
public:
MWAvgPoolingLayerImpl(MWCNNLayer*, MWTargetNetworkImpl*, int, int, int, int, int, int, int);
~MWAvgPoolingLayerImpl();
void createAvgPoolingLayer(int, int, int, int, int, int, int);
void predict();
void cleanup();
private:
cudnnPoolingDescriptor_t npGnQZLrEfVTQnEbwqij;
};
class MWOutputLayerImpl : public MWCNNLayerImpl {
public:
MWOutputLayerImpl(MWCNNLayer*, MWTargetNetworkImpl*, int);
~MWOutputLayerImpl();
void createOutputLayer();
void predict();
void cleanup();
};
#endif