classifier.c中load_file接口:
void load_file(char *cfgfile, char *weightfile)
{
net = parse_network_cfg(cfgfile);
}
parse.c文件:
network parse_network_cfg(char *filename)
{
return parse_network_cfg_custom(filename, 0, 0);
}
parse.c文件中的parse_network_cfg_custom中调用
network parse_network_cfg_custom(char *filename, int batch, int time_steps)
{
if(lt == CONVOLUTIONAL){
WriteLog("parse_convolutional");
l = parse_convolutional(options, params, net);
WriteLog("parse_convolutional 11");
}else if(lt == LOCAL){
}
parse.c文件中的parse_convolutional()中调用make_convolutional_layer():
convolutional_layer parse_convolutional(list *options, size_params params, network net)
{
convolutional_layer layer = make_convolutional_layer(batch,1,h,w,c,n,groups,size,stride,dilation,padding,activation, batch_normalize, binary, xnor, params.net.adam, use_bin_output, params.index, share_layer);
}
workspace_size在convolutional_layer.c函数中的make_convolutional_layer()函数中设置:
convolutional_layer l = { (LAYER_TYPE)0 };
l.type = CONVOLUTIONAL;
l.workspace_size = get_convolutional_workspace_size(l);
get_convolutional_workspace_size()在中convolutional_layer.c定义,具体代码如下:
size_t get_convolutional_workspace_size(layer l) {
size_t workspace_size = get_workspace_size32(l);
size_t workspace_size16 = get_workspace_size16(l);
if (workspace_size16 > workspace_size) workspace_size = workspace_size16;
return workspace_size;
}
get_wokspace_size32代码:
size_t get_workspace_size32(layer l){
#ifdef CUDNN
if(gpu_index >= 0){
size_t most = 0;
size_t s = 0;
CHECK_CUDNN(cudnnGetConvolutionForwardWorkspaceSize(cudnn_handle(),
l.srcTensorDesc,
l.weightDesc,
l.convDesc,
l.dstTensorDesc,
l.fw_algo,
&s));
if (s > most) most = s;
CHECK_CUDNN(cudnnGetConvolutionBackwardFilterWorkspaceSize(cudnn_handle(),
l.srcTensorDesc,
l.ddstTensorDesc,
l.convDesc,
l.dweightDesc,
l.bf_algo,
&s));
if (s > most) most = s;
CHECK_CUDNN(cudnnGetConvolutionBackwardDataWorkspaceSize(cudnn_handle(),
l.weightDesc,
l.ddstTensorDesc,
l.convDesc,
l.dsrcTensorDesc,
l.bd_algo,
&s));
if (s > most) most = s;
return most;
}
#endif
if (l.xnor) {
size_t re_packed_input_size = l.c * l.w * l.h * sizeof(float);
size_t workspace_size = (size_t)l.bit_align*l.size*l.size*l.c * sizeof(float);
if (workspace_size < re_packed_input_size) workspace_size = re_packed_input_size;
return workspace_size;
}
return (size_t)l.out_h*l.out_w*l.size*l.size*(l.c / l.groups)*sizeof(float);
}
get_wokspace_size16代码:
size_t get_workspace_size16(layer l) {
#if defined(CUDNN) && defined(CUDNN_HALF)
if (gpu_index >= 0) {
size_t most = 0;
size_t s = 0;
CHECK_CUDNN(cudnnGetConvolutionForwardWorkspaceSize(cudnn_handle(),
l.srcTensorDesc16,
l.weightDesc16,
l.convDesc,
l.dstTensorDesc16,
l.fw_algo16,
&s));
if (s > most) most = s;
CHECK_CUDNN(cudnnGetConvolutionBackwardFilterWorkspaceSize(cudnn_handle(),
l.srcTensorDesc16,
l.ddstTensorDesc16,
l.convDesc,
l.dweightDesc16,
l.bf_algo16,
&s));
if (s > most) most = s;
CHECK_CUDNN(cudnnGetConvolutionBackwardDataWorkspaceSize(cudnn_handle(),
l.weightDesc16,
l.ddstTensorDesc16,
l.convDesc,
l.dsrcTensorDesc16,
l.bd_algo16,
&s));
if (s > most) most = s;
return most;
}
#endif
return 0;
//if (l.xnor) return (size_t)l.bit_align*l.size*l.size*l.c * sizeof(float);
//return (size_t)l.out_h*l.out_w*l.size*l.size*l.c * sizeof(float);
}