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.
64 lines
1.7 KiB
64 lines
1.7 KiB
#include "costLayer.h"
|
|
|
|
#define LOG( X ) m_pLog->Log( "COST", this, X )
|
|
#define LOG_ERROR( X ) m_pLog->Log( "COST", this, _LOG_ERROR, X )
|
|
|
|
costLayer::costLayer(bool useGPU) : cortexLayer(COST, useGPU){
|
|
m_fScale = 1.f;
|
|
m_eCostType = L1;
|
|
};
|
|
|
|
costLayer::~costLayer(){
|
|
|
|
};
|
|
|
|
|
|
bool costLayer::create(uint32_t batch, uint32_t inputs, COST_TYPE cost_type, float scale){
|
|
char tBuff[256];
|
|
sprintf(tBuff, "cost %4d\n", inputs);
|
|
LOG(tBuff);
|
|
|
|
m_fScale = scale;
|
|
m_nBatch = batch;
|
|
m_nInput = inputs;
|
|
m_nDelta = m_nOutput = inputs;
|
|
m_eCostType = cost_type;
|
|
m_nDeltaVol = m_nOutputVol = m_nOutput * m_nBatch;
|
|
m_pDelta = (float*)calloc(m_nDeltaVol, sizeof(float));
|
|
m_pOutput = (float*)calloc(m_nOutputVol, sizeof(float));
|
|
//l.cost = (float*)calloc(1, sizeof(float));
|
|
#ifdef GPU
|
|
if (m_bUseGPU){
|
|
m_pGpuOutput = m_pPU->makeFloatArray(m_nOutputVol);
|
|
if (m_pGpuOutput = NULL){
|
|
free(m_pOutput); m_pOutput = NULL;
|
|
free(m_pDelta); m_pDelta = NULL;
|
|
return false;
|
|
};
|
|
m_pGpuDelta = m_pPU->makeFloatArray(m_nDeltaVol);
|
|
if (m_pGpuDelta = NULL){
|
|
free(m_pOutput); m_pOutput = NULL;
|
|
free(m_pDelta); m_pDelta = NULL;
|
|
m_pPU->freeMem(m_pGpuOutput); m_pGpuOutput = NULL;
|
|
return false;
|
|
};
|
|
};
|
|
#endif
|
|
return true;
|
|
};
|
|
|
|
void costLayer::resizeEX(int inputs){
|
|
m_nInput = inputs;
|
|
m_nOutput = inputs;
|
|
m_pDelta = (float*)realloc(m_pDelta, m_nDeltaVol * sizeof(float));
|
|
m_pOutput = (float*)realloc(m_pOutput, m_nOutputVol * sizeof(float));
|
|
#ifdef GPU
|
|
m_pPU->freeMem( m_pGpuDelta );
|
|
m_pPU->freeMem( m_pGpuOutput );
|
|
m_pGpuDelta = m_pPU->makeFloatArray(m_nDeltaVol, m_pDelta);
|
|
m_pGpuOutput = m_pPU->makeFloatArray(m_nOutputVol, m_pOutput);
|
|
#endif
|
|
}
|
|
|
|
#undef LOG
|
|
#undef LOG_ERROR
|