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.

28 lines
1020 B

7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #include "cuda.h"
  2. #include "../layers/routeLayer.h"
  3. void gpuCUDA::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_pGpuOutput;
  9. for (uint32_t j = 0; j < layer->m_nBatch; ++j){
  10. makeCopy(input_size, input + j*input_size, 1, layer->m_pGpuOutput + offset + j*layer->m_nOutput, 1);
  11. };
  12. offset += input_size;
  13. };
  14. };
  15. void gpuCUDA::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_pGpuDelta;
  21. for (uint32_t j = 0; j < layer->m_nBatch; ++j){
  22. calcAxpy(input_size, 1, layer->m_pGpuDelta + offset + j*layer->m_nOutput, 1, delta + j*input_size, 1);
  23. };
  24. offset += input_size;
  25. };
  26. };