deconv layer cudnn

This commit is contained in:
Francesco Gatti
2019-10-30 00:05:22 +01:00
parent 02936fa928
commit f9afee2f3b
7 changed files with 197 additions and 102 deletions
+27 -3
View File
@@ -11,6 +11,7 @@ namespace tk { namespace dnn {
enum layerType_t {
LAYER_DENSE,
LAYER_CONV2D,
LAYER_DECONV2D,
LAYER_ACTIVATION,
LAYER_FLATTEN,
LAYER_MULADD,
@@ -47,6 +48,7 @@ public:
switch(type) {
case LAYER_DENSE: return "Dense";
case LAYER_CONV2D: return "Conv2d";
case LAYER_DECONV2D: return "DeConv2d";
case LAYER_ACTIVATION: return "Activation";
case LAYER_FLATTEN: return "Flatten";
case LAYER_MULADD: return "MulAdd";
@@ -75,7 +77,7 @@ protected:
class LayerWgs : public Layer {
public:
LayerWgs(Network *net, int inputs, int outputs, int kh, int kw, int kt,
LayerWgs(Network *net, int inputs, int outputs, int kh, int kw, int kt,
std::string fname_weights, bool batchnorm = false);
virtual ~LayerWgs();
@@ -152,7 +154,7 @@ class Conv2d : public LayerWgs {
public:
Conv2d( Network *net, int out_ch, int kernelH, int kernelW,
int strideH, int strideW, int paddingH, int paddingW,
std::string fname_weights, bool batchnorm = false);
std::string fname_weights, bool batchnorm = false, bool deConv = false);
virtual ~Conv2d();
virtual layerType_t getLayerType() { return LAYER_CONV2D; };
@@ -163,11 +165,33 @@ public:
protected:
cudnnFilterDescriptor_t filterDesc;
cudnnConvolutionDescriptor_t convDesc;
cudnnConvolutionFwdAlgo_t algo;
cudnnConvolutionFwdAlgo_t fwAlgo;
cudnnConvolutionBwdDataAlgo_t bwAlgo;
cudnnTensorDescriptor_t biasTensorDesc;
void initCUDNN(bool back = false);
void inferCUDNN(dnnType* srcData, bool back = false);
void* workSpace;
size_t ws_sizeInBytes;
bool deConv;
};
/**
Convolutional 2D layer
*/
class DeConv2d : public Conv2d {
public:
DeConv2d( Network *net, int out_ch, int kernelH, int kernelW,
int strideH, int strideW, int paddingH, int paddingW,
std::string fname_weights, bool batchnorm = false) :
Conv2d(net, out_ch, kernelH, kernelW, strideH, strideW, paddingH, paddingW, fname_weights, batchnorm, true) {}
virtual ~DeConv2d() {}
virtual layerType_t getLayerType() { return LAYER_DECONV2D; };
virtual dnnType* infer(dataDim_t &dim, dnnType* srcData);
};
+1
View File
@@ -60,6 +60,7 @@ public:
dataDim_t getOutputDim();
bool fp16, dla;
bool dontLoadWeights;
};
}}
+1 -1
View File
@@ -90,7 +90,7 @@
void printCenteredTitle(const char *title, char fill, int dim);
bool fileExist(const char *fname);
void readBinaryFile(std::string fname, int size, dnnType** data_h, dnnType** data_d, int seek = 0);
void readBinaryFile(std::string fname, int size, dnnType** data_h, dnnType** data_d, int seek = 0, bool skipLoad = false);
int checkResult(int size, dnnType *data_d, dnnType *correct_d, bool device = true);
void printDeviceVector(int size, dnnType* vec_d, bool device = true);
void resize(int size, dnnType **data);