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

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #include <cuda_runtime.h>
  2. #include <curand.h>
  3. #include <cublas_v2.h>
  4. #include "cuda.h"
  5. #include "../layers/dropoutLayer.h"
  6. __global__ void yoloswag420blazeit360noscope(float *input, int size, float *rand, float prob, float scale)
  7. {
  8. int id = (blockIdx.x + blockIdx.y*gridDim.x) * blockDim.x + threadIdx.x;
  9. if(id < size) input[id] = (rand[id] < prob) ? 0 : input[id]*scale;
  10. }
  11. void gpuCUDA::forward_layer(dropoutLayer *layer, cortexSTATE state){
  12. if (!state.train) return;
  13. int size = layer->m_nInput * layer->m_nBatch;
  14. makeRandom(layer->m_pGpuRand, size);
  15. /*
  16. int i;
  17. for(i = 0; i < size; ++i){
  18. layer.rand[i] = rand_uniform();
  19. }
  20. cuda_push_array(layer.rand_gpu, layer.rand, size);
  21. */
  22. yoloswag420blazeit360noscope << <gridSize(size), BLOCK >> >(
  23. state.input,
  24. size,
  25. layer->m_pGpuRand,
  26. layer->m_fProbability,
  27. layer->m_fScale
  28. );
  29. checkError();// cudaPeekAtLastError());
  30. }
  31. void gpuCUDA::backward_layer(dropoutLayer *layer, cortexSTATE state){
  32. if(!state.delta) return;
  33. int size = layer->m_nInput*layer->m_nBatch;
  34. yoloswag420blazeit360noscope << <gridSize(size), BLOCK >> >(
  35. state.delta,
  36. size,
  37. layer->m_pGpuRand,
  38. layer->m_fProbability,
  39. layer->m_fScale
  40. );
  41. checkError();// cudaPeekAtLastError());
  42. }