| | |
| | | fill_ongpu(l.outputs * l.batch, 0, l.delta_gpu, 1); |
| | | } |
| | | l.forward_gpu(l, state); |
| | | if(net.wait_stream) |
| | | cudaStreamSynchronize(get_cuda_stream()); |
| | | state.input = l.output_gpu; |
| | | } |
| | | } |
| | |
| | | for(i = net.n-1; i >= 0; --i){ |
| | | state.index = i; |
| | | layer l = net.layers[i]; |
| | | if (l.stopbackward) break; |
| | | if(i == 0){ |
| | | state.input = original_input; |
| | | state.delta = original_delta; |
| | |
| | | |
| | | void update_network_gpu(network net) |
| | | { |
| | | cuda_set_device(net.gpu_index); |
| | | int i; |
| | | int update_batch = net.batch*net.subdivisions; |
| | | float rate = get_current_rate(net); |
| | | for(i = 0; i < net.n; ++i){ |
| | | layer l = net.layers[i]; |
| | | l.t = get_current_batch(net); |
| | | if(l.update_gpu){ |
| | | l.update_gpu(l, update_batch, rate, net.momentum, net.decay); |
| | | } |
| | |
| | | state.delta = 0; |
| | | state.truth = *net.truth_gpu; |
| | | state.train = 1; |
| | | #ifdef CUDNN_HALF |
| | | int i; |
| | | for (i = 0; i < net.n; ++i) { |
| | | layer l = net.layers[i]; |
| | | cuda_convert_f32_to_f16(l.weights_gpu, l.c*l.n*l.size*l.size, l.weights_gpu16); |
| | | } |
| | | #endif |
| | | forward_network_gpu(net, state); |
| | | //cudaStreamSynchronize(get_cuda_stream()); |
| | | backward_network_gpu(net, state); |
| | | } |
| | | |
| | |
| | | { |
| | | int update_batch = net.batch*net.subdivisions; |
| | | float rate = get_current_rate(net); |
| | | l.t = get_current_batch(net); |
| | | if(l.update_gpu){ |
| | | l.update_gpu(l, update_batch, rate, net.momentum, net.decay); |
| | | } |
| | |
| | | //printf("%f\n", errors[i]); |
| | | sum += errors[i]; |
| | | } |
| | | //cudaDeviceSynchronize(); |
| | | if (get_current_batch(nets[0]) % interval == 0) { |
| | | printf("Syncing... "); |
| | | fflush(stdout); |
| | | sync_nets(nets, n, interval); |
| | | printf("Done!\n"); |
| | | } |
| | | //cudaDeviceSynchronize(); |
| | | free(threads); |
| | | free(errors); |
| | | return (float)sum/(n); |
| | |
| | | float *get_network_output_layer_gpu(network net, int i) |
| | | { |
| | | layer l = net.layers[i]; |
| | | cuda_pull_array(l.output_gpu, l.output, l.outputs*l.batch); |
| | | if(l.type != REGION) cuda_pull_array(l.output_gpu, l.output, l.outputs*l.batch); |
| | | return l.output; |
| | | } |
| | | |
| | |
| | | |
| | | float *network_predict_gpu(network net, float *input) |
| | | { |
| | | cuda_set_device(net.gpu_index); |
| | | if (net.gpu_index != cuda_get_device()) |
| | | cuda_set_device(net.gpu_index); |
| | | int size = get_network_input_size(net) * net.batch; |
| | | network_state state; |
| | | state.index = 0; |