Commit 6de7b834 authored by David Keitel's avatar David Keitel
Browse files

tCW pyCUDA: minor code cleanup

 -make some functions internal in tcw_fstat_map_funcs.py
 -clean up debug messages
 -clean up code formatting
parent 691dae29
...@@ -632,8 +632,8 @@ class ComputeFstat(BaseSearchClass): ...@@ -632,8 +632,8 @@ class ComputeFstat(BaseSearchClass):
self.windowRange.dt0 = self.Tsft self.windowRange.dt0 = self.Tsft
self.windowRange.dtau = self.Tsft self.windowRange.dtau = self.Tsft
# special treatment of window_type = none ==> replace by # special treatment of window_type = none
# rectangular window spanning all the data # ==> replace by rectangular window spanning all the data
if self.windowRange.type == lalpulsar.TRANSIENT_NONE: if self.windowRange.type == lalpulsar.TRANSIENT_NONE:
self.windowRange.t0 = int(self.minStartTime) self.windowRange.t0 = int(self.minStartTime)
self.windowRange.t0Band = 0 self.windowRange.t0Band = 0
...@@ -661,6 +661,7 @@ class ComputeFstat(BaseSearchClass): ...@@ -661,6 +661,7 @@ class ComputeFstat(BaseSearchClass):
if self.dtau: if self.dtau:
self.windowRange.dtau = self.dtau self.windowRange.dtau = self.dtau
logging.info('Initialising transient FstatMap features...')
self.tCWFstatMapFeatures, self.gpu_context = ( self.tCWFstatMapFeatures, self.gpu_context = (
tcw.init_transient_fstat_map_features( tcw.init_transient_fstat_map_features(
self.tCWFstatMapVersion == 'pycuda', self.cudaDeviceName)) self.tCWFstatMapVersion == 'pycuda', self.cudaDeviceName))
...@@ -707,15 +708,6 @@ class ComputeFstat(BaseSearchClass): ...@@ -707,15 +708,6 @@ class ComputeFstat(BaseSearchClass):
# F-stat computation # F-stat computation
self.windowRange.tau = int(2*self.Tsft) self.windowRange.tau = int(2*self.Tsft)
# logging.debug(
# 'Calling "%s" version of ComputeTransientFstatMap() with\
# windowRange: (type=%d (%s), t0=%f, t0Band=%f, dt0=%f, tau=%f,\
# tauBand=%f, dtau=%f)...' % (
# self.tCWFstatMapVersion, self.windowRange.type,
# self.transientWindowType, self.windowRange.t0,
# self.windowRange.t0Band, self.windowRange.dt0,
# self.windowRange.tau, self.windowRange.tauBand,
# self.windowRange.dtau))
self.FstatMap = tcw.call_compute_transient_fstat_map( self.FstatMap = tcw.call_compute_transient_fstat_map(
self.tCWFstatMapVersion, self.tCWFstatMapFeatures, self.tCWFstatMapVersion, self.tCWFstatMapFeatures,
self.FstatResults.multiFatoms[0], self.windowRange) self.FstatResults.multiFatoms[0], self.windowRange)
...@@ -724,13 +716,6 @@ class ComputeFstat(BaseSearchClass): ...@@ -724,13 +716,6 @@ class ComputeFstat(BaseSearchClass):
else: else:
F_mn = self.FstatMap.F_mn F_mn = self.FstatMap.F_mn
# logging.debug('maxF: {}'.format(self.FstatMap.maxF))
# logging.debug('t0_ML: %ds=T0+%fd' % (
# self.FstatMap.t0_ML, (self.FstatMap.t0_ML-tstart)/(3600.*24.)))
# logging.debug('tau_ML: %ds=%fd' % (
# self.FstatMap.tau_ML, self.FstatMap.tau_ML/(3600.*24.)))
# logging.debug('F_mn: {}'.format(F_mn))
twoF = 2*np.max(F_mn) twoF = 2*np.max(F_mn)
if self.BSGL is False: if self.BSGL is False:
if np.isnan(twoF): if np.isnan(twoF):
......
...@@ -435,6 +435,10 @@ class TransientGridSearch(GridSearch): ...@@ -435,6 +435,10 @@ class TransientGridSearch(GridSearch):
self.inititate_search_object() self.inititate_search_object()
data = [] data = []
if self.outputTransientFstatMap:
tCWfilebase = os.path.splitext(self.out_file)[0] + '_tCW_'
logging.info('Will save per-Doppler Fstatmap' \
' results to {}*.dat'.format(tCWfilebase))
for vals in tqdm(self.input_data): for vals in tqdm(self.input_data):
detstat = self.search.get_det_stat(*vals) detstat = self.search.get_det_stat(*vals)
windowRange = getattr(self.search, 'windowRange', None) windowRange = getattr(self.search, 'windowRange', None)
...@@ -446,11 +450,18 @@ class TransientGridSearch(GridSearch): ...@@ -446,11 +450,18 @@ class TransientGridSearch(GridSearch):
else: else:
F_mn = FstatMap.F_mn F_mn = FstatMap.F_mn
if self.outputTransientFstatMap: if self.outputTransientFstatMap:
tCWfile = os.path.splitext(self.out_file)[0]+'_tCW_%.16f_%.16f_%.16f_%.16g_%.16g.dat' % (vals[2],vals[5],vals[6],vals[3],vals[4]) # freq alpha delta f1dot f2dot # per-Doppler filename convention:
# freq alpha delta f1dot f2dot
tCWfile = ( tCWfilebase
+ '%.16f_%.16f_%.16f_%.16g_%.16g.dat' %
(vals[2],vals[5],vals[6],vals[3],vals[4]) )
if self.tCWFstatMapVersion == 'lal': if self.tCWFstatMapVersion == 'lal':
fo = lal.FileOpen(tCWfile, 'w') fo = lal.FileOpen(tCWfile, 'w')
lalpulsar.write_transientFstatMap_to_fp ( fo, FstatMap, windowRange, None ) lalpulsar.write_transientFstatMap_to_fp (
del fo # instead of lal.FileClose() which is not SWIG-exported fo, FstatMap, windowRange, None )
# instead of lal.FileClose(),
# which is not SWIG-exported:
del fo
else: else:
self.write_F_mn ( tCWfile, F_mn, windowRange) self.write_F_mn ( tCWfile, F_mn, windowRange)
maxidx = np.unravel_index(F_mn.argmax(), F_mn.shape) maxidx = np.unravel_index(F_mn.argmax(), F_mn.shape)
......
...@@ -26,7 +26,8 @@ __global__ void cudaTransientFstatExpWindow ( float *input, ...@@ -26,7 +26,8 @@ __global__ void cudaTransientFstatExpWindow ( float *input,
/* compute Fstat-atom index i_t0 in [0, numAtoms) */ /* compute Fstat-atom index i_t0 in [0, numAtoms) */
unsigned int TAtomHalf = TAtom/2; // integer division unsigned int TAtomHalf = TAtom/2; // integer division
unsigned int t0 = win_t0 + m * win_dt0; unsigned int t0 = win_t0 + m * win_dt0;
int i_tmp = ( t0 - t0_data + TAtomHalf ) / TAtom; // integer round: floor(x+0.5) /* integer round: floor(x+0.5) */
int i_tmp = ( t0 - t0_data + TAtomHalf ) / TAtom;
if ( i_tmp < 0 ) { if ( i_tmp < 0 ) {
i_tmp = 0; i_tmp = 0;
} }
...@@ -35,22 +36,26 @@ __global__ void cudaTransientFstatExpWindow ( float *input, ...@@ -35,22 +36,26 @@ __global__ void cudaTransientFstatExpWindow ( float *input,
i_t0 = numAtoms - 1; i_t0 = numAtoms - 1;
} }
/* translate n into an atoms end-index for this search interval [t0, t0+Tcoh], /* translate n into an atoms end-index
* for this search interval [t0, t0+Tcoh],
* giving the index range of atoms to sum over * giving the index range of atoms to sum over
*/ */
unsigned int tau = win_tau + n * win_dtau; unsigned int tau = win_tau + n * win_dtau;
/* get end-time t1 of this transient-window search /* get end-time t1 of this transient-window search
* for given tau, what Tcoh should the exponential window cover? * for given tau, what Tcoh should the exponential window cover?
* for speed reasons we want to truncate Tcoh = tau * TRANSIENT_EXP_EFOLDING * for speed reasons we want to truncate
* Tcoh = tau * TRANSIENT_EXP_EFOLDING
* with the e-folding factor chosen such that the window-value * with the e-folding factor chosen such that the window-value
* is practically negligible after that, where it will be set to 0 * is practically negligible after that, where it will be set to 0
*/ */
// unsigned int t1 = lround( win_t0 + TRANSIENT_EXP_EFOLDING * win_tau); // unsigned int t1 = lround( win_t0 + TRANSIENT_EXP_EFOLDING * win_tau);
unsigned int t1 = t0 + TRANSIENT_EXP_EFOLDING * tau; unsigned int t1 = t0 + TRANSIENT_EXP_EFOLDING * tau;
/* compute window end-time Fstat-atom index i_t1 in [0, numAtoms) */ /* compute window end-time Fstat-atom index i_t1 in [0, numAtoms)
i_tmp = ( t1 - t0_data + TAtomHalf ) / TAtom - 1; // integer round: floor(x+0.5) * using integer round: floor(x+0.5)
*/
i_tmp = ( t1 - t0_data + TAtomHalf ) / TAtom - 1;
if ( i_tmp < 0 ) { if ( i_tmp < 0 ) {
i_tmp = 0; i_tmp = 0;
} }
......
...@@ -20,7 +20,8 @@ __global__ void cudaTransientFstatRectWindow ( float *input, ...@@ -20,7 +20,8 @@ __global__ void cudaTransientFstatRectWindow ( float *input,
/* compute Fstat-atom index i_t0 in [0, numAtoms) */ /* compute Fstat-atom index i_t0 in [0, numAtoms) */
unsigned int TAtomHalf = TAtom/2; // integer division unsigned int TAtomHalf = TAtom/2; // integer division
unsigned int t0 = win_t0 + m * win_dt0; unsigned int t0 = win_t0 + m * win_dt0;
int i_tmp = ( t0 - t0_data + TAtomHalf ) / TAtom; // integer round: floor(x+0.5) /* integer round: floor(x+0.5) */
int i_tmp = ( t0 - t0_data + TAtomHalf ) / TAtom;
if ( i_tmp < 0 ) { if ( i_tmp < 0 ) {
i_tmp = 0; i_tmp = 0;
} }
...@@ -46,7 +47,8 @@ __global__ void cudaTransientFstatRectWindow ( float *input, ...@@ -46,7 +47,8 @@ __global__ void cudaTransientFstatRectWindow ( float *input,
if ( (m < N_tauRange) && (n < N_tauRange) ) { if ( (m < N_tauRange) && (n < N_tauRange) ) {
/* translate n into an atoms end-index for this search interval [t0, t0+Tcoh], /* translate n into an atoms end-index
* for this search interval [t0, t0+Tcoh],
* giving the index range of atoms to sum over * giving the index range of atoms to sum over
*/ */
unsigned int tau = win_tau + n * win_dtau; unsigned int tau = win_tau + n * win_dtau;
...@@ -54,8 +56,10 @@ __global__ void cudaTransientFstatRectWindow ( float *input, ...@@ -54,8 +56,10 @@ __global__ void cudaTransientFstatRectWindow ( float *input,
/* get end-time t1 of this transient-window search */ /* get end-time t1 of this transient-window search */
unsigned int t1 = t0 + tau; unsigned int t1 = t0 + tau;
/* compute window end-time Fstat-atom index i_t1 in [0, numAtoms) */ /* compute window end-time Fstat-atom index i_t1 in [0, numAtoms)
i_tmp = ( t1 - t0_data + TAtomHalf ) / TAtom - 1; // integer round: floor(x+0.5) * using integer round: floor(x+0.5)
*/
i_tmp = ( t1 - t0_data + TAtomHalf ) / TAtom - 1;
if ( i_tmp < 0 ) { if ( i_tmp < 0 ) {
i_tmp = 0; i_tmp = 0;
} }
...@@ -72,7 +76,8 @@ __global__ void cudaTransientFstatRectWindow ( float *input, ...@@ -72,7 +76,8 @@ __global__ void cudaTransientFstatRectWindow ( float *input,
/* sum up atoms, /* sum up atoms,
* special optimiziation in the rectangular-window case: * special optimiziation in the rectangular-window case:
* just add on to previous tau values, * just add on to previous tau values,
* ie re-use the sum over [i_t0, i_t1_last] from the pevious tau-loop iteration * ie re-use the sum over [i_t0, i_t1_last]
from the pevious tau-loop iteration
*/ */
Ad += input[i*input_cols+0]; // a2_alpha Ad += input[i*input_cols+0]; // a2_alpha
Bd += input[i*input_cols+1]; // b2_alpha Bd += input[i*input_cols+1]; // b2_alpha
......
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment