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.

29 lines
1002 B

7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #include "cpu.h"
  2. #include "../layers/routeLayer.h"
  3. void cpuHOST::forward_layer(routeLayer *layer, cortexSTATE state){
  4. uint32_t offset = 0;
  5. for (uint32_t i = 0; i < layer->m_nN; ++i){
  6. uint32_t index = layer->m_pInputLayers[i];
  7. uint32_t input_size = layer->m_pInputSizes[i];
  8. float *input = state.net->getLayer(index)->m_pOutput;
  9. for (uint32_t j = 0; j < layer->m_nBatch; ++j){
  10. makeCopy(input_size, input + j*input_size, 1, layer->m_pOutput + offset + j*layer->m_nOutput, 1);
  11. };
  12. offset += input_size;
  13. };
  14. };
  15. void cpuHOST::backward_layer(routeLayer *layer, cortexSTATE state){
  16. uint32_t offset = 0;
  17. for (uint32_t i = 0; i < layer->m_nN; ++i){
  18. uint32_t index = layer->m_pInputLayers[i];
  19. uint32_t input_size = layer->m_pInputSizes[i];
  20. float *delta = state.net->getLayer(index)->m_pDelta;
  21. for (uint32_t j = 0; j < layer->m_nBatch; ++j){
  22. calcAxpy(input_size, 1, layer->m_pDelta + offset + j*layer->m_nOutput, 1, delta + j*input_size, 1);
  23. };
  24. offset += input_size;
  25. };
  26. };