first work to add GPU support via DKS for Fourier.
This commit is contained in:
97
src/tests/DKS_FourierTest/Makefile
Normal file
97
src/tests/DKS_FourierTest/Makefile
Normal file
@@ -0,0 +1,97 @@
|
||||
#---------------------------------------------------
|
||||
# get compilation and library flags from root-config
|
||||
|
||||
ROOTCFLAGS = $(shell $(ROOTSYS)/bin/root-config --cflags)
|
||||
ROOTLIBS = $(shell $(ROOTSYS)/bin/root-config --libs)
|
||||
ROOTGLIBS = $(shell $(ROOTSYS)/bin/root-config --glibs)
|
||||
|
||||
#---------------------------------------------------
|
||||
# set compilation and library flags for DKS
|
||||
|
||||
DKS_CUDADIR = /usr/local/cuda-6.5/targets/x86_64-linux
|
||||
DKS_INCDIR = /home/l_suter_a/DKS/src
|
||||
DKS_CFLAGS = -DHAVE_DKS -DDKS_OPENCL -DDKS_CUDA -I${DKS_INCDIR} -I${DKS_CUDADIR}/include
|
||||
DKS_LIBDIR = /home/l_suter_a/DKS/build/src
|
||||
DKS_LIBS = -L${DKS_CUDADIR}/lib -lOpenCL -L${DKS_LIBDIR} -ldksshared
|
||||
|
||||
#---------------------------------------------------
|
||||
# set compilation and library flags for FFTW
|
||||
FFTW3_INCDIR = /usr/include
|
||||
FFTW3_LIBS = -L/usr/lib64 -lfftw3
|
||||
|
||||
#---------------------------------------------------
|
||||
# set compilation and library flags for PMusr
|
||||
|
||||
PMUSR_INCDIR = $(ROOTSYS)/include
|
||||
PMUSR_SRCDIR = $(HOME)/musrfit/src/classes
|
||||
PMUSR_LIBS = -L $(ROOTSYS)/lib -lPMusr
|
||||
|
||||
#---------------------------------------------------
|
||||
# depending on the architecture, choose the compiler,
|
||||
# linker, and the flags to use
|
||||
#
|
||||
|
||||
ARCH = $(shell $(ROOTSYS)/bin/root-config --arch)
|
||||
|
||||
ifeq ($(ARCH),linux)
|
||||
OS = LINUX
|
||||
endif
|
||||
ifeq ($(ARCH),linuxx8664gcc)
|
||||
OS = LINUX
|
||||
endif
|
||||
ifeq ($(ARCH),win32gcc)
|
||||
OS = WIN32GCC
|
||||
endif
|
||||
ifeq ($(ARCH),macosx)
|
||||
OS = DARWIN
|
||||
endif
|
||||
|
||||
# -- Linux
|
||||
ifeq ($(OS),LINUX)
|
||||
CXX = gcc
|
||||
CXXFLAGS = -g -O2 -Wall -fPIC
|
||||
INCLUDES = -I$(PMUSR_INCDIR) -I$(DKS_INCDIR)
|
||||
LD = g++
|
||||
LDFLAGS =
|
||||
INSTALLPATH = ./
|
||||
EXEC = dks_fourierTest
|
||||
SUFFIX =
|
||||
endif
|
||||
|
||||
# -- MacOSX/Darwin
|
||||
ifeq ($(OS),DARWIN)
|
||||
CXX = gcc
|
||||
CXXFLAGS = -O3 -Wall -fPIC
|
||||
INCLUDES = -I$(PMUSR_INCDIR) -I$(FFTW3_INCDIR) -I$(DKS_INCDIR)
|
||||
LD = g++
|
||||
LDFLAGS = -O
|
||||
INSTALLPATH = ./
|
||||
EXEC = dks_fourierTest
|
||||
SUFFIX =
|
||||
endif
|
||||
|
||||
# the output from the root-config script:
|
||||
CXXFLAGS += $(ROOTCFLAGS) $(DKS_CFLAGS)
|
||||
LDFLAGS +=
|
||||
|
||||
# the ROOT libraries (G = graphic)
|
||||
LIBS = $(ROOTLIBS) -lXMLParser $(FFTW3_LIBS) $(DKS_LIBS)
|
||||
GLIBS = $(ROOTGLIBS) -lXMLParser $(FFTW3_LIBS) $(DKS_LIBS)
|
||||
|
||||
# some definitions: headers, sources, objects,...
|
||||
FOURIER = PFourier
|
||||
|
||||
all: $(EXEC)
|
||||
|
||||
clean:
|
||||
rm *.o
|
||||
|
||||
$(EXEC): $(FOURIER).o $(EXEC).o
|
||||
@echo "---> Building $(EXEC) ..."
|
||||
/bin/rm -f $(SHLIB)
|
||||
$(LD) $(FOURIER).o $(EXEC).o -o $(EXEC) $(GLIBS)
|
||||
@echo "done"
|
||||
|
||||
$(FOURIER).o: $(PMUSR_SRCDIR)/$(FOURIER).cpp
|
||||
$(CXX) $(INCLUDES) $(CXXFLAGS) -c $<
|
||||
|
||||
143
src/tests/DKS_FourierTest/dks_fourierTest.cpp
Normal file
143
src/tests/DKS_FourierTest/dks_fourierTest.cpp
Normal file
@@ -0,0 +1,143 @@
|
||||
#include <sys/time.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <vector>
|
||||
using namespace std;
|
||||
|
||||
#include "TH1F.h"
|
||||
#include "TFile.h"
|
||||
|
||||
#include "PMusr.h"
|
||||
#include "PFourier.h"
|
||||
|
||||
|
||||
//---------------------------------------------------
|
||||
double millitime()
|
||||
{
|
||||
struct timeval now;
|
||||
gettimeofday(&now, 0);
|
||||
|
||||
return ((double)now.tv_sec * 1.0e6 + (double)now.tv_usec)/1.0e3;
|
||||
}
|
||||
|
||||
//---------------------------------------------------
|
||||
void dks_fourierTest_syntax()
|
||||
{
|
||||
cout << endl << "usage: dks_fourierTest [useFFTW, N, L | --help] ";
|
||||
cout << endl << " useFFTW : flag, if true -> FFTW, otherwise -> DKS";
|
||||
cout << endl << " N : number of histos";
|
||||
cout << endl << " L : histo length";
|
||||
cout << endl << " if not given, useFFTW=true, N=8, L=2^20=1048576";
|
||||
cout << endl << " --help: this help";
|
||||
cout << endl << endl;
|
||||
}
|
||||
|
||||
//---------------------------------------------------
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
vector<TH1F*> data;
|
||||
vector<PFourier*> fourierData;
|
||||
vector<TH1F*> fourierPowerHistos;
|
||||
|
||||
int N=8, L=1048576;
|
||||
Bool_t useFFTW = true;
|
||||
|
||||
switch (argc) {
|
||||
case 1:
|
||||
break;
|
||||
case 4:
|
||||
if (!strcmp(argv[1], "true") || !strcmp(argv[1], "1"))
|
||||
useFFTW = true;
|
||||
else if (!strcmp(argv[1], "false") || !strcmp(argv[1], "0"))
|
||||
useFFTW = false;
|
||||
else {
|
||||
dks_fourierTest_syntax();
|
||||
return 1;
|
||||
}
|
||||
N = strtol(argv[2], 0, 10);
|
||||
L = strtol(argv[3], 0, 10);
|
||||
break;
|
||||
default:
|
||||
dks_fourierTest_syntax();
|
||||
return 1;
|
||||
break;
|
||||
}
|
||||
|
||||
if ((N<=0) || (L<=0)) {
|
||||
dks_fourierTest_syntax();
|
||||
return 1;
|
||||
}
|
||||
|
||||
// feed the histos
|
||||
TH1F *h;
|
||||
char str[128];
|
||||
double dt = 10.0 / (double)L;
|
||||
double dval = 0.0;
|
||||
for (unsigned int i=0; i<(unsigned int)N; i++) {
|
||||
snprintf(str, sizeof(str), "h%d", i);
|
||||
h = new TH1F(str, str, L+1, -dt/2, 10.0+dt/2);
|
||||
for (unsigned int j=0; j<(unsigned int)h->GetNbinsX(); j++) {
|
||||
dval = exp(-0.5*dt*j)*cos(0.013554*5000.0*dt*j+6.2832/N*i);
|
||||
h->SetBinContent(j+1, dval);
|
||||
}
|
||||
data.push_back(h);
|
||||
}
|
||||
|
||||
cout << "debug> data.size()=" << data.size() << endl;
|
||||
|
||||
// setup FFT
|
||||
PFourier *fh;
|
||||
for (unsigned int i=0; i<data.size(); i++) {
|
||||
fh = new PFourier(data[i], FOURIER_UNIT_GAUSS, 0.0, 0.0, false, 0, useFFTW);
|
||||
fourierData.push_back(fh);
|
||||
}
|
||||
|
||||
cout << "debug> fourierData.size()=" << fourierData.size() << endl;
|
||||
|
||||
// do FFT
|
||||
double start = millitime();
|
||||
for (unsigned int i=0; i<fourierData.size(); i++) {
|
||||
fourierData[i]->Transform();
|
||||
}
|
||||
double end = millitime();
|
||||
cout << "info> overall computation time: " << (end-start)/1.0e3 << " (sec)." << endl << endl;
|
||||
// get FFT data
|
||||
TH1F *pf;
|
||||
unsigned int out=128;
|
||||
for (unsigned int i=0; i<fourierData.size(); i++) {
|
||||
pf = fourierData[i]->GetPowerFourier();
|
||||
fourierPowerHistos.push_back(pf);
|
||||
}
|
||||
|
||||
cout << "debug> fourierPowerHistos.size()=" << fourierPowerHistos.size() << endl;
|
||||
|
||||
// dump results
|
||||
for (unsigned int i=0; i<fourierPowerHistos.size(); i++) {
|
||||
out = (unsigned int)fourierPowerHistos[i]->GetNbinsX();
|
||||
cout << "debug> out=" << out << endl;
|
||||
if (out > 64)
|
||||
out = 64;
|
||||
cout << "debug> fourier " << i+1 << ": ";
|
||||
for (unsigned int j=1; j<=out; j++)
|
||||
cout << fourierPowerHistos[i]->GetBinContent(j) << ", ";
|
||||
cout << endl << "---" << endl;
|
||||
}
|
||||
TFile fout("dks_fourierTest.root", "recreate");
|
||||
for (unsigned int i=0; i<fourierPowerHistos.size(); i++) {
|
||||
fourierPowerHistos[i]->Write();
|
||||
}
|
||||
fout.Close();
|
||||
|
||||
// clean up
|
||||
for (unsigned int i=0; i<data.size(); i++) {
|
||||
delete data[i];
|
||||
delete fourierData[i];
|
||||
delete fourierPowerHistos[i];
|
||||
}
|
||||
data.clear();
|
||||
fourierData.clear();
|
||||
fourierPowerHistos.clear();
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user