Skip to content

Commit aff8ea6

Browse files
committed
compute number of rows to cache in baseHessian class
1 parent 3887408 commit aff8ea6

2 files changed

Lines changed: 66 additions & 0 deletions

File tree

svm-shared/HessianIO/baseHessian.cpp

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88

99
#include "baseHessian.h"
10+
#include <helper_cuda.h>
1011
#include <sys/time.h>
1112
#include <sys/sysinfo.h>
1213
#include "../gpu_global_utility.h"
@@ -400,3 +401,67 @@ void BaseHessian::PrintHessianInfo()
400401
cout << "part2_end=" << m_nRowEndPos2 << endl;
401402
}
402403

404+
405+
/**
406+
* @brief: kernel matrix precomputation
407+
*/
408+
void BaseHessian::PrecomputeKernelMatrix(vector<vector<float_point> > &v_vDocVector, BaseHessian *hessianIOOps)
409+
{
410+
//compute Hessian Matrix
411+
string strHessianMatrixFileName = HESSIAN_FILE;
412+
string strDiagHessianFileName = HESSIAN_DIAG_FILE;
413+
414+
int nNumofSample = v_vDocVector.size();
415+
416+
//initialize Hessian IO operator
417+
//CLinearKernel RBF(pfGamma[j]);
418+
419+
int nNumofRowsOfHessianMatrix = v_vDocVector.size();
420+
//space of row-index-in-file is for improving reading performace
421+
BaseHessian::m_nNumofDim = v_vDocVector.front().size();
422+
BaseHessian::m_nTotalNumofInstance = nNumofRowsOfHessianMatrix;
423+
424+
StorageManager *manager = StorageManager::getManager();
425+
int nNumofHessianRow = manager->RowInRAM(BaseHessian::m_nNumofDim, BaseHessian::m_nTotalNumofInstance, nNumofSample);
426+
427+
cout << nNumofHessianRow << " rows cached in RAM" << endl;
428+
long long lSizeofCachedHessian = sizeof(float_point) * (long long)nNumofHessianRow * nNumofSample;
429+
430+
431+
cout << "numRow " << nNumofHessianRow << "; numIns " << nNumofSample << "; numBytes " << lSizeofCachedHessian << endl;
432+
if(lSizeofCachedHessian < 0)
433+
{
434+
cerr << "locate negative amount of host memory" << endl;
435+
exit(-1);
436+
}
437+
438+
checkCudaErrors(cudaMallocHost((void**)&(BaseHessian::m_pfHessianRowsInHostMem), lSizeofCachedHessian));
439+
440+
memset(BaseHessian::m_pfHessianRowsInHostMem, 0, lSizeofCachedHessian);
441+
BaseHessian::m_nNumofCachedHessianRow = nNumofHessianRow;
442+
BaseHessian::m_pfHessianDiag = new float_point[hessianIOOps->m_nTotalNumofInstance];
443+
//hessianIOOps->m_pfHessianDiagTest = new float_point[hessianIOOps->m_nTotalNumofInstance];
444+
445+
//pre-compute Hessian Matrix and store the result into a file
446+
cout << "precomputing kernel matrix...";
447+
cout.flush();
448+
449+
timeval t1, t2;
450+
float_point elapsedTime;
451+
gettimeofday(&t1, NULL);
452+
bool bWriteHessian = hessianIOOps->PrecomputeHessian(strHessianMatrixFileName, strDiagHessianFileName, v_vDocVector);
453+
hessianIOOps->ReadDiagFromHessianMatrix();
454+
455+
gettimeofday(&t2, NULL);
456+
elapsedTime = (t2.tv_sec - t1.tv_sec) * 1000.0;
457+
elapsedTime += (t2.tv_usec - t1.tv_usec) / 1000.0;
458+
//cout << "Done" << elapsedTime << " ms.\n";
459+
cout << " Done" << endl;
460+
461+
if(bWriteHessian == false)
462+
{
463+
cerr << "write matrix to file failed" << endl;
464+
exit(0);
465+
}
466+
}
467+

svm-shared/HessianIO/baseHessian.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ class BaseHessian
6767
void SaveRows(float_point *pfSubMatrix, const SubMatrix &subMatrix);
6868
static void ReadRow(int nPosofRowAtHessian, float_point *pfHessianRow);
6969

70+
void PrecomputeKernelMatrix(vector<vector<float_point> > &v_vDocVector, BaseHessian *hessianIOOps);
7071
virtual bool PrecomputeHessian(const string &strHessianMatrixFileName, const string &strDiagHessianFileName, vector<vector<float_point> > &v_v_DocVector) = 0;
7172

7273
private:

0 commit comments

Comments
 (0)