lattice / quda

QUDA is a library for performing calculations in lattice QCD on GPUs.
https://lattice.github.io/quda
Other
292 stars 99 forks source link

QUDA interface `freeGaugeQuda` clean-up #1362

Closed weinbe2 closed 1 year ago

weinbe2 commented 1 year ago

This PR does a good deal of clean-up/removal of code duplication related to how gauge fields are freed in interface_quda.cpp, largely by introducing a new function freeUniqueGaugeQuda(...); which narrowly frees the "regular" gauge fields, the fat fields, the long fields, and the smeared fields depending on the argument passed in.

This is also a hotfix PR because it fixes a bug introduced in the MILC gauge observable PR. In this PR, the new MILC interface observable routines loaded the gauge field via loadGaugeQuda, allocating the precise field and making aliases for the sloppy, refinement, etc field. This conflicted with the existing routine to update the gauge fields, which as part of maintaining/updating residency would narrowly delete just the precise field without any consistent clean-up of the sloppy fields, etc. In many cases this skated by on UB --- the host structure memory which was allocated incidentally remained "uncleaned" so the sloppy fields could still be accessed. In recent tests, though, this triggered segfaults due to accessing already free'd memory (as it should).

Since this PR touches the infrastructure to free internal fields in many different places, it needs to be tested across many applications before being merged, so I've tagged multiple people who work on a range of different applications.

weinbe2 commented 1 year ago

@maddyscientist @mathiaswagner when y'all have a moment, can you do a follow-up visual review of the code? @hummingtree helped me find a typo (thanks!), so I feel a few more independent reviews would be nice...