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.8 KiB
47 lines
1.8 KiB
#include "cuda.h"
|
|
#include "../layers/regionLayer.h"
|
|
|
|
void gpuCUDA::forward_layer(regionLayer *l, cortexSTATE state){
|
|
///*
|
|
if(!state.train){
|
|
makeCopy( l->m_nBatch*l->m_nInput, state.input, 1, l->m_pGpuOutput, 1);
|
|
return;
|
|
};
|
|
//*/
|
|
makeFlatten(state.input, l->m_nIn_Height*l->m_nIn_Width, l->m_nN*(l->m_nCoords + l->m_nClasses + 1), l->m_nBatch, 1, l->m_pGpuOutput);
|
|
if (l->m_pSoftmaxTree != NULL){
|
|
uint32_t count = 5;
|
|
for (uint32_t i = 0; i < l->m_pSoftmaxTree->groups; ++i) {
|
|
int group_size = l->m_pSoftmaxTree->group_size[i];
|
|
makeSoftMax(l->m_pGpuOutput + count, group_size, l->m_nClasses + 5, l->m_nIn_Height*l->m_nIn_Width*l->m_nN*l->m_nBatch, 1, l->m_pGpuOutput + count);
|
|
count += group_size;
|
|
};
|
|
} else if (l->m_bSoftMax){
|
|
makeSoftMax(l->m_pGpuOutput + 5, l->m_nClasses, l->m_nClasses + 5, l->m_nIn_Height*l->m_nIn_Width*l->m_nN*l->m_nBatch, 1, l->m_pGpuOutput + 5);
|
|
};
|
|
|
|
float *in_cpu = (float *)calloc(l->m_nOutput, sizeof(float));
|
|
float *truth_cpu = NULL;
|
|
if (state.truth){
|
|
int num_truth = l->m_nBatch*l->m_nTruth;
|
|
truth_cpu = (float *)calloc(num_truth, sizeof(float));
|
|
pullFloatArray(state.truth, truth_cpu, num_truth);
|
|
};
|
|
pullFloatArray(l->m_pGpuOutput, in_cpu, l->m_nOutput);
|
|
cortexSTATE cpu_state = state;
|
|
cpu_state.train = state.train;
|
|
cpu_state.truth = truth_cpu;
|
|
cpu_state.input = in_cpu;
|
|
|
|
forward_layer(l, cpu_state);
|
|
|
|
pushFloatArray(l->m_pGpuOutput, l->m_pOutput, l->m_nOutput);
|
|
free(cpu_state.input);
|
|
if (!state.train) return;
|
|
pushFloatArray(l->m_pGpuDelta, l->m_pDelta, l->m_nDelta);
|
|
if (cpu_state.truth != NULL)free(cpu_state.truth);
|
|
};
|
|
|
|
void gpuCUDA::backward_layer(regionLayer *l, cortexSTATE state){
|
|
makeFlatten(l->m_pGpuDelta, l->m_nIn_Height*l->m_nIn_Width, l->m_nN*(l->m_nCoords + l->m_nClasses + 1), l->m_nBatch, 0, state.delta);
|
|
};
|