gputls 2.0.1__tar.gz → 2.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (25) hide show
  1. {gputls-2.0.1/src/gputls.egg-info → gputls-2.1.0}/PKG-INFO +1 -1
  2. {gputls-2.0.1 → gputls-2.1.0}/src/gputls/core.py +71 -18
  3. {gputls-2.0.1 → gputls-2.1.0}/src/gputls/kernels.cu +142 -99
  4. {gputls-2.0.1 → gputls-2.1.0}/src/gputls/version.py +1 -1
  5. {gputls-2.0.1 → gputls-2.1.0/src/gputls.egg-info}/PKG-INFO +1 -1
  6. {gputls-2.0.1 → gputls-2.1.0}/LICENSE +0 -0
  7. {gputls-2.0.1 → gputls-2.1.0}/README.md +0 -0
  8. {gputls-2.0.1 → gputls-2.1.0}/pyproject.toml +0 -0
  9. {gputls-2.0.1 → gputls-2.1.0}/setup.cfg +0 -0
  10. {gputls-2.0.1 → gputls-2.1.0}/src/gputls/__init__.py +0 -0
  11. {gputls-2.0.1 → gputls-2.1.0}/src/gputls/constants.py +0 -0
  12. {gputls-2.0.1 → gputls-2.1.0}/src/gputls/grid.py +0 -0
  13. {gputls-2.0.1 → gputls-2.1.0}/src/gputls/helpers.py +0 -0
  14. {gputls-2.0.1 → gputls-2.1.0}/src/gputls/interpolation.py +0 -0
  15. {gputls-2.0.1 → gputls-2.1.0}/src/gputls/main.py +0 -0
  16. {gputls-2.0.1 → gputls-2.1.0}/src/gputls/results.py +0 -0
  17. {gputls-2.0.1 → gputls-2.1.0}/src/gputls/stats.py +0 -0
  18. {gputls-2.0.1 → gputls-2.1.0}/src/gputls/transit.py +0 -0
  19. {gputls-2.0.1 → gputls-2.1.0}/src/gputls/validate.py +0 -0
  20. {gputls-2.0.1 → gputls-2.1.0}/src/gputls.egg-info/SOURCES.txt +0 -0
  21. {gputls-2.0.1 → gputls-2.1.0}/src/gputls.egg-info/dependency_links.txt +0 -0
  22. {gputls-2.0.1 → gputls-2.1.0}/src/gputls.egg-info/requires.txt +0 -0
  23. {gputls-2.0.1 → gputls-2.1.0}/src/gputls.egg-info/top_level.txt +0 -0
  24. {gputls-2.0.1 → gputls-2.1.0}/tests/test_gtls.py +0 -0
  25. {gputls-2.0.1 → gputls-2.1.0}/tests/test_tls_compare.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: gputls
3
- Version: 2.0.1
3
+ Version: 2.1.0
4
4
  Summary: GPU-accelerated Transit Least Squares (TLS) for periodic transit detection
5
5
  Author-email: Quanquan Hu <huqq1917@outlook.com>
6
6
  Maintainer-email: Quanquan Hu <huqq1917@outlook.com>
@@ -75,6 +75,29 @@ def start_strides(widths, margin):
75
75
  return np.where(widths > skip, widths // skip, 1).astype(np.int32)
76
76
 
77
77
 
78
+ WINDOW_LANES = (1, 2, 4, 8, 16, 32) # threads per window of the searchChi2_G* kernels
79
+ LANE_STEP_BYTES = 64 # bytes of start stride per thread of a window, see lanes_per_window
80
+ POINT_BYTES = 8 # bytes read per point by searchChi2 (float2 of w r and w)
81
+
82
+
83
+ def lanes_per_window(strides):
84
+ """Threads sharing one searchChi2 window: the smallest G in WINDOW_LANES with
85
+ stride * POINT_BYTES / G <= LANE_STEP_BYTES, at most 32.
86
+
87
+ One read instruction of a warp covers 32 / G windows of G consecutive points each, spaced
88
+ stride points apart: it spans stride / G times the bytes it uses, and the overlap of
89
+ neighbouring windows is reused stride / G steps later. Keeping stride / G <= 8 keeps both
90
+ small (bench/window_lanes on branch perf/window-lanes: within a few percent of the fastest
91
+ G for every stride, data size, batch size and L1 size measured). Depends only on the
92
+ stride, not on the device.
93
+ """
94
+ needed = np.asarray(strides, dtype=np.int64) * POINT_BYTES / LANE_STEP_BYTES
95
+ lanes = np.full(needed.shape, WINDOW_LANES[-1], dtype=np.int32)
96
+ for g in reversed(WINDOW_LANES):
97
+ lanes[needed <= g] = g
98
+ return lanes
99
+
100
+
78
101
  def duration_limit_args(R_star_min, R_star_max, M_star_min, M_star_max):
79
102
  """Scalar arguments (rShort, gmShort, rLong, gmLong, upperLimit) of the durationsGrid kernel.
80
103
 
@@ -92,14 +115,17 @@ def duration_limit_args(R_star_min, R_star_max, M_star_min, M_star_max):
92
115
  )
93
116
 
94
117
 
95
- def decode_keys(keys):
118
+ def decode_keys(keys, base):
96
119
  """Split searchChi2 keys into (chi2, flattened duration/start location).
97
120
 
98
- chi2 is NaN where no window was searched (key left at EMPTY_KEY).
121
+ The keys hold delta = chi2 - base in float32; chi2 = float32(base + delta), base being the
122
+ chi2 without transit (GPUSearch.base). chi2 is NaN where no window was searched (key left
123
+ at EMPTY_KEY).
99
124
  """
100
125
  high = (keys >> 32).astype(cp.uint32)
101
126
  bits = cp.where(high >= 0x80000000, high ^ 0x80000000, ~high).astype(cp.uint32)
102
- return bits.view(cp.float32), (keys & 0xFFFFFFFF).astype(cp.int64)
127
+ chi2 = (base + bits.view(cp.float32).astype(cp.float64)).astype(cp.float32)
128
+ return chi2, (keys & 0xFFFFFFFF).astype(cp.int64)
103
129
 
104
130
 
105
131
  class GPUSearch:
@@ -135,6 +161,20 @@ class GPUSearch:
135
161
  self.transit_depth_min = np.float32(transit_depth_min)
136
162
  self.constant_residual = float(np.sum(((1.0 - y) / dy) ** 2))
137
163
 
164
+ # chi2 without transit, sum of w r^2 as searchChi2 weights the points (patchWeighted):
165
+ # it does not depend on the order of the points, so it is the same for every period
166
+ dy2 = cp.maximum(self.dyGPU * self.dyGPU, cp.float32(1e-10))
167
+ weightedResidual = (cp.float32(1.0) / dy2) * self.residualGPU
168
+ self.base = float(cp.sum(weightedResidual.astype(cp.float64) * self.residualGPU.astype(cp.float64)))
169
+
170
+ # Fixed-point scale 2^E of the residual prefix sums (scanResidual): the largest E with
171
+ # patchedDatasSize * max|r| * 2^E < 2^62, so no prefix sum can overflow int64
172
+ bound = self.patchedDatasSize * float(cp.max(cp.abs(self.residualGPU)))
173
+ exponent = 62 - int(np.ceil(np.log2(bound))) if bound > 0 else 62
174
+ exponent = int(np.clip(exponent, -100, 100))
175
+ self.fixedScale = np.float32(2.0 ** exponent)
176
+ self.fixedInvScale = np.float32(2.0 ** -exponent)
177
+
138
178
  # Template depth profiles s = 1 - lc, one row per duration
139
179
  self.maxWidth = int(np.max(durations))
140
180
  signal = np.zeros((len(durations), self.maxWidth), dtype=np.float32)
@@ -186,12 +226,12 @@ class GPUSearch:
186
226
  raise ValueError("Too many start points per period for the GPU search")
187
227
 
188
228
  # Phase fold and sort (bucket sort, equal to a stable argsort of the phases)
189
- periodsGPU = cp.asarray(periods).astype(cp.float64)
229
+ inversePeriodsGPU = cp.asarray(1.0 / np.asarray(periods, dtype=np.float64))
190
230
  phasesGPU = cp.empty((nPeriods, tSize), dtype=cp.float64)
191
231
  countsGPU = cp.zeros((nPeriods, tSize), dtype=cp.int32)
192
232
  grid = ((tSize + 255) // 256, nPeriods)
193
233
  module.get_function("foldBuckets")(
194
- grid, (256,), (self.tGPU, periodsGPU, phasesGPU, countsGPU, np.int32(tSize)))
234
+ grid, (256,), (self.tGPU, inversePeriodsGPU, phasesGPU, countsGPU, np.int32(tSize)))
195
235
  cursorGPU = cp.empty((nPeriods, tSize), dtype=cp.int32)
196
236
  module.get_function("scanCounts")((nPeriods,), (SCAN_THREADS,), (countsGPU, cursorGPU, np.int32(tSize)))
197
237
  sortIndexGPU = cp.empty((nPeriods, tSize), dtype=cp.int32)
@@ -210,21 +250,34 @@ class GPUSearch:
210
250
  np.int32(tSize), np.int32(patchedSize)))
211
251
  del sortIndexGPU
212
252
 
213
- # Prefix sums of the residuals and the chi2 of the light curve without transit
214
- cumResidualGPU = cp.empty((nPeriods, patchedSize), dtype=cp.float64)
215
- baseGPU = cp.empty(nPeriods, dtype=cp.float64)
253
+ # Fixed-point prefix sums of the residuals
254
+ cumResidualGPU = cp.empty((nPeriods, patchedSize), dtype=cp.int64)
216
255
  module.get_function("scanResidual")(
217
256
  (nPeriods,), (SCAN_THREADS,),
218
- (residualGPU, weightedGPU, cumResidualGPU, baseGPU, np.int32(tSize), np.int32(patchedSize)))
257
+ (residualGPU, cumResidualGPU, self.fixedScale, np.int32(patchedSize)))
219
258
  del residualGPU
220
259
 
260
+ # One launch per run of durations sharing the same threads per window (the strides,
261
+ # and so the lanes, grow with the duration)
221
262
  bestGPU = cp.full(nPeriods, EMPTY_KEY, dtype=cp.uint64)
222
- module.get_function("searchChi2")(
223
- ((int(offsets[-1]) + 255) // 256, nPeriods), (256,),
224
- (bestGPU, cumResidualGPU, weightedGPU, baseGPU, self.signalGPU, self.overshootGPU,
225
- self.widthsGPU, cp.asarray(selected), cp.asarray(offsets.astype(np.int32)),
226
- cp.asarray(strides), periodMaskGPU, np.int32(len(selected)), np.int32(len(self.durations)),
227
- np.int32(tSize), np.int32(patchedSize), np.int32(self.maxWidth), self.transit_depth_min))
263
+ lanes = lanes_per_window(strides)
264
+ selectedGPU = cp.asarray(selected)
265
+ offsetsGPU = cp.asarray(offsets.astype(np.int32))
266
+ stridesGPU = cp.asarray(strides)
267
+ yBegin = 0
268
+ while yBegin < len(selected):
269
+ G = int(lanes[yBegin])
270
+ yEnd = yBegin + 1
271
+ while yEnd < len(selected) and lanes[yEnd] == G:
272
+ yEnd += 1
273
+ nWindows = int(offsets[yEnd] - offsets[yBegin])
274
+ module.get_function(f"searchChi2_G{G}")(
275
+ ((nWindows * G + 255) // 256, nPeriods), (256,),
276
+ (bestGPU, cumResidualGPU, self.fixedInvScale, weightedGPU, self.signalGPU, self.overshootGPU,
277
+ self.widthsGPU, selectedGPU, offsetsGPU, stridesGPU, periodMaskGPU,
278
+ np.int32(yBegin), np.int32(yEnd), np.int32(len(self.durations)),
279
+ np.int32(tSize), np.int32(patchedSize), np.int32(self.maxWidth), self.transit_depth_min))
280
+ yBegin = yEnd
228
281
  return bestGPU
229
282
 
230
283
  def chi2_batch(self, periods, size, refine):
@@ -244,7 +297,7 @@ class GPUSearch:
244
297
  return np.full(valid_range, self.constant_residual, dtype=np.float32)
245
298
 
246
299
  margin = self.T0_refine_margin if refine else self.T0_fit_margin
247
- chi2, _ = decode_keys(self.best_keys(periods, periodMaskGPU, margin)[:valid_range])
300
+ chi2, _ = decode_keys(self.best_keys(periods, periodMaskGPU, margin)[:valid_range], self.base)
248
301
  chi2 = cp.where(cp.isfinite(chi2), chi2, self.constant_residual)
249
302
  return chi2.astype(cp.float32).get()
250
303
 
@@ -269,7 +322,7 @@ class MultiGPUSearch:
269
322
  """Peak device memory of one period of a best_keys batch, in bytes.
270
323
 
271
324
  Live arrays peak in scanResidual at 20 P + 16 (P = patchedDatasSize): residual (4 P),
272
- weighted (8 P), cumResidual (8 P), base and periods. The memory pool places residual
325
+ weighted (8 P), cumResidual (8 P) and periods (bounded by 16 bytes). The memory pool places residual
273
326
  inside the freed 8 N phase buffer of the sort and cannot return that buffer to the
274
327
  driver, so the device footprint is 8 N + 16 P + 16 (N = tSize), plus one byte per
275
328
  duration for the period mask of searchChi2. Independent of T0_fit_margin.
@@ -434,7 +487,7 @@ def search_single_period(search, period, t, y, dy):
434
487
  durations = search.durations[durationsBool]
435
488
  single_lc_cache_overview = search.lc_cache_overview[durationsBool]
436
489
 
437
- chi2, location = decode_keys(search.best_keys(np.array([period]), periodMaskGPU, margin=0))
490
+ chi2, location = decode_keys(search.best_keys(np.array([period]), periodMaskGPU, margin=0), search.base)
438
491
  bestLocation = int(location[0]) if bool(cp.isfinite(chi2[0])) else 0
439
492
 
440
493
  durationIndex = np.floor(bestLocation / (tSize)).astype(int)
@@ -40,16 +40,18 @@ extern "C"{
40
40
 
41
41
  /**
42
42
  * Phase sort, stage 1: fold and count the points of each bucket floor(phase * tSize)
43
- * (about one point per bucket). phase = time / period - floor(time / period).
43
+ * (about one point per bucket). phase = time / period - floor(time / period), with the
44
+ * division done as a multiplication by the correctly rounded 1 / period (float64 division
45
+ * is a long instruction sequence, multiplication a single instruction).
44
46
  */
45
- __global__ void foldBuckets(const double* time, const double* periods, double* phase,
47
+ __global__ void foldBuckets(const double* time, const double* inversePeriods, double* phase,
46
48
  int* counts, int tSize) {
47
49
  int i = blockIdx.x * blockDim.x + threadIdx.x; // point index
48
50
  int z = blockIdx.y; // period index
49
51
  if (i >= tSize) {
50
52
  return;
51
53
  }
52
- double phaseRaw = time[i] / periods[z];
54
+ double phaseRaw = time[i] * inversePeriods[z];
53
55
  double p = phaseRaw - (int)(phaseRaw);
54
56
  long long o = (long long)z * tSize;
55
57
  phase[o + i] = p;
@@ -204,123 +206,164 @@ extern "C"{
204
206
  }
205
207
 
206
208
  /**
207
- * Inclusive float64 prefix sum of each row of the patched residuals (one block per row),
208
- * and base = sum of w r^2 over the first tSize (not patched) points of the row.
209
+ * Inclusive prefix sum of each row of the patched residuals (one block per row), in fixed
210
+ * point: every residual is rounded to a multiple of 1 / scale (scale = 2^E, chosen by
211
+ * GPUSearch so the row sums fit in 63 bits), then summed exactly in int64. Window sums are
212
+ * exact differences of two prefix sums, whatever the row length and the residual offset.
209
213
  */
210
- __global__ void scanResidual(const float* patchedResidual, const float2* patchedWeighted,
211
- double* cumResidual, double* base, int tSize, int patchedSize) {
214
+ __global__ void scanResidual(const float* patchedResidual, long long* cumResidual, float scale,
215
+ int patchedSize) {
212
216
  long long o = (long long)blockIdx.x * patchedSize;
213
- double carry = 0.0;
214
- double chi2 = 0.0;
217
+ long long carry = 0;
215
218
  for (int tile = 0; tile < patchedSize; tile += blockDim.x) {
216
219
  int q = tile + threadIdx.x;
217
- double r = q < patchedSize ? (double)patchedResidual[o + q] : 0.0;
218
- if (q < tSize) {
219
- chi2 += (double)patchedWeighted[o + q].x * r;
220
- }
221
- double total;
222
- double inclusive = blockInclusiveScan(r, &total);
220
+ long long r = q < patchedSize ? __float2ll_rn(patchedResidual[o + q] * scale) : 0;
221
+ long long total;
222
+ long long inclusive = blockInclusiveScan(r, &total);
223
223
  if (q < patchedSize) {
224
224
  cumResidual[o + q] = carry + inclusive;
225
225
  }
226
226
  carry += total;
227
227
  }
228
- double total;
229
- blockInclusiveScan(chi2, &total);
230
- if (threadIdx.x == 0) {
231
- base[blockIdx.x] = total;
232
- }
233
228
  }
234
229
 
235
- // Order-preserving map of a float onto an unsigned int: a < b <=> key(a) < key(b)
236
- __device__ __forceinline__ unsigned int orderedKey(float f) {
237
- unsigned int u = __float_as_uint(f);
238
- return (u & 0x80000000u) ? ~u : (u | 0x80000000u);
239
- }
230
+ } // extern "C"
240
231
 
241
- /**
242
- * Lowest chi2 of every period over all searched durations and start points, fused into one
243
- * pass (no per-start-point arrays). For a window of L points starting at `start` with
244
- * template depth profile s_i and amplitude k = mean_depth * overshoot / SIGNAL_DEPTH, the chi2
245
- * sum_{all points} w r^2 - sum_{window} w r^2 + sum_{window} w (r - k s)^2
246
- * is evaluated as base - 2 k A_R + k^2 A_2 with A_R = sum s_i (w r)_i, A_2 = sum s_i^2 w_i
247
- * (the algebraic expansion of TLS 2.0). The mean depth comes from a float64 prefix sum of r.
248
- *
249
- * Work items of a period are the start points of all searched durations, laid out by
250
- * `offsets`; start points of duration y are multiples of strides[y]. The searched durations
251
- * are the union over the batch; a period only tests those of its own row of periodMask
252
- * (physically plausible durations, see durationBool), so results do not depend on the batch.
253
- * best[z] receives min over work items of (orderedKey(chi2) << 32 | y * tSize + start), so
254
- * ties resolve to the first duration, then the first start point.
255
- */
256
- __global__ void searchChi2(unsigned long long* best,
257
- const double* cumResidual, // (periods, patchedSize), inclusive
258
- const float2* patchedWeighted, // (periods, patchedSize)
259
- const double* base, // (periods)
260
- const float* signal, // (durations, maxWidth)
261
- const float* overshoot, // (durations)
262
- const int* widths, // (durations)
263
- const int* selected, // (nSelected) searched durations
264
- const int* offsets, // (nSelected + 1)
265
- const int* strides, // (nSelected)
266
- const bool* periodMask, // (periods, nDurations)
267
- int nSelected, int nDurations, int tSize, int patchedSize,
268
- int maxWidth, float transitDepthMin) {
269
- int z = blockIdx.y;
270
- int g = blockIdx.x * blockDim.x + threadIdx.x;
271
- unsigned long long key = 0xffffffffffffffffull;
232
+ // Order-preserving map of a float onto an unsigned int: a < b <=> key(a) < key(b)
233
+ __device__ __forceinline__ unsigned int orderedKey(float f) {
234
+ unsigned int u = __float_as_uint(f);
235
+ return (u & 0x80000000u) ? ~u : (u | 0x80000000u);
236
+ }
272
237
 
273
- if (g < offsets[nSelected]) {
274
- int y = 0;
275
- while (offsets[y + 1] <= g) {
276
- y++;
277
- }
278
- int start = (g - offsets[y]) * strides[y];
279
- int d = selected[y];
280
- int L = widths[d];
281
- const double* C = cumResidual + (long long)z * patchedSize;
282
- double windowSum = C[start + L - 1] - (start > 0 ? C[start - 1] : 0.0);
283
- float meanDepth = (float)(windowSum / L);
238
+ /**
239
+ * Lowest chi2 of every period over the searched durations yBegin <= y < yEnd and their start
240
+ * points, fused into one pass (no per-start-point arrays). For a window of L points starting at
241
+ * `start` with template depth profile s_i and amplitude k = mean_depth * overshoot / SIGNAL_DEPTH,
242
+ * the chi2
243
+ * sum_{all points} w r^2 - sum_{window} w r^2 + sum_{window} w (r - k s)^2
244
+ * is evaluated as base + delta, delta = k^2 A_2 - 2 k A_R with A_R = sum s_i (w r)_i,
245
+ * A_2 = sum s_i^2 w_i (the algebraic expansion of TLS 2.0). base = sum_{all points} w r^2 is
246
+ * the same for every window and period, so the windows are ranked by delta alone, in float32
247
+ * (decode_keys adds base). The mean depth is the exact fixed-point window sum of r (see
248
+ * scanResidual), converted and divided by L with float32 rounding: no float64 per window.
249
+ *
250
+ * Work items of a period are the start points of all searched durations, laid out by
251
+ * `offsets`; start points of duration y are multiples of strides[y]. The searched durations
252
+ * are the union over the batch; a period only tests those of its own row of periodMask
253
+ * (physically plausible durations, see durationBool), so results do not depend on the batch.
254
+ * best[z] receives min over work items of (orderedKey(delta) << 32 | y * tSize + start), so
255
+ * ties resolve to the first duration, then the first start point.
256
+ *
257
+ * G consecutive threads share one window (G divides 32): they read G consecutive points per
258
+ * step and sum A_R, A_2 with warp shuffles. With one thread per window, neighbouring threads
259
+ * read points strides[y] apart, which wastes memory transactions and evicts the overlap of
260
+ * neighbouring windows from L1 once the stride is large; G is chosen per duration from the
261
+ * stride (see core.lanes_per_window and bench/window_lanes on branch perf/window-lanes).
262
+ */
263
+ template <int G>
264
+ __device__ __forceinline__ void searchChi2Lanes(
265
+ unsigned long long* best,
266
+ const long long* cumResidual, // (periods, patchedSize), inclusive, fixed point
267
+ float invScale, // 1 / scale of cumResidual (a power of 2)
268
+ const float2* patchedWeighted, // (periods, patchedSize)
269
+ const float* signal, // (durations, maxWidth)
270
+ const float* overshoot, // (durations)
271
+ const int* widths, // (durations)
272
+ const int* selected, // (nSelected) searched durations
273
+ const int* offsets, // (nSelected + 1)
274
+ const int* strides, // (nSelected)
275
+ const bool* periodMask, // (periods, nDurations)
276
+ int yBegin, int yEnd, int nDurations, int tSize, int patchedSize,
277
+ int maxWidth, float transitDepthMin) {
278
+ int z = blockIdx.y;
279
+ int sub = threadIdx.x % G; // lane within the window's group
280
+ int g = offsets[yBegin] + (blockIdx.x * blockDim.x + threadIdx.x) / G;
281
+ unsigned long long key = 0xffffffffffffffffull;
282
+ float ar = 0.0f;
283
+ float a2 = 0.0f;
284
+ float meanDepth = 0.0f;
285
+ bool active = false;
286
+ int y = yBegin;
287
+ int start = 0;
288
+ int d = 0;
284
289
 
285
- if (periodMask[(long long)z * nDurations + d] && meanDepth > transitDepthMin) {
286
- float k = meanDepth * overshoot[d] * 2.0f; // 2 = 1 / SIGNAL_DEPTH
287
- const float2* x = patchedWeighted + (long long)z * patchedSize + start;
288
- const float* s = signal + (long long)d * maxWidth;
289
- float ar = 0.0f;
290
- float a2 = 0.0f;
291
- for (int i = 0; i < L; i++) {
292
- float si = s[i];
293
- float2 v = x[i];
294
- ar = fmaf(si, v.x, ar);
295
- a2 = fmaf(si * si, v.y, a2);
296
- }
297
- float chi2 = (float)(base[z] + (double)(k * (k * a2 - 2.0f * ar)));
298
- key = ((unsigned long long)orderedKey(chi2) << 32) | (unsigned int)(y * tSize + start);
290
+ if (g < offsets[yEnd]) {
291
+ while (offsets[y + 1] <= g) {
292
+ y++;
293
+ }
294
+ start = (g - offsets[y]) * strides[y];
295
+ d = selected[y];
296
+ int L = widths[d];
297
+ if (periodMask[(long long)z * nDurations + d]) {
298
+ const long long* C = cumResidual + (long long)z * patchedSize;
299
+ long long windowSum = C[start + L - 1] - (start > 0 ? C[start - 1] : 0);
300
+ meanDepth = __fdiv_rn(__ll2float_rn(windowSum) * invScale, (float)L);
301
+ active = meanDepth > transitDepthMin; // the same for all G lanes of the window
302
+ }
303
+ if (active) {
304
+ const float2* x = patchedWeighted + (long long)z * patchedSize + start;
305
+ const float* s = signal + (long long)d * maxWidth;
306
+ for (int i = sub; i < L; i += G) {
307
+ float si = s[i];
308
+ float2 v = x[i];
309
+ ar = fmaf(si, v.x, ar);
310
+ a2 = fmaf(si * si, v.y, a2);
299
311
  }
300
312
  }
313
+ }
314
+
315
+ // Sum over the G lanes of each window (every lane takes part in the shuffles)
316
+ #pragma unroll
317
+ for (int o = G / 2; o > 0; o >>= 1) {
318
+ ar += __shfl_xor_sync(0xffffffff, ar, o);
319
+ a2 += __shfl_xor_sync(0xffffffff, a2, o);
320
+ }
321
+ if (active && sub == 0) {
322
+ float k = meanDepth * overshoot[d] * 2.0f; // 2 = 1 / SIGNAL_DEPTH
323
+ float delta = k * (k * a2 - 2.0f * ar);
324
+ key = ((unsigned long long)orderedKey(delta) << 32) | (unsigned int)(y * tSize + start);
325
+ }
301
326
 
302
- // Block-wide minimum, then one atomic per block
327
+ // Block-wide minimum, then one atomic per block
328
+ for (int o = 16; o > 0; o >>= 1) {
329
+ unsigned long long other = __shfl_down_sync(0xffffffff, key, o);
330
+ key = other < key ? other : key;
331
+ }
332
+ __shared__ unsigned long long warpMin[32];
333
+ int lane = threadIdx.x & 31;
334
+ int warp = threadIdx.x >> 5;
335
+ if (lane == 0) {
336
+ warpMin[warp] = key;
337
+ }
338
+ __syncthreads();
339
+ if (warp == 0) {
340
+ int nWarps = (blockDim.x + 31) >> 5;
341
+ key = lane < nWarps ? warpMin[lane] : 0xffffffffffffffffull;
303
342
  for (int o = 16; o > 0; o >>= 1) {
304
343
  unsigned long long other = __shfl_down_sync(0xffffffff, key, o);
305
344
  key = other < key ? other : key;
306
345
  }
307
- __shared__ unsigned long long warpMin[32];
308
- int lane = threadIdx.x & 31;
309
- int warp = threadIdx.x >> 5;
310
- if (lane == 0) {
311
- warpMin[warp] = key;
312
- }
313
- __syncthreads();
314
- if (warp == 0) {
315
- int nWarps = (blockDim.x + 31) >> 5;
316
- key = lane < nWarps ? warpMin[lane] : 0xffffffffffffffffull;
317
- for (int o = 16; o > 0; o >>= 1) {
318
- unsigned long long other = __shfl_down_sync(0xffffffff, key, o);
319
- key = other < key ? other : key;
320
- }
321
- if (lane == 0 && key != 0xffffffffffffffffull) {
322
- atomicMin(best + z, key);
323
- }
346
+ if (lane == 0 && key != 0xffffffffffffffffull) {
347
+ atomicMin(best + z, key);
324
348
  }
325
349
  }
326
350
  }
351
+
352
+ // searchChi2_G1 ... searchChi2_G32: G threads per window
353
+ #define SEARCH_CHI2(G) \
354
+ extern "C" __global__ void searchChi2_G##G( \
355
+ unsigned long long* best, const long long* cumResidual, float invScale, \
356
+ const float2* patchedWeighted, const float* signal, const float* overshoot, const int* widths, \
357
+ const int* selected, const int* offsets, const int* strides, const bool* periodMask, \
358
+ int yBegin, int yEnd, int nDurations, int tSize, int patchedSize, int maxWidth, \
359
+ float transitDepthMin) { \
360
+ searchChi2Lanes<G>(best, cumResidual, invScale, patchedWeighted, signal, overshoot, widths, \
361
+ selected, offsets, strides, periodMask, yBegin, yEnd, nDurations, \
362
+ tSize, patchedSize, maxWidth, transitDepthMin); \
363
+ }
364
+ SEARCH_CHI2(1)
365
+ SEARCH_CHI2(2)
366
+ SEARCH_CHI2(4)
367
+ SEARCH_CHI2(8)
368
+ SEARCH_CHI2(16)
369
+ SEARCH_CHI2(32)
@@ -1,2 +1,2 @@
1
- __version__ = "2.0.1"
1
+ __version__ = "2.1.0"
2
2
  __date__ = "Nov-2026"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: gputls
3
- Version: 2.0.1
3
+ Version: 2.1.0
4
4
  Summary: GPU-accelerated Transit Least Squares (TLS) for periodic transit detection
5
5
  Author-email: Quanquan Hu <huqq1917@outlook.com>
6
6
  Maintainer-email: Quanquan Hu <huqq1917@outlook.com>
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes