2015-01-23 03:38:24 +03:00
|
|
|
extern "C" {
|
|
|
|
#include "dropout_layer.h"
|
|
|
|
#include "cuda.h"
|
|
|
|
#include "utils.h"
|
2015-03-12 08:20:15 +03:00
|
|
|
#include "params.h"
|
2015-01-23 03:38:24 +03:00
|
|
|
}
|
|
|
|
|
2015-03-12 08:20:15 +03:00
|
|
|
__global__ void yoloswag420blazeit360noscope(float *input, int size, float *rand, float prob, float scale)
|
2015-01-23 03:38:24 +03:00
|
|
|
{
|
|
|
|
int id = (blockIdx.x + blockIdx.y*gridDim.x) * blockDim.x + threadIdx.x;
|
2015-03-12 08:20:15 +03:00
|
|
|
if(id < size) input[id] = (rand[id] < prob) ? 0 : input[id]*scale;
|
2015-01-23 03:38:24 +03:00
|
|
|
}
|
|
|
|
|
2015-03-12 08:20:15 +03:00
|
|
|
extern "C" void forward_dropout_layer_gpu(dropout_layer layer, network_state state)
|
2015-01-23 03:38:24 +03:00
|
|
|
{
|
2015-03-12 08:20:15 +03:00
|
|
|
if (!state.train) return;
|
2015-01-23 03:38:24 +03:00
|
|
|
int j;
|
|
|
|
int size = layer.inputs*layer.batch;
|
|
|
|
for(j = 0; j < size; ++j) layer.rand[j] = rand_uniform();
|
|
|
|
cuda_push_array(layer.rand_gpu, layer.rand, layer.inputs*layer.batch);
|
|
|
|
|
2015-03-12 08:20:15 +03:00
|
|
|
yoloswag420blazeit360noscope<<<cuda_gridsize(size), BLOCK>>>(state.input, size, layer.rand_gpu, layer.probability, layer.scale);
|
2015-01-23 03:38:24 +03:00
|
|
|
check_error(cudaPeekAtLastError());
|
|
|
|
}
|
|
|
|
|
2015-03-12 08:20:15 +03:00
|
|
|
extern "C" void backward_dropout_layer_gpu(dropout_layer layer, network_state state)
|
2015-01-23 03:38:24 +03:00
|
|
|
{
|
2015-03-12 08:20:15 +03:00
|
|
|
if(!state.delta) return;
|
2015-01-23 03:38:24 +03:00
|
|
|
int size = layer.inputs*layer.batch;
|
|
|
|
|
2015-03-12 08:20:15 +03:00
|
|
|
yoloswag420blazeit360noscope<<<cuda_gridsize(size), BLOCK>>>(state.delta, size, layer.rand_gpu, layer.probability, layer.scale);
|
2015-01-23 03:38:24 +03:00
|
|
|
check_error(cudaPeekAtLastError());
|
|
|
|
}
|