Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duplicated code #9

Open
mkolopanis opened this issue May 27, 2020 · 4 comments
Open

Duplicated code #9

mkolopanis opened this issue May 27, 2020 · 4 comments

Comments

@mkolopanis
Copy link
Collaborator

LWA_bifrost.py and LWA_bifrost_DFT.py have lots of duplicated code.
Some questions we should consider

  • Can we move dupliacted code to helper module?
  • Lots of these objects in the scripts are very similar, is it possible to make a base object and have it subclassed?
  • Does the DFT script do everything the same as the original just add additional functionality and as an extension do we need both scripts?
@jaycedowell
Copy link

We might be able to address some of this with judicious use of bifrost.pipeline.
Here is an example of what the interface is like but I personally haven't used it.

@mkolopanis
Copy link
Collaborator Author

I've been looking more into cleaning up the two scripts I mentioned. I've found the following major difference between the MOFF correlator implementations. When implementing the romein kernel, the non-dft version of the code uses polmajor=False in the two instances polmajor appears as a function kwarg. The DFT version always uses polmajor=True though.

Reading through the kernel source code, setting polmajor=True basically forces a single polarization. Is this the expected behavior @KentJames? Or maybe the code split off and at some point polmajor was set to false in the non-DFT but never updated in the DFT script?

I'm looking to combine these into just one script. They are nearly identical and the DFT one only seems to add functionality except for the polmajor keyword (and a reordering of axes which I don't think should be a major issue).

LWA_EPIC/LWA/LWA_bifrost.py

Lines 939 to 945 in f22d933

try:
bf_romein.execute(udata, gdata)
except NameError:
bf_romein = Romein()
bf_romein.init(self.locs, gphases, self.grid_size, polmajor=False)
bf_romein.execute(udata, gdata)
gdata = gdata.reshape(self.ntime_gulp * nchan * npol, self.grid_size, self.grid_size)

try:
bf_romein.execute(udata, gdata)
except NameError:
bf_romein = Romein()
bf_romein.init(self.locs, gphases, self.grid_size, polmajor=True)
bf_romein.execute(udata, gdata)
gdata = gdata.reshape(self.ntime_gulp * nchan * npol, self.grid_size, self.grid_size)

https://github.com/epic-astronomy/bifrost/blob/34a0671fc31a417b9266dd07eef566f37d7ecb96/src/romein.cu#L251-L273

current implementation when the link was taken:

template<typename InType, typename OutType>
inline void launch_romein_kernel(int      nbaseline,
                                 int      npol,
                                 bool     polmajor,
                                 int      maxsupport, 
                                 int      gridsize, 
                                 int      nbatch,
                                 int*     xpos,
                                 int*     ypos,
                                 int*     zpos,
                                 OutType* kernels,
                                 InType*  d_in,
                                 OutType* d_out,
                                 cudaStream_t stream=0) {
    //cout << "LAUNCH for " << nelement << endl;
    dim3 block(8,1);
    dim3 grid(nbatch*npol,1);
    if( polmajor ) {
        npol = 1;
    } else {
        block.y = npol;
        grid.x = nbatch;
    }

@mkolopanis
Copy link
Collaborator Author

looking at the git blame on LWA_bifrost.py, the polmajor=False was set after the DFT code was created. Perhaps the update just never flowed through.

@mkolopanis
Copy link
Collaborator Author

looks like this may also be the case with the antenna dimension ordering?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants