Skip to content

Commit 508ce26

Browse files
committed
try fixing early thread exit in ndeg twisted mass
1 parent 9f3a60e commit 508ce26

1 file changed

Lines changed: 20 additions & 16 deletions

File tree

include/kernels/dslash_ndeg_twisted_mass_preconditioned.cuh

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ namespace quda
7373
int src_idx = src_flavor / 2;
7474
int flavor = src_flavor % 2;
7575

76+
bool active2 = mykernel_type != EXTERIOR_KERNEL_ALL; // is thread active (non-trival for fused kernel only)
7677
int thread_dim; // which dimension is thread working on (fused kernel only)
7778
auto coord = getCoords<QUDA_4D_PC, mykernel_type>(arg, idx, flavor, parity, thread_dim);
7879

@@ -86,16 +87,15 @@ namespace quda
8687
active = false;
8788
}
8889
}
89-
active &= mykernel_type != EXTERIOR_KERNEL_ALL; // is thread active (non-trival for fused kernel only)
9090

9191
if (!allthreads || active) {
9292
if (!dagger || Arg::asymmetric) // defined in dslash_wilson.cuh
93-
applyWilson<dagger, mykernel_type>(out, arg, coord, parity, idx, thread_dim, active, src_idx);
93+
applyWilson<dagger, mykernel_type>(out, arg, coord, parity, idx, thread_dim, active2, src_idx);
9494
else // defined in dslash_twisted_mass_preconditioned
95-
applyWilsonTM<dagger, 2, mykernel_type>(out, arg, coord, parity, idx, thread_dim, active, src_idx);
95+
applyWilsonTM<dagger, 2, mykernel_type>(out, arg, coord, parity, idx, thread_dim, active2, src_idx);
9696
}
9797

98-
if (active) {
98+
if (!allthreads || active) {
9999
if (xpay && mykernel_type == INTERIOR_KERNEL && !arg.dd_x.isZero(coord)) {
100100
if constexpr (!dagger || Arg::asymmetric) { // apply inverse twist which is undone below
101101
// use consistent load order across s to ensure better cache locality
@@ -109,7 +109,7 @@ namespace quda
109109
Vector x = arg.x[src_idx](my_flavor_idx, my_spinor_parity);
110110
out += x; // just directly add since twist already applied in the dslash
111111
}
112-
} else if (mykernel_type != INTERIOR_KERNEL) {
112+
} else if (mykernel_type != INTERIOR_KERNEL && active2) {
113113
// if we're not the interior kernel, then we must sum the partial
114114
Vector x = arg.out[src_idx](my_flavor_idx, my_spinor_parity);
115115
out += x;
@@ -118,20 +118,24 @@ namespace quda
118118

119119
if constexpr (!dagger || Arg::asymmetric) { // apply A^{-1} to D*in
120120
SharedMemoryCache<Vector> cache {*this};
121-
if (isComplete<mykernel_type>(arg, coord) && active) {
122-
// to apply the preconditioner we need to put "out" in shared memory so the other flavor can access it
123-
cache.save(out);
124-
}
121+
if (!allthreads || active) {
122+
if (isComplete<mykernel_type>(arg, coord) && active2) {
123+
// to apply the preconditioner we need to put "out" in shared memory so the other flavor can access it
124+
cache.save(out);
125+
}
126+
}
125127
cache.sync(); // safe to sync here since other threads will exit if allowed, or all be here
126-
if (isComplete<mykernel_type>(arg, coord) && active) {
127-
if (flavor == 0)
128-
out = arg.a * (out + arg.b * out.igamma(4) + arg.c * cache.load_y(target::thread_idx().y + 1));
129-
else
130-
out = arg.a * (out - arg.b * out.igamma(4) + arg.c * cache.load_y(target::thread_idx().y - 1));
131-
}
128+
if (!allthreads || active) {
129+
if (isComplete<mykernel_type>(arg, coord) && active2) {
130+
if (flavor == 0)
131+
out = arg.a * (out + arg.b * out.igamma(4) + arg.c * cache.load_y(target::thread_idx().y + 1));
132+
else
133+
out = arg.a * (out - arg.b * out.igamma(4) + arg.c * cache.load_y(target::thread_idx().y - 1));
134+
}
135+
}
132136
}
133137

134-
if (active) arg.out[src_idx](my_flavor_idx, my_spinor_parity) = out;
138+
if (active && active2) arg.out[src_idx](my_flavor_idx, my_spinor_parity) = out;
135139
}
136140
};
137141

0 commit comments

Comments
 (0)