add memory handling for DKS/GPU. No fitting possible, yet.
This commit is contained in:
@@ -81,6 +81,17 @@ Double_t PFitterFcnDKS::operator()(const std::vector<Double_t>& par) const
|
||||
{
|
||||
Double_t value = 0.0;
|
||||
|
||||
// write parameter to GPU
|
||||
Int_t ierr = fDKS.writeParams(&par[0], par.size());
|
||||
|
||||
// loop over all data sets
|
||||
for (UInt_t i=0; i<fRunListCollection->GetNoOfSingleHisto(); i++) {
|
||||
// set N0, Nbkg
|
||||
// set fun values
|
||||
// set map values
|
||||
// calc chisq/log-mlh
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -122,6 +133,8 @@ void PFitterFcnDKS::CalcExpectedChiSquare(const std::vector<Double_t> &par, Doub
|
||||
*/
|
||||
void PFitterFcnDKS::InitDKS(const UInt_t dksTag)
|
||||
{
|
||||
Int_t ierr = 0;
|
||||
|
||||
// if any device was allocated before, free the device resources
|
||||
FreeDKS();
|
||||
|
||||
@@ -142,16 +155,89 @@ void PFitterFcnDKS::InitDKS(const UInt_t dksTag)
|
||||
|
||||
// init chisq buffer on the GPU
|
||||
|
||||
// 1) calculated the maximum size for the data needed.
|
||||
Int_t maxSize = -1, size = -1;
|
||||
Int_t parSize = -1, mapSize = -1, funSize = -1;
|
||||
for (UInt_t i=0; i<fRunListCollection->GetNoOfSingleHisto(); i++) {
|
||||
size = fRunListCollection->GetSingleHisto(i)->GetValue()->size();
|
||||
if (maxSize < size)
|
||||
maxSize = size;
|
||||
}
|
||||
for (UInt_t i=0; i<fRunListCollection->GetNoOfAsymmetry(); i++) {
|
||||
size = fRunListCollection->GetAsymmetry(i)->GetValue()->size();
|
||||
if (maxSize < size)
|
||||
maxSize = size;
|
||||
}
|
||||
if (maxSize == -1) {
|
||||
cerr << ">> PFitterFcnDKS::InitDKS: **ERROR** failed to get data size to be fitted." << endl;
|
||||
fValid = false;
|
||||
return;
|
||||
}
|
||||
|
||||
// 2) get number of parameters / functions / maps
|
||||
parSize = fRunListCollection->GetNoOfParameters();
|
||||
if (parSize == -1) {
|
||||
cerr << ">> PFitterFcnDKS::InitDKS: **ERROR** failed to get number of fit parameters." << endl;
|
||||
fValid = false;
|
||||
return;
|
||||
}
|
||||
funSize = fRunListCollection->GetNoOfFunctions();
|
||||
if (funSize == -1) {
|
||||
cerr << ">> PFitterFcnDKS::InitDKS: **ERROR** failed to get number of functions." << endl;
|
||||
fValid = false;
|
||||
return;
|
||||
}
|
||||
mapSize = fRunListCollection->GetNoOfMaps();
|
||||
if (mapSize == -1) {
|
||||
cerr << ">> PFitterFcnDKS::InitDKS: **ERROR** failed to get number of maps." << endl;
|
||||
fValid = false;
|
||||
return;
|
||||
}
|
||||
cout << "debug> parSize=" << parSize << ", funSize=" << funSize << ", mapSize=" << mapSize << endl;
|
||||
|
||||
// now ready to init the chisq buffer on the GPU
|
||||
ierr = fDKS.initChiSquare(maxSize, parSize, funSize, mapSize);
|
||||
if (ierr != 0) {
|
||||
cerr << ">> PFitterFcnDKS::InitDKS: **ERROR** failed to allocate the necessary chisq buffer on the GPU." << endl;
|
||||
fValid = false;
|
||||
return;
|
||||
}
|
||||
|
||||
// allocate memory for the data on the GPU/CPU and transfer the data sets
|
||||
fMemData.resize(fRunListCollection->GetNoOfSingleHisto());
|
||||
PRunData *runData=0;
|
||||
for (UInt_t i=0; i<fRunListCollection->GetNoOfSingleHisto(); i++) {
|
||||
runData = fRunListCollection->GetSingleHisto(i);
|
||||
if (runData == 0) {
|
||||
cerr << ">> PFitterFcnDKS::InitDKS: **ERROR** failed to get data set (i=" << i << ") from fRunListCollection." << endl;
|
||||
fValid = false;
|
||||
return;
|
||||
}
|
||||
fMemData[i] = fDKS.allocateMemory<Double_t>(runData->GetValue()->size(), ierr);
|
||||
if (ierr != 0) {
|
||||
cerr << ">> PFitterFcnDKS::InitDKS: **ERROR** failed to allocated data set memory (i=" << i << ") on the GPU" << endl;
|
||||
fValid = false;
|
||||
return;
|
||||
}
|
||||
fDKS.writeData<double>(fMemData[i], runData->GetValue(), runData->GetValue()->size());
|
||||
}
|
||||
|
||||
// set the function string and compile the program
|
||||
Int_t ierr = fDKS.callCompileProgram(fTheoStr, !fUseChi2);
|
||||
ierr = fDKS.callCompileProgram(fTheoStr, !fUseChi2);
|
||||
if (ierr != 0) {
|
||||
cerr << ">> PFitterFcnDKS::InitDKS: **ERROR** failed to compile theory!" << endl;
|
||||
fValid = false;
|
||||
return;
|
||||
}
|
||||
|
||||
// keep the N0 and Nbkg for each data set
|
||||
fNidx.resize(fRunListCollection->GetNoOfSingleHisto());
|
||||
for (UInt_t i=0; i<fRunListCollection->GetNoOfSingleHisto(); i++) {
|
||||
fNidx[i].fN0 = fRunListCollection->GetN0Idx(i);
|
||||
fNidx[i].fNbkg = fRunListCollection->GetNbkgIdx(i);
|
||||
cout << "debug> runNo=" << i << ", N0 idx=" << fNidx[i].fN0 << ", Nbkg idx=" << fNidx[i].fNbkg << endl;
|
||||
}
|
||||
|
||||
// checks device properties if openCL
|
||||
ierr = fDKS.checkMuSRKernels();
|
||||
if (ierr != 0) {
|
||||
@@ -172,5 +258,10 @@ void PFitterFcnDKS::InitDKS(const UInt_t dksTag)
|
||||
*/
|
||||
void PFitterFcnDKS::FreeDKS()
|
||||
{
|
||||
|
||||
PRunData *runData=0;
|
||||
for (UInt_t i=0; i<fMemData.size(); i++) {
|
||||
runData = fRunListCollection->GetSingleHisto(i);
|
||||
fDKS.freeMemory<Double_t>(fMemData[i], runData->GetValue()->size());
|
||||
}
|
||||
fMemData.clear();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user