You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.2 KiB

8 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #include <cuda_runtime.h>
  2. #include <curand.h>
  3. #include <cublas_v2.h>
  4. extern "C" {
  5. #include "dropout_layer.h"
  6. #include "dn_cuda.h"
  7. #include "utils.h"
  8. }
  9. namespace DN{
  10. __global__ void yoloswag420blazeit360noscope(float *input, int size, float *rand, float prob, float scale)
  11. {
  12. int id = (blockIdx.x + blockIdx.y*gridDim.x) * blockDim.x + threadIdx.x;
  13. if (id < size) input[id] = (rand[id] < prob) ? 0 : input[id] * scale;
  14. }
  15. void forward_dropout_layer_gpu(dropout_layer layer, network net)
  16. {
  17. if (!net.train) return;
  18. int size = layer.inputs*layer.batch;
  19. cuda_random(layer.rand_gpu, size);
  20. /*
  21. int i;
  22. for(i = 0; i < size; ++i){
  23. layer.rand[i] = rand_uniform();
  24. }
  25. cuda_push_array(layer.rand_gpu, layer.rand, size);
  26. */
  27. yoloswag420blazeit360noscope << <cuda_gridsize(size), BLOCK >> >(net.input_gpu, size, layer.rand_gpu, layer.probability, layer.scale);
  28. check_error(cudaPeekAtLastError());
  29. }
  30. void backward_dropout_layer_gpu(dropout_layer layer, network net)
  31. {
  32. if (!net.delta_gpu) return;
  33. int size = layer.inputs*layer.batch;
  34. yoloswag420blazeit360noscope << <cuda_gridsize(size), BLOCK >> >(net.delta_gpu, size, layer.rand_gpu, layer.probability, layer.scale);
  35. check_error(cudaPeekAtLastError());
  36. }
  37. };