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.

30 lines
1.0 KiB

7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #include "cpu.h"
  2. #include "../layers/avgpoolLayer.h"
  3. void cpuHOST::forward_layer(avgpoolLayer *layer, cortexSTATE state){
  4. uint32_t Area = layer->m_nIn_Width * layer->m_nIn_Height;
  5. for (uint32_t b = 0; b < layer->m_nBatch; ++b){
  6. for (uint32_t k = 0; k < layer->m_nIn_Channels; ++k){
  7. uint32_t out_index = k + b*layer->m_nIn_Channels;
  8. layer->m_pOutput[out_index] = 0;
  9. for (uint32_t i = 0; i < Area; ++i){
  10. uint32_t in_index = i + Area*out_index;
  11. layer->m_pOutput[out_index] += state.input[in_index];
  12. };
  13. layer->m_pOutput[out_index] /= Area;
  14. };
  15. };
  16. };
  17. void cpuHOST::backward_layer(avgpoolLayer *layer, cortexSTATE state){
  18. uint32_t Area = layer->m_nIn_Width * layer->m_nIn_Height;
  19. for (uint32_t b = 0; b < layer->m_nBatch; ++b){
  20. for (uint32_t k = 0; k < layer->m_nIn_Channels; ++k){
  21. uint32_t out_index = k + b*layer->m_nIn_Channels;
  22. for (uint32_t i = 0; i < Area; ++i){
  23. uint32_t in_index = i + Area*out_index;
  24. state.delta[in_index] += layer->m_pDelta[out_index]/Area;
  25. };
  26. };
  27. };
  28. };