deconv layer cudnn
This commit is contained in:
+26
-2
@@ -11,6 +11,7 @@ namespace tk { namespace dnn {
|
|||||||
enum layerType_t {
|
enum layerType_t {
|
||||||
LAYER_DENSE,
|
LAYER_DENSE,
|
||||||
LAYER_CONV2D,
|
LAYER_CONV2D,
|
||||||
|
LAYER_DECONV2D,
|
||||||
LAYER_ACTIVATION,
|
LAYER_ACTIVATION,
|
||||||
LAYER_FLATTEN,
|
LAYER_FLATTEN,
|
||||||
LAYER_MULADD,
|
LAYER_MULADD,
|
||||||
@@ -47,6 +48,7 @@ public:
|
|||||||
switch(type) {
|
switch(type) {
|
||||||
case LAYER_DENSE: return "Dense";
|
case LAYER_DENSE: return "Dense";
|
||||||
case LAYER_CONV2D: return "Conv2d";
|
case LAYER_CONV2D: return "Conv2d";
|
||||||
|
case LAYER_DECONV2D: return "DeConv2d";
|
||||||
case LAYER_ACTIVATION: return "Activation";
|
case LAYER_ACTIVATION: return "Activation";
|
||||||
case LAYER_FLATTEN: return "Flatten";
|
case LAYER_FLATTEN: return "Flatten";
|
||||||
case LAYER_MULADD: return "MulAdd";
|
case LAYER_MULADD: return "MulAdd";
|
||||||
@@ -152,7 +154,7 @@ class Conv2d : public LayerWgs {
|
|||||||
public:
|
public:
|
||||||
Conv2d( Network *net, int out_ch, int kernelH, int kernelW,
|
Conv2d( Network *net, int out_ch, int kernelH, int kernelW,
|
||||||
int strideH, int strideW, int paddingH, int paddingW,
|
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 ~Conv2d();
|
||||||
virtual layerType_t getLayerType() { return LAYER_CONV2D; };
|
virtual layerType_t getLayerType() { return LAYER_CONV2D; };
|
||||||
|
|
||||||
@@ -163,11 +165,33 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
cudnnFilterDescriptor_t filterDesc;
|
cudnnFilterDescriptor_t filterDesc;
|
||||||
cudnnConvolutionDescriptor_t convDesc;
|
cudnnConvolutionDescriptor_t convDesc;
|
||||||
cudnnConvolutionFwdAlgo_t algo;
|
cudnnConvolutionFwdAlgo_t fwAlgo;
|
||||||
|
cudnnConvolutionBwdDataAlgo_t bwAlgo;
|
||||||
cudnnTensorDescriptor_t biasTensorDesc;
|
cudnnTensorDescriptor_t biasTensorDesc;
|
||||||
|
|
||||||
|
void initCUDNN(bool back = false);
|
||||||
|
void inferCUDNN(dnnType* srcData, bool back = false);
|
||||||
void* workSpace;
|
void* workSpace;
|
||||||
size_t ws_sizeInBytes;
|
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);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -60,6 +60,7 @@ public:
|
|||||||
dataDim_t getOutputDim();
|
dataDim_t getOutputDim();
|
||||||
|
|
||||||
bool fp16, dla;
|
bool fp16, dla;
|
||||||
|
bool dontLoadWeights;
|
||||||
};
|
};
|
||||||
|
|
||||||
}}
|
}}
|
||||||
|
|||||||
@@ -90,7 +90,7 @@
|
|||||||
|
|
||||||
void printCenteredTitle(const char *title, char fill, int dim);
|
void printCenteredTitle(const char *title, char fill, int dim);
|
||||||
bool fileExist(const char *fname);
|
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);
|
int checkResult(int size, dnnType *data_d, dnnType *correct_d, bool device = true);
|
||||||
void printDeviceVector(int size, dnnType* vec_d, bool device = true);
|
void printDeviceVector(int size, dnnType* vec_d, bool device = true);
|
||||||
void resize(int size, dnnType **data);
|
void resize(int size, dnnType **data);
|
||||||
|
|||||||
+142
-76
@@ -4,9 +4,121 @@
|
|||||||
|
|
||||||
namespace tk { namespace dnn {
|
namespace tk { namespace dnn {
|
||||||
|
|
||||||
|
void Conv2d::initCUDNN(bool back) {
|
||||||
|
|
||||||
|
cudnnTensorDescriptor_t srcTensor = srcTensorDesc;
|
||||||
|
cudnnTensorDescriptor_t dstTensor = dstTensorDesc;
|
||||||
|
|
||||||
|
dataDim_t idim, odim;
|
||||||
|
if(!back) {
|
||||||
|
idim = input_dim;
|
||||||
|
odim = output_dim;
|
||||||
|
} else {
|
||||||
|
idim = output_dim;
|
||||||
|
odim = input_dim;
|
||||||
|
}
|
||||||
|
idim.print();
|
||||||
|
odim.print();
|
||||||
|
|
||||||
|
checkCUDNN( cudnnCreateFilterDescriptor(&filterDesc) );
|
||||||
|
checkCUDNN( cudnnCreateConvolutionDescriptor(&convDesc) );
|
||||||
|
checkCUDNN( cudnnCreateTensorDescriptor(&biasTensorDesc) );
|
||||||
|
|
||||||
|
// input tensor dim
|
||||||
|
checkCUDNN( cudnnSetTensor4dDescriptor(srcTensor,
|
||||||
|
net->tensorFormat, net->dataType, idim.n, idim.c, idim.h, idim.w) );
|
||||||
|
|
||||||
|
checkCUDNN( cudnnSetFilter4dDescriptor(filterDesc,
|
||||||
|
net->dataType, net->tensorFormat, odim.c, idim.c,
|
||||||
|
kernelH, kernelW) );
|
||||||
|
|
||||||
|
checkCUDNN( cudnnSetConvolution2dDescriptor(convDesc,
|
||||||
|
paddingH, paddingW, // padding
|
||||||
|
strideH, strideW, // stride
|
||||||
|
1,1, // upscale
|
||||||
|
CUDNN_CROSS_CORRELATION, CUDNN_DATA_FLOAT) );
|
||||||
|
|
||||||
|
// check dimension of convolution output
|
||||||
|
dataDim_t tmpdim;
|
||||||
|
checkCUDNN( cudnnGetConvolution2dForwardOutputDim(
|
||||||
|
convDesc, srcTensor, filterDesc,
|
||||||
|
&tmpdim.n, &tmpdim.c, &tmpdim.h, &tmpdim.w) );
|
||||||
|
if(odim.n != tmpdim.n || odim.c != tmpdim.c || odim.h != tmpdim.h || odim.w != tmpdim.w) {
|
||||||
|
std::cout<<"tkdim: "; odim.print();
|
||||||
|
std::cout<<"cudnndim: "; tmpdim.print();
|
||||||
|
FatalError("Eror conv dimension mismatch");
|
||||||
|
}
|
||||||
|
|
||||||
|
checkCUDNN( cudnnSetTensor4dDescriptor(dstTensor,
|
||||||
|
net->tensorFormat, net->dataType, odim.n, odim.c, odim.h, odim.w) );
|
||||||
|
|
||||||
|
checkCUDNN( cudnnSetTensor4dDescriptor(biasTensorDesc,
|
||||||
|
net->tensorFormat, net->dataType,
|
||||||
|
1, output_dim.c, 1, 1) );
|
||||||
|
|
||||||
|
// init workspace
|
||||||
|
workSpace = NULL;
|
||||||
|
ws_sizeInBytes = 0;
|
||||||
|
if(back) {
|
||||||
|
checkCUDNN( cudnnGetConvolutionBackwardDataAlgorithm(net->cudnnHandle,
|
||||||
|
filterDesc, dstTensor, convDesc, srcTensor,
|
||||||
|
CUDNN_CONVOLUTION_BWD_DATA_PREFER_FASTEST, 0, &bwAlgo) );
|
||||||
|
checkCUDNN(cudnnGetConvolutionBackwardDataWorkspaceSize(net->cudnnHandle,
|
||||||
|
filterDesc, dstTensor, convDesc, srcTensor,
|
||||||
|
bwAlgo, &ws_sizeInBytes));
|
||||||
|
|
||||||
|
// invert tensors
|
||||||
|
srcTensorDesc = dstTensor;
|
||||||
|
dstTensorDesc = srcTensor;
|
||||||
|
} else {
|
||||||
|
checkCUDNN( cudnnGetConvolutionForwardAlgorithm(net->cudnnHandle,
|
||||||
|
srcTensor, filterDesc, convDesc, dstTensor,
|
||||||
|
CUDNN_CONVOLUTION_FWD_PREFER_FASTEST, 0, &fwAlgo) );
|
||||||
|
checkCUDNN(cudnnGetConvolutionForwardWorkspaceSize(net->cudnnHandle,
|
||||||
|
srcTensor, filterDesc, convDesc, dstTensor,
|
||||||
|
fwAlgo, &ws_sizeInBytes));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Conv2d::inferCUDNN(dnnType* srcData, bool back) {
|
||||||
|
|
||||||
|
dnnType alpha = dnnType(1);
|
||||||
|
dnnType beta = dnnType(0);
|
||||||
|
if(back) {
|
||||||
|
checkCUDNN(cudnnConvolutionBackwardData(net->cudnnHandle,
|
||||||
|
&alpha, filterDesc, data_d,
|
||||||
|
srcTensorDesc, srcData,
|
||||||
|
convDesc, bwAlgo, workSpace, ws_sizeInBytes,
|
||||||
|
&beta, dstTensorDesc, dstData));
|
||||||
|
} else {
|
||||||
|
checkCUDNN(cudnnConvolutionForward(net->cudnnHandle,
|
||||||
|
&alpha, srcTensorDesc, srcData, filterDesc,
|
||||||
|
data_d, convDesc, fwAlgo, workSpace, ws_sizeInBytes,
|
||||||
|
&beta, dstTensorDesc, dstData));
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!batchnorm) {
|
||||||
|
// bias
|
||||||
|
alpha = dnnType(1);
|
||||||
|
beta = dnnType(0);
|
||||||
|
checkCUDNN( cudnnAddTensor(net->cudnnHandle,
|
||||||
|
&alpha, biasTensorDesc, bias_d,
|
||||||
|
&beta, dstTensorDesc, dstData) );
|
||||||
|
} else {
|
||||||
|
alpha = dnnType(1);
|
||||||
|
beta = dnnType(0);
|
||||||
|
cudnnBatchNormalizationForwardInference(net->cudnnHandle,
|
||||||
|
CUDNN_BATCHNORM_SPATIAL, &alpha, &beta,
|
||||||
|
dstTensorDesc, dstData, dstTensorDesc,
|
||||||
|
dstData, biasTensorDesc, //same tensor descriptor as bias
|
||||||
|
scales_d, bias_d, mean_d, variance_d,
|
||||||
|
CUDNN_BN_MIN_EPSILON);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Conv2d::Conv2d( Network *net, int out_ch, int kernelH, int kernelW,
|
Conv2d::Conv2d( Network *net, int out_ch, int kernelH, int kernelW,
|
||||||
int strideH, int strideW, int paddingH, int paddingW,
|
int strideH, int strideW, int paddingH, int paddingW,
|
||||||
std::string fname_weights, bool batchnorm) :
|
std::string fname_weights, bool batchnorm, bool deConv) :
|
||||||
|
|
||||||
LayerWgs(net, net->getOutputDim().c, out_ch, kernelH, kernelW, 1,
|
LayerWgs(net, net->getOutputDim().c, out_ch, kernelH, kernelW, 1,
|
||||||
fname_weights, batchnorm) {
|
fname_weights, batchnorm) {
|
||||||
@@ -17,64 +129,28 @@ Conv2d::Conv2d( Network *net, int out_ch, int kernelH, int kernelW,
|
|||||||
this->strideW = strideW;
|
this->strideW = strideW;
|
||||||
this->paddingH = paddingH;
|
this->paddingH = paddingH;
|
||||||
this->paddingW = paddingW;
|
this->paddingW = paddingW;
|
||||||
|
this->deConv = deConv;
|
||||||
|
|
||||||
checkCUDNN( cudnnCreateFilterDescriptor(&filterDesc) );
|
if(!deConv) {
|
||||||
checkCUDNN( cudnnCreateConvolutionDescriptor(&convDesc) );
|
output_dim.n = input_dim.n;
|
||||||
checkCUDNN( cudnnCreateTensorDescriptor(&biasTensorDesc) );
|
output_dim.c = out_ch;
|
||||||
|
output_dim.h = (input_dim.h + 2 * paddingH - kernelH) / strideH + 1;
|
||||||
int n = input_dim.n;
|
output_dim.w = (input_dim.w + 2 * paddingW - kernelW) / strideW + 1;
|
||||||
int c = input_dim.c;
|
output_dim.l = 1;
|
||||||
int h = input_dim.h;
|
} else {
|
||||||
int w = input_dim.w;
|
output_dim.n = input_dim.n;
|
||||||
|
output_dim.c = out_ch;
|
||||||
checkCUDNN( cudnnSetTensor4dDescriptor(srcTensorDesc,
|
output_dim.h = (input_dim.h * strideH) - 2*paddingH + kernelH -1;
|
||||||
net->tensorFormat, net->dataType, n, c, h, w) );
|
output_dim.w = (input_dim.w * strideW) - 2*paddingW + kernelW -1;
|
||||||
|
output_dim.l = 1;
|
||||||
checkCUDNN( cudnnSetFilter4dDescriptor(filterDesc,
|
}
|
||||||
net->dataType, net->tensorFormat, out_ch, input_dim.c,
|
initCUDNN(deConv);
|
||||||
kernelH, kernelW) );
|
|
||||||
|
|
||||||
checkCUDNN( cudnnSetConvolution2dDescriptor(convDesc,
|
|
||||||
paddingH, paddingW, // padding
|
|
||||||
strideH, strideW, // stride
|
|
||||||
1,1, // upscale
|
|
||||||
CUDNN_CROSS_CORRELATION, CUDNN_DATA_FLOAT) );
|
|
||||||
|
|
||||||
// find dimension of convolution output
|
|
||||||
checkCUDNN( cudnnGetConvolution2dForwardOutputDim(
|
|
||||||
convDesc, srcTensorDesc, filterDesc,
|
|
||||||
&n, &c, &h, &w) );
|
|
||||||
|
|
||||||
checkCUDNN( cudnnSetTensor4dDescriptor(dstTensorDesc,
|
|
||||||
net->tensorFormat, net->dataType, n, c, h, w) );
|
|
||||||
|
|
||||||
checkCUDNN( cudnnGetConvolutionForwardAlgorithm(net->cudnnHandle,
|
|
||||||
srcTensorDesc, filterDesc, convDesc, dstTensorDesc,
|
|
||||||
CUDNN_CONVOLUTION_FWD_PREFER_FASTEST, 0, &algo) );
|
|
||||||
|
|
||||||
workSpace = NULL;
|
|
||||||
ws_sizeInBytes = 0;
|
|
||||||
|
|
||||||
checkCUDNN( cudnnGetConvolutionForwardWorkspaceSize(net->cudnnHandle,
|
|
||||||
srcTensorDesc, filterDesc, convDesc, dstTensorDesc,
|
|
||||||
algo, &ws_sizeInBytes) );
|
|
||||||
|
|
||||||
|
// allocate warkspace
|
||||||
if (ws_sizeInBytes!=0) {
|
if (ws_sizeInBytes!=0) {
|
||||||
checkCuda( cudaMalloc(&workSpace, ws_sizeInBytes) );
|
checkCuda( cudaMalloc(&workSpace, ws_sizeInBytes) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
checkCUDNN( cudnnSetTensor4dDescriptor(biasTensorDesc,
|
|
||||||
net->tensorFormat, net->dataType,
|
|
||||||
1, out_ch, 1, 1) );
|
|
||||||
|
|
||||||
|
|
||||||
output_dim.n = n;
|
|
||||||
output_dim.c = c;
|
|
||||||
output_dim.h = h;
|
|
||||||
output_dim.w = w;
|
|
||||||
output_dim.l = 1;
|
|
||||||
|
|
||||||
//allocate data for infer result
|
//allocate data for infer result
|
||||||
checkCuda( cudaMalloc(&dstData, output_dim.tot()*sizeof(dnnType)) );
|
checkCuda( cudaMalloc(&dstData, output_dim.tot()*sizeof(dnnType)) );
|
||||||
}
|
}
|
||||||
@@ -93,35 +169,25 @@ Conv2d::~Conv2d() {
|
|||||||
|
|
||||||
dnnType* Conv2d::infer(dataDim_t &dim, dnnType* srcData) {
|
dnnType* Conv2d::infer(dataDim_t &dim, dnnType* srcData) {
|
||||||
|
|
||||||
|
if(deConv) {
|
||||||
|
FatalError("you must use DeConv class for Deconvolutional layers");
|
||||||
|
}
|
||||||
|
|
||||||
// convolution
|
// convolution
|
||||||
dnnType alpha = dnnType(1);
|
inferCUDNN(srcData, false);
|
||||||
dnnType beta = dnnType(0);
|
|
||||||
checkCUDNN( cudnnConvolutionForward(net->cudnnHandle,
|
|
||||||
&alpha, srcTensorDesc, srcData, filterDesc,
|
|
||||||
data_d, convDesc, algo, workSpace, ws_sizeInBytes,
|
|
||||||
&beta, dstTensorDesc, dstData) );
|
|
||||||
|
|
||||||
if(!batchnorm) {
|
|
||||||
// bias
|
|
||||||
alpha = dnnType(1);
|
|
||||||
beta = dnnType(1);
|
|
||||||
checkCUDNN( cudnnAddTensor(net->cudnnHandle,
|
|
||||||
&alpha, biasTensorDesc, bias_d,
|
|
||||||
&beta, dstTensorDesc, dstData) );
|
|
||||||
} else {
|
|
||||||
float one = 1;
|
|
||||||
float zero = 0;
|
|
||||||
cudnnBatchNormalizationForwardInference(net->cudnnHandle,
|
|
||||||
CUDNN_BATCHNORM_SPATIAL, &one, &zero,
|
|
||||||
dstTensorDesc, dstData, dstTensorDesc,
|
|
||||||
dstData, biasTensorDesc, //same tensor descriptor as bias
|
|
||||||
scales_d, bias_d, mean_d, variance_d,
|
|
||||||
CUDNN_BN_MIN_EPSILON);
|
|
||||||
}
|
|
||||||
//update data dimensions
|
//update data dimensions
|
||||||
dim = output_dim;
|
dim = output_dim;
|
||||||
|
return dstData;
|
||||||
|
}
|
||||||
|
|
||||||
|
dnnType* DeConv2d::infer(dataDim_t &dim, dnnType* srcData) {
|
||||||
|
|
||||||
|
// convolution
|
||||||
|
inferCUDNN(srcData, true);
|
||||||
|
|
||||||
|
//update data dimensions
|
||||||
|
dim = output_dim;
|
||||||
return dstData;
|
return dstData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+5
-5
@@ -16,18 +16,18 @@ LayerWgs::LayerWgs(Network *net, int inputs, int outputs,
|
|||||||
|
|
||||||
std::cout<<"Reading weights: I="<<inputs<<" O="<<outputs<<" KERNEL="<<kh<<"x"<<kw<<"x"<<kl<<"\n";
|
std::cout<<"Reading weights: I="<<inputs<<" O="<<outputs<<" KERNEL="<<kh<<"x"<<kw<<"x"<<kl<<"\n";
|
||||||
int seek = 0;
|
int seek = 0;
|
||||||
readBinaryFile(weights_path.c_str(), inputs*outputs*kh*kw*kl, &data_h, &data_d, seek);
|
readBinaryFile(weights_path.c_str(), inputs*outputs*kh*kw*kl, &data_h, &data_d, seek, net->dontLoadWeights);
|
||||||
seek += inputs*outputs*kh*kw*kl;
|
seek += inputs*outputs*kh*kw*kl;
|
||||||
readBinaryFile(weights_path.c_str(), outputs, &bias_h, &bias_d, seek);
|
readBinaryFile(weights_path.c_str(), outputs, &bias_h, &bias_d, seek, net->dontLoadWeights);
|
||||||
|
|
||||||
this->batchnorm = batchnorm;
|
this->batchnorm = batchnorm;
|
||||||
if(batchnorm) {
|
if(batchnorm) {
|
||||||
seek += outputs;
|
seek += outputs;
|
||||||
readBinaryFile(weights_path.c_str(), outputs, &scales_h, &scales_d, seek);
|
readBinaryFile(weights_path.c_str(), outputs, &scales_h, &scales_d, seek, net->dontLoadWeights);
|
||||||
seek += outputs;
|
seek += outputs;
|
||||||
readBinaryFile(weights_path.c_str(), outputs, &mean_h, &mean_d, seek);
|
readBinaryFile(weights_path.c_str(), outputs, &mean_h, &mean_d, seek, net->dontLoadWeights);
|
||||||
seek += outputs;
|
seek += outputs;
|
||||||
readBinaryFile(weights_path.c_str(), outputs, &variance_h, &variance_d, seek);
|
readBinaryFile(weights_path.c_str(), outputs, &variance_h, &variance_d, seek, net->dontLoadWeights);
|
||||||
|
|
||||||
float eps = CUDNN_BN_MIN_EPSILON;
|
float eps = CUDNN_BN_MIN_EPSILON;
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ Network::Network(dataDim_t input_dim) {
|
|||||||
<<", CUDNN v"<<cu_ver<<")\n";
|
<<", CUDNN v"<<cu_ver<<")\n";
|
||||||
dataType = CUDNN_DATA_FLOAT;
|
dataType = CUDNN_DATA_FLOAT;
|
||||||
tensorFormat = CUDNN_TENSOR_NCHW;
|
tensorFormat = CUDNN_TENSOR_NCHW;
|
||||||
|
dontLoadWeights = false;
|
||||||
|
|
||||||
checkCUDNN( cudnnCreate(&cudnnHandle) );
|
checkCUDNN( cudnnCreate(&cudnnHandle) );
|
||||||
checkERROR( cublasCreate(&cublasHandle) );
|
checkERROR( cublasCreate(&cublasHandle) );
|
||||||
|
|||||||
+20
-17
@@ -21,26 +21,29 @@ bool fileExist(const char *fname) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void readBinaryFile(std::string fname, int size, dnnType** data_h, dnnType** data_d, int seek)
|
void readBinaryFile(std::string fname, int size, dnnType** data_h, dnnType** data_d, int seek, bool skipLoad)
|
||||||
{
|
{
|
||||||
std::ifstream dataFile (fname, std::ios::in | std::ios::binary);
|
|
||||||
std::stringstream error_s;
|
|
||||||
if (!dataFile)
|
|
||||||
{
|
|
||||||
error_s << "Error opening file " << fname;
|
|
||||||
FatalError(error_s.str());
|
|
||||||
}
|
|
||||||
|
|
||||||
if(seek != 0) {
|
|
||||||
dataFile.seekg(seek*sizeof(dnnType), dataFile.cur);
|
|
||||||
}
|
|
||||||
|
|
||||||
int size_b = size*sizeof(dnnType);
|
int size_b = size*sizeof(dnnType);
|
||||||
*data_h = new dnnType[size];
|
*data_h = new dnnType[size];
|
||||||
if (!dataFile.read ((char*) *data_h, size_b))
|
|
||||||
{
|
if(!skipLoad) {
|
||||||
error_s << "Error reading file " << fname;
|
std::ifstream dataFile(fname, std::ios::in | std::ios::binary);
|
||||||
FatalError(error_s.str());
|
std::stringstream error_s;
|
||||||
|
if (!dataFile) {
|
||||||
|
error_s << "Error opening file " << fname;
|
||||||
|
FatalError(error_s.str());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (seek != 0) {
|
||||||
|
dataFile.seekg(seek * sizeof(dnnType), dataFile.cur);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!dataFile.read((char *) *data_h, size_b)) {
|
||||||
|
error_s << "Error reading file " << fname;
|
||||||
|
FatalError(error_s.str());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
std::cout<<COL_RED<<"WARNING: skipping data load, this should only used in debug\n"<<COL_END;
|
||||||
}
|
}
|
||||||
|
|
||||||
checkCuda( cudaMalloc(data_d, size_b) );
|
checkCuda( cudaMalloc(data_d, size_b) );
|
||||||
|
|||||||
Reference in New Issue
Block a user