更多darknet源代码学习笔记,参看:darknet源码学习:预测分类函数float *network_predict_gpu(network net, float *input)
parse_network_cfg_custom()解析cfg文件函数parse_network_cfg()中调用
network parse_network_cfg(char *filename)
{
return parse_network_cfg_custom(filename, 0, 0);
}
parse_network_cfg_custom中获取input_state_gpu,具体代码如下:
int size = get_network_input_size(net) * net.batch;
net.input_state_gpu = cuda_make_array(0, size);
cuda_make_array函数定义:
float *cuda_make_array(float *x, size_t n)
{
float *x_gpu;
size_t size = sizeof(float)*n;
cudaError_t status = cudaMalloc((void **)&x_gpu, size);
if (status != cudaSuccess) fprintf(stderr, " Try to set subdivisions=64 in your cfg-file. \n");
CHECK_CUDA(status);
if(x){
//status = cudaMemcpy(x_gpu, x, size, cudaMemcpyHostToDevice);
status = cudaMemcpyAsync(x_gpu, x, size, cudaMemcpyHostToDevice, get_cuda_stream());
CHECK_CUDA(status);
}
if(!x_gpu) error("Cuda malloc failed\n");
return x_gpu;
}