Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
ee86d15
Apply the test utilities' staggered phases in all four directions wit…
weinbe2 Nov 23, 2026
8793830
Add gauge_phase_test for the staggered phases of device, extended and…
weinbe2 Nov 23, 2026
af3f616
Take the staggered phases and t boundary sign of every site of a gaug…
weinbe2 Nov 23, 2026
b35f916
Label MILC's phased links antiperiodic for the gauge observables, so …
weinbe2 Nov 23, 2026
b853dd3
Apply the antiperiodic t sign to the last three time slices of long l…
weinbe2 Nov 23, 2026
9935de4
Add GaugeField::applyTBoundary and removeTBoundary, which put the ant…
weinbe2 Nov 23, 2026
c80d6b4
Keep the regular grid dims local to GaugePhaseGeometry's constructor,…
weinbe2 Nov 23, 2026
f214686
Count only the t links of the time slices that cross the t boundary, …
weinbe2 Nov 23, 2026
107343f
Test GaugeField::applyTBoundary and removeTBoundary on long links wit…
weinbe2 Nov 23, 2026
454115c
Reject long links with reconstruct 12 or 8 in applyGaugeTBoundary, wh…
weinbe2 Nov 23, 2026
5b4f766
Index the sites of extended fields by the parity of their interior co…
weinbe2 Nov 23, 2026
611c812
Test that the staggered phases of thin links carry an imaginary chemi…
weinbe2 Nov 23, 2026
b047115
Run gauge_phase_test with x, z and t partitioned, so that extended fi…
weinbe2 Nov 23, 2026
36d6a83
Label the sites of extended gauge fields by the parity of their regul…
weinbe2 Nov 23, 2026
065f0a7
Make getGlobalCoords a member of GaugePhaseGeometry, with the wrappin…
weinbe2 Nov 23, 2026
d8e2dde
Compare gauge_phase_test's extended fields, halo included, with the t…
weinbe2 Nov 23, 2026
1c544c8
Compare gauge_phase_test's gauge forces with the test utilities' mome…
weinbe2 Nov 23, 2026
82464b0
Name gauge_phase_test's staggered phase conventions with a new get_st…
weinbe2 Nov 23, 2026
42172df
Add an applyGaugeTemporalBCs overload for host gauge fields, which ta…
weinbe2 Nov 23, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions include/gauge_field.h
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,21 @@ namespace quda {
*/
void removeStaggeredPhase();

/**
@brief Put the antiperiodic t boundary sign into the links of a field without staggered phases: negate the t
links of the last global time slice, or of the last three for long links, halo included, and record an
antiperiodic t boundary, which for such fields means that the links hold the sign. The field must record a
periodic t boundary, be in native order with reconstruct NO, 13, 12, 9 or 8 (NO, 13 or 9 for long links), and
for reconstruct 12 and 8 have no imaginary chemical potential.
*/
void applyTBoundary();

/**
@brief Take the antiperiodic t boundary sign out of the links of a field without staggered phases, and record
a periodic t boundary; the reverse of applyTBoundary
*/
void removeTBoundary();

/**
Return the imaginary chemical potential applied to this field
*/
Expand Down Expand Up @@ -807,6 +822,14 @@ namespace quda {
*/
void applyGaugePhase(GaugeField &u);

/**
@brief Negate the t links that cross the t boundary: those of the last global time slice, or of the last three
for long links, halo included. The field's t boundary label is left to the caller.
@param[in,out] u The gauge field, in native order with reconstruct NO, 13, 12, 9 or 8 (NO, 13 or 9 for long
links), and for reconstruct 12 and 8 no imaginary chemical potential
*/
void applyGaugeTBoundary(GaugeField &u);

/**
Compute XOR-based checksum of this gauge field: each gauge field entry is
converted to type uint64_t, and compute the cummulative XOR of these values.
Expand Down
3 changes: 2 additions & 1 deletion include/kernels/extract_gauge_ghost_extended.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ namespace quda {
int d = D0 + gd - g *arg.R[dim];

// we only do the extraction for parity we are currently working on
int oddness = (a+b+c+d) & 1;
// sites are labelled by the parity of their regular coordinates, as in the rest of the field
int oddness = (a + b + c + d + arg.R[0] + arg.R[1] + arg.R[2] + arg.R[3]) & 1;
if (oddness == parity) {
if (Arg::extract) extractor(arg, dir, a, b, c, d, g, parity);
else injector(arg, dir, a, b, c, d, g, parity);
Expand Down
163 changes: 129 additions & 34 deletions include/kernels/gauge_phase.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -5,87 +5,148 @@
#include <kernel.h>
#include <math_helper.h>

namespace quda {
namespace quda
{

/**
@brief Where the sites of a gauge field are on the global lattice, halo included, and which t links cross the
t boundary
*/
struct GaugePhaseGeometry {
int_fastdiv E[4]; // extended grid dims
int border[4];
int offset[4]; // global coordinates of the rank's first regular site
int_fastdiv G[4]; // global grid dims
int parity_shift; // sites are labelled by their regular parity: this changes it to that of their coordinates
int boundary_slices; // the last global time slices whose t links cross the boundary: three for long links

GaugePhaseGeometry(const GaugeField &u)
{
parity_shift = 0;
for (int d = 0; d < 4; d++) {
E[d] = u.X()[d];
border[d] = u.R()[d];
const int X = u.X()[d] - 2 * border[d];
offset[d] = comm_coord(d) * X;
G[d] = comm_dim(d) * X;
parity_shift += border[d];
}
parity_shift &= 1;
boundary_slices = u.LinkType() == QUDA_THREE_LINKS ? 3 : 1;
}

/**
@brief Whether the t links of a global time slice cross the t boundary
@param[in] t The global t coordinate
*/
__device__ __host__ inline bool crossesTBoundary(int t) const { return t >= G[3] - boundary_slices; }

/**
@brief The global coordinate of a coordinate of the field, halo included, which wraps around the global lattice
@param[in] d The direction
@param[in] x The coordinate in the field
*/
__device__ __host__ inline int globalCoord(int d, int x) const { return (x - border[d] + offset[d] + G[d]) % G[d]; }

/**
@brief The global coordinates of a site of the field, halo included
@param[out] x The coordinates
@param[in] x_cb The site's checkerboard index in the field
@param[in] parity The site's parity label
*/
__device__ __host__ inline void getGlobalCoords(int x[4], int x_cb, int parity) const
{
getCoords(x, x_cb, E, (parity + parity_shift) & 1);
#pragma unroll
for (int d = 0; d < 4; d++) x[d] = globalCoord(d, x[d]);
}

/**
@brief The number of time slices of the field, halo included, whose t links cross the t boundary
*/
int boundaryTimeSlices() const
{
int n = 0;
for (int t = 0; t < E[3]; t++) n += crossesTBoundary(globalCoord(3, t));
return n;
}
};

template <typename Float_, int nColor_, QudaReconstructType recon_, QudaStaggeredPhase phase_>
struct GaugePhaseArg : kernel_param<> {
struct GaugePhaseArg : kernel_param<>, GaugePhaseGeometry {
using Float = Float_;
using real = typename mapper<Float>::type;
static constexpr int nColor = nColor_;
static_assert(nColor == 3, "Only nColor=3 enabled at this time");
static constexpr QudaReconstructType recon = recon_;
static constexpr QudaStaggeredPhase phase = phase_;
typedef typename gauge_mapper<Float,recon>::type Gauge;
typedef typename gauge_mapper<Float, recon>::type Gauge;

Gauge u;
int X[4];
real tBoundary;
real i_mu;
complex<real> i_mu_phase;
GaugePhaseArg(GaugeField &u) : kernel_param(dim3(u.VolumeCB(), 2, 1)), u(u), i_mu(static_cast<real>(u.iMu()))
GaugePhaseArg(GaugeField &u) :
kernel_param(dim3(u.VolumeCB(), 2, 1)), GaugePhaseGeometry(u), u(u), i_mu(static_cast<real>(u.iMu()))
{
// if staggered phases are applied, then we are removing them
// else we are applying them
real dir = u.StaggeredPhaseApplied() ? real(-1.0) : real(1.0);

i_mu_phase = complex<real>(static_cast<real>(cos(M_PI * double(u.iMu()) / (u.X()[3] * comm_dim(3)))),
dir * static_cast<real>(sin(M_PI * double(u.iMu()) / (u.X()[3] * comm_dim(3)))));
const int T = G[3];
i_mu_phase = complex<real>(static_cast<real>(cos(M_PI * double(u.iMu()) / T)),
dir * static_cast<real>(sin(M_PI * double(u.iMu()) / T)));

for (int d=0; d<4; d++) X[d] = u.X()[d];

// only set the boundary condition on the last time slice of nodes
bool last_node_in_t = (commCoords(3) == commDim(3)-1);
tBoundary = static_cast<real>(static_cast<int>(last_node_in_t ? u.TBoundary() : QUDA_PERIODIC_T));
tBoundary = static_cast<real>(static_cast<int>(u.TBoundary()));
}
};

// FIXME need to check this with odd local volumes
template <int dim, typename Arg> constexpr auto getPhase(int x, int y, int z, int t, const Arg &arg) {
// x, y, z and t are a site's global coordinates
template <int dim, typename Arg> constexpr auto getPhase(int x, int y, int z, int t, const Arg &arg)
{
typename Arg::real phase = typename Arg::real(1.0);
if (Arg::phase == QUDA_STAGGERED_PHASE_MILC) {
if (dim==0) {
if (dim == 0) {
phase = (1 - 2 * (t % 2));
} else if (dim == 1) {
phase = (1 - 2 * ((t + x) % 2));
} else if (dim == 2) {
phase = (1 - 2 * ((t + x + y) % 2));
} else if (dim == 3) { // also apply boundary condition
phase = (t == arg.X[3] - 1) ? arg.tBoundary : typename Arg::real(1.0);
phase = arg.crossesTBoundary(t) ? arg.tBoundary : typename Arg::real(1.0);
}
} else if (Arg::phase == QUDA_STAGGERED_PHASE_TIFR) {
if (dim==0) {
if (dim == 0) {
phase = (1 - 2 * ((3 + t + z + y) % 2));
} else if (dim == 1) {
phase = (1 - 2 * ((2 + t + z) % 2));
} else if (dim == 2) {
phase = (1 - 2 * ((1 + t) % 2));
} else if (dim == 3) { // also apply boundary condition
phase = (t == arg.X[3] - 1) ? arg.tBoundary : typename Arg::real(1.0);
phase = arg.crossesTBoundary(t) ? arg.tBoundary : typename Arg::real(1.0);
}
} else if (Arg::phase == QUDA_STAGGERED_PHASE_CHROMA) {
// Chroma follows CPS convention, but uses -Dslash instead of Dslash compared to QUDA
if (dim==0) {
phase = -1.0;
if (dim == 0) {
phase = -1.0;
} else if (dim == 1) {
phase = (1 - 2 * ((1 + x) % 2));
} else if (dim == 2) {
phase = (1 - 2 * ((1 + x + y) % 2));
} else if (dim == 3) { // also apply boundary condition
phase = ((t == arg.X[3] - 1) ? arg.tBoundary : typename Arg::real(1.0)) * (1 - 2 * ((1 + x + y + z) % 2));
phase = (arg.crossesTBoundary(t) ? arg.tBoundary : typename Arg::real(1.0)) * (1 - 2 * ((1 + x + y + z) % 2));
}
}
return phase;
}

template <int dim, typename Arg>
__device__ __host__ void gaugePhase(int indexCB, int parity, const Arg &arg) {
__device__ __host__ void gaugePhase(const int x[4], int indexCB, int parity, const Arg &arg)
{
using real = typename Arg::real;

int x[4];
getCoords(x, indexCB, arg.X, parity);

real phase = getPhase<dim>(x[0], x[1], x[2], x[3], arg);
Matrix<complex<real>,Arg::nColor> u = arg.u(dim, indexCB, parity);
Matrix<complex<real>, Arg::nColor> u = arg.u(dim, indexCB, parity);
u *= phase;

// apply imaginary chemical potential if needed
Expand All @@ -94,19 +155,53 @@ namespace quda {
arg.u(dim, indexCB, parity) = u;
}

template <typename Arg> struct GaugePhase
{
template <typename Arg> struct GaugePhase {
const Arg &arg;
constexpr GaugePhase(const Arg &arg) : arg(arg) { }
static constexpr const char *filename() { return KERNEL_FILE; }

__device__ __host__ void operator()(int x_cb, int parity)
{
int x[4];
arg.getGlobalCoords(x, x_cb, parity);
gaugePhase<0>(x, x_cb, parity, arg);
gaugePhase<1>(x, x_cb, parity, arg);
gaugePhase<2>(x, x_cb, parity, arg);
gaugePhase<3>(x, x_cb, parity, arg);
}
};

template <typename Float_, int nColor_, QudaReconstructType recon_>
struct GaugeTBoundaryArg : kernel_param<>, GaugePhaseGeometry {
using Float = Float_;
using real = typename mapper<Float>::type;
static constexpr int nColor = nColor_;
static_assert(nColor == 3, "Only nColor=3 enabled at this time");
static constexpr QudaReconstructType recon = recon_;
typedef typename gauge_mapper<Float, recon>::type Gauge;

Gauge u;
GaugeTBoundaryArg(GaugeField &u) : kernel_param(dim3(u.VolumeCB(), 2, 1)), GaugePhaseGeometry(u), u(u) { }
};

/**
@brief Negate the t links that cross the t boundary. They are loaded under the field's t boundary label and
stored without it: the reconstructions pack a link without the label, which only the unpacking uses.
*/
template <typename Arg> struct GaugeTBoundary {
const Arg &arg;
constexpr GaugePhase(const Arg &arg) : arg(arg) {}
constexpr GaugeTBoundary(const Arg &arg) : arg(arg) { }
static constexpr const char *filename() { return KERNEL_FILE; }

__device__ __host__ void operator()(int x_cb, int parity)
{
gaugePhase<0>(x_cb, parity, arg);
gaugePhase<1>(x_cb, parity, arg);
gaugePhase<2>(x_cb, parity, arg);
gaugePhase<3>(x_cb, parity, arg);
int x[4];
arg.getGlobalCoords(x, x_cb, parity);
if (!arg.crossesTBoundary(x[3])) return;
Matrix<complex<typename Arg::real>, Arg::nColor> u = arg.u(3, x_cb, parity);
u *= static_cast<typename Arg::real>(-1.0);
arg.u(3, x_cb, parity) = u;
}
};

}
} // namespace quda
4 changes: 2 additions & 2 deletions include/quda.h
Original file line number Diff line number Diff line change
Expand Up @@ -1481,8 +1481,8 @@ extern "C" {
/**
* Apply the staggered phase factors to the gauge field. If the
* imaginary chemical potential is non-zero then the phase factor
* exp(imu/T) will be applied to the links in the temporal
* direction.
* exp(i pi i_mu / T), T being the global time extent, will be
* applied to every link in the temporal direction.
*
* @param gauge_h The gauge field
* @param param The parameters of the gauge field
Expand Down
37 changes: 37 additions & 0 deletions lib/gauge_field.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,43 @@ namespace quda {
staggeredPhaseApplied = false;
}

/**
@brief Check that a field's t boundary sign can be put into or taken out of its links
@param[in] u The field
@param[in] t_boundary The t boundary the field must record
@param[in] name The operation, for messages
*/
static void checkTBoundary(const GaugeField &u, QudaTboundary t_boundary, const char *name)
{
switch (u.StaggeredPhase()) {
case QUDA_STAGGERED_PHASE_MILC:
case QUDA_STAGGERED_PHASE_TIFR:
case QUDA_STAGGERED_PHASE_CHROMA:
errorQuda("%s: the t boundary sign of a field with staggered phase type %d goes with its phases", name,
u.StaggeredPhase());
default: break;
}
if (u.TBoundary() != t_boundary)
errorQuda("%s: the field records t boundary %d, not %d", name, u.TBoundary(), t_boundary);
if (!u.isNative()) errorQuda("%s: the field is in order %d, not native order", name, u.Order());
}

void GaugeField::applyTBoundary()
{
checkTBoundary(*this, QUDA_PERIODIC_T, __func__);
applyGaugeTBoundary(*this);
t_boundary = QUDA_ANTI_PERIODIC_T;
if (ghostExchange == QUDA_GHOST_EXCHANGE_PAD) exchangeGhost();
}

void GaugeField::removeTBoundary()
{
checkTBoundary(*this, QUDA_ANTI_PERIODIC_T, __func__);
applyGaugeTBoundary(*this);
t_boundary = QUDA_PERIODIC_T;
if (ghostExchange == QUDA_GHOST_EXCHANGE_PAD) exchangeGhost();
}

void GaugeField::createComms(const lat_dim_t &R, bool no_comms_fill, bool bidir)
{
allocateGhostBuffer(R, no_comms_fill, bidir); // allocate the ghost buffer if not yet allocated
Expand Down
48 changes: 48 additions & 0 deletions lib/gauge_phase.cu
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,59 @@ namespace quda {

void applyGaugePhase(GaugeField &u)
{
if (u.LinkType() == QUDA_THREE_LINKS && u.iMu() != 0.0)
errorQuda("The imaginary chemical potential (i_mu = %g) is not supported on long links",
static_cast<double>(u.iMu()));
getProfile().TPSTART(QUDA_PROFILE_COMPUTE);
instantiate<GaugePhase_, ReconstructNone>(u);
// ensure that ghosts are updated if needed
if (u.GhostExchange() == QUDA_GHOST_EXCHANGE_PAD) u.exchangeGhost();
getProfile().TPSTOP(QUDA_PROFILE_COMPUTE);
}

template <typename Float, int nColor, QudaReconstructType recon> class GaugeTBoundary_ : TunableKernel2D
{
GaugeField &u; // used for meta data only
long long boundary_bytes;
unsigned int minThreads() const { return u.VolumeCB(); }

public:
GaugeTBoundary_(GaugeField &u) :
TunableKernel2D(u, 2),
u(u),
boundary_bytes(2 * (u.Bytes() / 4) * GaugePhaseGeometry(u).boundaryTimeSlices() / u.X()[3])
{
strcat(aux, "t_boundary");
apply(device::get_default_stream());
}

void apply(const qudaStream_t &stream)
{
TuneParam tp = tuneLaunch(*this, getTuning(), getVerbosity());
launch<GaugeTBoundary>(tp, stream, GaugeTBoundaryArg<Float, nColor, recon>(u));
}

void preTune() { u.backup(); }
void postTune() { u.restore(); }

long long flops() const { return 0; }
long long bytes() const { return boundary_bytes; }
};

void applyGaugeTBoundary(GaugeField &u)
{
const bool recon_12_8 = u.Reconstruct() == QUDA_RECONSTRUCT_12 || u.Reconstruct() == QUDA_RECONSTRUCT_8;
if (u.LinkType() == QUDA_THREE_LINKS && recon_12_8)
errorQuda("Reconstruct %d rebuilds the t boundary sign on one time slice, not the three of long links",
u.Reconstruct());
// a field without phases holds i_mu only if its links were given the potential's U(1) phase, which reconstruct 12
// and 8 cannot represent
if (recon_12_8 && u.iMu() != 0.0)
errorQuda("Reconstruct %d cannot hold the imaginary chemical potential (i_mu = %g)", u.Reconstruct(),
static_cast<double>(u.iMu()));
getProfile().TPSTART(QUDA_PROFILE_COMPUTE);
instantiate<GaugeTBoundary_, ReconstructGauge>(u);
getProfile().TPSTOP(QUDA_PROFILE_COMPUTE);
}

} // namespace quda
Loading
Loading