Manuscript Offprint
arXiv:2611.01078CuPH: Parallel Cubical Persistent Homology via Level-Synchronous Component Tracking
Abstract
Persistent homology (PH) is a mathematically principled multi-scale topological descriptor of shape and connectivity in data. It is widely applied in image classification, segmentation, and shape analysis across medical and aerial imaging, providing structural information that pixel-wise deep learning may overlook. Standard cubical PH decomposes an image into cubical cells (vertices, edges, and squares) and reduces them sequentially in filtration order. This sequential reduction has parallel depth for an -pixel image, limiting within-image GPU parallelism and constraining its use in topology-aware deep learning. We introduce CuPH, a GPU-based parallel algorithm for computing cubical PH on 2D images that operates directly on pixels rather than cubical cells. CuPH buckets pixels by filtration values, activates them with a level-synchronous sweep, and tracks connected components with a lock-free union-find method. We prove that CuPH produces persistence diagrams identical to standard cubical PH on integer inputs, with a stability bound for floating-point inputs. CuPH reduces parallel depth from to for an image with intensity levels. We implement the level sweep as a single CUDA kernel, eliminating cross-level kernel-launch overhead. Empirically, CuPH is 18.6–99.6× faster than the existing GPU baseline (CMP). As a drop-in PH backend, CuPH accelerates topology-aware classification (4.2–16.7×) and segmentation (8.3–44×) while preserving accuracy. It also enables computing full-image PH losses on high-resolution images, improving segmentation Dice by 2.2–4.6 points over patch-local PH baselines and accelerating training by 25–31×.
1 Introduction
In image segmentation and classification, preserving topological structures (e.g., connected components and loops) is often as important as pixel-wise features. For example, a vessel-segmentation prediction may well overlap with ground-truth pixels but break a single capillary into multiple segments [30]; a road-extraction model may correctly label the road pixels but sever a highway at an intersection [27]; an organ-segmentation prediction may achieve high pixel agreement but introduce a phantom hole in the organ wall [5]. Such errors violate the topology of the target, which standard objectives such as cross-entropy and Dice [25] do not explicitly constrain. Persistent homology (PH) [10, 34], a tool from computational topology, fills this gap by providing a principled measure of these structural properties. PH has motivated a growing body of topology-aware learning methods that use persistence-based features or losses to penalize broken vessels, fragmented road networks, leaky membranes, and spurious components [14, 32, 22, 28, 16].
Despite the theoretical advantages, applying PH in deep learning (DL) remains computationally expensive. Standard cubical PH operates at the cell level (Figure 1a): it constructs all cubical cells (vertices, edges, and squares) of an -pixel image, imposes a filtration order, and reduces them
Preprint.
(a) Pipeline comparison.

(b) Throughput comparison.
Figure 1: (a) Existing cubical PH methods construct ~4n cubical cells (vertices, edges, and squares) and reduce them sequentially via union-find or matrix reduction. CuPH operates directly on pixels in parallel. (b) CuPH achieves 18.6–99.6× speedup over the GPU baseline (CMP) across batch sizes on the ISIC 2018 dataset [6]; CPU methods plateau below 500 img/s.
sequentially via union-find or matrix reduction methods [23, 15]. This serial reduction has parallel depth, which limits within-image parallelism on GPU. Consequently, even on -size images, the fastest CPU algorithm, Cripser [15], reaches only 458 images/s, and the GPU baseline CMP [16] requires batch to match Cripser, reaching 56 images/s at batch 64 and 1,441 images/s only at batch 4,096 (Figure 1b). Thus, researchers rely on three workarounds. Offline pre-computation extracts PH features first and freezes them as model input [28]; this avoids training-time computation but cannot adapt to a learned representation. Patch-local PH restricts topological signals to small patches [14, 32] (typically sizes or ) in images that are often or larger. This fits within the backend's per-image cost limits but cannot represent a global road network, membrane sheet, or organ boundary whose topological support extends beyond a single patch. Component-graph topology replaces PH by a graph-theoretic proxy [22], gaining speed but losing PH's theoretical guarantee that zero loss implies matching Betti numbers [14]. A fast exact PH backend will change not only the runtime, but also the class of topology-aware objectives that DL models can use.
To address this computational bottleneck, we propose CuPH, a GPU algorithm for cubical PH. Our observation is that the cost of standard cubical PH is not inherent: it stems from cell-level formulations that do not exploit the bounded level structure of image filtrations. Specifically, for an image, the filtration parameter value is bounded and discrete, with intensity levels for an 8-bit image and in general. CuPH avoids constructing the full cubical complex (Figure 1a). It comprises two stages supported by a component-tracking primitive: Level Bucketing groups pixels by intensity; Level Sweeping processes levels sequentially, activating pixels at each level in parallel; Component Tracking maintains connected components and emits persistence pairs under the Elder Rule [10]. CuPH thus reduces the parallel depth from to , and achieves 18.6–99.6× speedup over the GPU baseline (CMP) across batch sizes (Figure 1b).
Our contributions are as follows. (i) Algorithm: A new level-synchronous GPU cubical PH algorithm for 2D images; CuPH operates directly on pixels, avoids explicit construction of the full cubical complex, and is implemented as a batched CUDA algorithm that can serve as a drop-in backend for existing topology-aware DL pipelines. (ii) Theory: We prove that CuPH produces persistence diagrams (PDs) identical to standard cubical PH on integer inputs, with a stability bound for floating-point inputs. The algorithm has total work and parallel depth for an -pixel image with intensity levels. (iii) Empirical results: We evaluate CuPH as a standalone PH algorithm and as a drop-in backend for topology-aware classification, segmentation, and PH-based losses. CuPH is 18.6–99.6× faster than the existing GPU baseline (CMP) across batch sizes. As a drop-in backend, it accelerates topology-aware classification by 4.2–16.7× and segmentation by 8.3–44× while preserving accuracy. It also enables computing full-image PH losses on high-resolution images, improving segmentation Dice by 2.2–4.6 points over patch-local PH baselines (whose losses are computed only on local patches) and accelerating training by 25–31×.

Figure 2: Illustrating the CuPH pipeline on a 4 × 4 image with intensity levels. (a) Pixels are partitioned into buckets by intensity value. (b) Levels are processed in order: at level 0, components and are born; at level 1, is born, and one pixel joins ; at level 2, merges into , emitting a non-diagonal pair ; at level 3, merges into , emitting . (c) The resulting persistence diagram, with giving an essential pair .
denote an image on the pixel grid of size , with pixels, and intensity levels (e.g., for an 8-bit image). For a pixel , denotes its intensity value, which serves as the filtration value at . The cubical complex on consists of vertices, edges, and squares induced by pixel adjacency (4- or 8-connectivity). Each cell takes the filtration value (its largest constituent pixel intensity). At threshold , all cells with form the sublevel complex , equivalently the cells whose constituent pixels all satisfy . As increases from 0 to , these complexes form a nested filtration .
A connected component is born at a threshold value where it first appears, and dies when an edge merges it with another component. The Elder Rule [8] resolves merges: the component with a lower birth value survives. In this work, ties are broken by lexicographic order on (birth, pixel_index). Each death of a component yields a persistence pair (with birth and death ). Pairs with lie on the diagram diagonal, called diagonal pairs. Components that never die give essential pairs . All these pairs form the persistence diagram PD(X). We follow the standard convention that PDs identify diagonal pairs with the diagonal [8]; under this convention, diagonal pairs do not affect any diagram comparison, and thus we ignore them. PDs are often compared using the bottleneck distance [7] or -Wasserstein distance [31], both used for optimal matchings between diagrams; these distances underpin the stability guarantees (discussed in Section 3.2).
2.1 The Standard Cubical PH Algorithm
The standard cubical PH algorithm [15, 23] follows a three-step pipeline (Figure 1a, top): construct the full cubical complex with cells in time, sort the cells by filtration value in time, and reduce them sequentially by edge-based union-find for and matrix reduction for higher dimensions. For , union-find under the Elder Rule runs in amortized time [33]. For , the standard approach is boundary-matrix reduction [8], with worst-case complexity. For 2D images, this cubic cost can be avoided: Alexander duality [9, 3] recasts as a separate problem on a padded dual image, allowing union-find to handle both dimensions. CuPH adopts this duality-based reduction approach (Section 3).
The sequential nature of the edge-based union-find leads to an parallel depth, limiting GPU acceleration. The best-known GPU approach CMP [16] batches across images but cannot parallelize within a single image. This bottleneck has constrained fast computation of PH-based features and differentiable topology losses in DL methods [14, 32, 28]. In particular, persistence-based segmentation losses commonly compute the topological term on small random patches for predictions rather than on the full image [14, 32], capturing only local rather than global topological patterns.
3 Method
CuPH replaces the standard filtration sorting with level bucketing, followed by a level-synchronous parallel sweep that processes each level's pixels concurrently. We present the algorithm in Section 3.1, the theoretical analysis in Section 3.2, and the GPU implementation in Section 3.3.
3.1 The CuPH Pipeline
CuPH consists of two stages, Level Bucketing and Level Sweeping, supported by a Component Tracking primitive invoked during the sweeping (Figure 2). Level Bucketing groups pixels by filtration value. Level Sweeping iterates over the levels in increasing order, activating each level's pixels in parallel and merging neighboring components. Component Tracking maintains a lock-free union-find forest, applying the Elder Rule [10] and emitting persistence pairs when components die. Algorithm 1 summarizes the procedure.
Level Bucketing. CuPH partitions the pixels of image into buckets by filtration value (pixel intensity), where contains all pixels with (see Figure 2(a)). This step uses the standard GPU counting-sort primitive, which combines parallel histogram, prefix sum [13], and scatter [24], running in work and depth.
Level Sweeping. Level Sweeping consists of an outer loop across levels (sequential) and an inner loop within each level (parallel). The outer loop runs from level to in order, because the Elder Rule at level depends on which components are active and on their birth values, both determined by earlier levels. Although the outer loop is not parallel, it shortens the sequential dependency chain from cells in the standard algorithm to levels. The inner loop is fully parallel: all pixels activated at level share the same intensity value, and processing them in any order yields the same persistence diagram (Theorem 1).
At each level , the inner loop has two phases separated by a barrier. The Activate phase writes label and birth value for every pixel in parallel. The Connect phase then processes, in parallel, every neighboring pair with and in the 4-connected neighborhood of that is already active (either from an earlier level or just activated at level ), invoking MERGE (the details in Component Tracking). The barrier between the two phases ensures that pixels activated at level can all participate in within-level merges. Figure 2(b) illustrates this at level : components and were born at level 0, and three pixels in are activated (each as a singleton component with birth value 1). Connect then merges them with their active neighbors: one pixel is absorbed into via an earlier-level neighbor; the other two merge with each other to form . In each merge at level , the component being absorbed is born at level 1, giving a persistence pair that is diagonal and should be omitted. No pair is emitted at level 1.
Component Tracking. CuPH maintains the active connected-component partition with a union-find forest. Each active pixel stores a parent pointer , and each root (a pixel with ) stores its birth value for the component it represents. The forest is updated via a MERGE function invoked by Connect; concurrent updates use lock-free atomic compare-and-swap (CAS).
MERGE follows the standard lock-free union-find process, with the Elder Rule providing the linking criterion and successful merges emitting persistence pairs. Specifically, MERGE first runs FIND on and to locate their current roots. With the two roots found by FIND, MERGE applies the Elder Rule using the lexicographic key : the root with the smaller key becomes the survivor root, and the other becomes the dying root. The merge then links the dying root to the survivor root via an atomic CAS operation. If the CAS succeeds, the dying root is no longer a root and the merge is completed. If it fails, then another thread has linked this root in the meantime. The failed thread then reruns FIND on and . Since the roots may have changed, the thread retries the merge, or returns if both and are found to already be in the same component.
A successful CAS triggers pair emission unless the merge would produce a diagonal pair (i.e., ). If the dying root was born before the current level (i.e., ), CuPH emits a persistence pair ; if , the pair is diagonal and is omitted. Figure 2(b) illustrates a non-diagonal pair emission at level , where level-2 activations cause and (both born at level 0) to merge. The Elder Rule's tie-breaker (root indices) selects as the survivor root; a successful CAS links to , dies, and CuPH emits the persistence pair .
3.2 Theoretical Analysis
We establish three guarantees for CuPH on an -pixel, -level image : equivalence with the standard cubical PH (Theorem 1), total work and parallel depth (Theorems 2 and 3), and stability bounds (Corollaries 4 and 5). Let denote CuPH's output diagram
Algorithm 1 CuPH.
Require: Image with pixels, 4-connected neighborhood
Ensure: Persistence diagram PD(X)
1: PD
2: Partition into bucket by filtration value Level Bucketing 3: parallel for : label : inactive 4: for to do Level Sweeping 5: parallel for : label, birth Activate 6: barrier 7: parallel for with label: MERGE Connect 8: barrier 9: append to PD essential pairs 10: return PD
11: function MERGE
12: repeat 13: ; locate current roots 14: if then 15: already in the same component 16: ; let (survivor root), (dying root) be the roots with smaller and larger , respectively 17: old link to 18: if old = u then CAS succeeded 19: if birth then 20: emit a non-diagonal pair 21: return 22:
and denote the standard cubical diagram, for . All bounds are analyzed for one image. For a batch of images, the work scales by and the parallel depth is unchanged.
Equivalence. Both the standard cubical PH algorithm and CuPH process the same neighboring pixel pairs at level : the standard algorithm via an explicit edge, while CuPH via Connect with both endpoints and being active. The two therefore feed the same merges to union-find at each level but differ in their merge order (sequential vs. parallel). Theorem 1 shows that this order difference does not affect the output.
Theorem 1 (Equivalence). For an image ,
Proof Sketch. We prove the equivalence by induction on the filtration level , with three key properties at each level: identical inputs (both algorithms feed the same set of merges to union-find), order-invariance (all sequential merge orders produce the same persistence diagram), and linearization (CuPH's concurrent process is equivalent to some valid sequential merge order). See Appendix A for the full proof.
Theorem 2 (Work complexity). Assume that the atomic CAS operation in each MERGE conducts amortized retries. CuPH performs total work on image .
Proof Sketch. In CuPH, Level Bucketing performs work via histogram, prefix sum, and scatter. Level Sweeping processes neighboring pairs (each pixel has neighbors); each pair invokes MERGE, which under the assumption performs amortized retries, each with amortized cost from FIND [33]. Thus, the total work on is . The full proof is in Appendix B.
Theorem 3 (Parallel depth). Consider an ideal shared-memory model with atomic compare-and-swap (CAS). Assume that , the number of processors satisfies , where is the neighborhood size (e.g., for 4-connectivity), the CAS operation in each MERGE conducts amortized retries, and any FIND path in the union-find forest is of a length under the maintained union-find forest invariant. Then CuPH has a parallel depth of .
Proof Sketch. With , Level Bucketing has parallel depth via the standard work-efficient parallel counting-sort primitive. Level Sweeping performs sequential iterations (the Elder
Rule at level depends on the earlier levels); within each iteration, the Activate phase has depth, and the Connect phase has depth from FIND via path halving, with amortized retries conducted by CAS adding only a constant factor overhead. In total, parallel depth. The full proof is in Appendix B.
Stability. CuPH's output diagrams inherit standard cubical PH stability via Theorem 1.
Corollary 4 (Stability). For any two discrete-valued images on a pixel grid , with , bottleneck distance , and Wasserstein distance ,
By Theorem 1, the bounds follow from the bottleneck [7] and Wasserstein [31, Theorem 5.1] stability.
Quantization Stability. In practice, image inputs often contain continuous-values. The next corollary bounds the deviation of CuPH's diagram from the PD of the original continuous-valued image.
Corollary 5 (Quantization stability). Let the value range of a function be (i.e., ), be the uniform -level quantization of with step size (hence, ), and denote its bin-midpoint dequantization, so that . Let denote CuPH's output diagram with each value rescaled to . Then for ,
By Theorem 1, . The bottleneck bound follows from and the bottleneck stability [7]. The Wasserstein bound follows from Skraba and Turner [31, Theorem 5.1] with . Table 8 in the Appendix reports that empirically, is approximately tighter than this worst-case Wasserstein bound.
3.3 GPU Implementation
CuPH's level-synchronous structure poses two GPU implementation challenges. (a) Inter-level synchronization: level cannot start until all Activate and Connect operations at level finish, and per-level kernel launch would incur overhead proportional to . (b) Intra-level concurrency: within each level, multiple MERGE calls may simultaneously update the union-find forest, requiring atomic operations to prevent lost updates. We address these with two design choices: a single-kernel level sweep and a lock-free union-find. We describe batched execution and the pipeline below.
Single-kernel Level Sweep. To address inter-level synchronization, CuPH runs the entire level sweep within one kernel, with each image assigned to a single CUDA block. The block iterates over the levels in ascending order; at each level, threads cooperatively execute the Activate phase (writing labels and birth values for pixels in the level's bucket), hit a __syncthreads() barrier, and then execute the Connect phase (visiting active neighbors and calling MERGE). A second __syncthreads() at the end of each level ensures that all level- merges complete before level- activations start. Because the entire sweep runs in a single block, this level-synchronous iteration uses inexpensive block-local barriers in place of repeated kernel launches. Buckets larger than the block's thread count are processed via the standard CUDA strided-loop pattern.
Lock-free Union-Find. To address intra-level concurrency, CuPH implements the union-find forest lock-free. Per-pixel labels and birth values reside in global memory. FIND uses path halving for efficiency [33]. MERGE links the dying root to the survivor root via atomicCAS on the dying root's label. Emitted persistence pairs are recorded via atomicAdd on the per-image pair counter. Forest validity follows from a strict-decrease invariant established in the proof of Theorem 1: each successful CAS attaches a dying root to a parent with a strictly smaller lexicographic key ; thus strictly decreases along every parent pointer regardless of CAS interleaving, precluding cycles.
Batch Parallelism and Variants. A pre-allocated memory pool gives each image its own private workspace. Independent images therefore run in independent CUDA blocks without contention,
Table 1: Throughput comparison on ISIC 2018. (a) Throughput (img/s) at varying resolutions (batch size = 64). (b) Throughput, memory (MB), and speedup at varying batch sizes (resolution = 224²).
| (a) Resolution scaling | |||||
|---|---|---|---|---|---|
| Method | 64² | 128² | 224² | 512² | 1024² |
| GUDHI | 1,232 | 269.8 | 97.5 | 9.4 | 1.8 |
| Cripser | 5,258 | 1,495 | 458.5 | 38.7 | 9.1 |
| CMP | 1,349 | 268.4 | 56.2 | 7.7 | 1.3 |
| CuPH | 11,319 | 8,453 | 5,232 | 805.2 | 208.4 |
| CuPH/CMP | 8.4× | 31.5× | 93.1× | 104.6× | 160.3× |
| (b) Batch scaling | |||||
|---|---|---|---|---|---|
| Batch size | CuPH | CMP | Speedup | ||
| img/s | MB | img/s | MB | ||
| 16 | 1,452 | 170 | 21.8 | 298 | 66.6× |
| 32 | 2,792 | 190 | 31.6 | 496 | 88.4× |
| 64 | 5,232 | 272 | 56.2 | 994 | 93.1× |
| 128 | 9,729 | 428 | 97.7 | 1,408 | 99.6× |
| 256 | 15,443 | 748 | 162.3 | 2,716 | 95.2× |
| 1024 | 22,963 | 2,898 | 513.1 | 10,398 | 44.8× |
| 4096 | 26,794 | 11,292 | 1,441 | 41,264 | 18.6× |
enabling batched processing across the GPU. The pipeline reuses the same kernel after constructing the padded Alexander-dual image [3]; superlevel filtrations are obtained by reversing intensity levels and remapping the resulting birth–death pairs. Full kernel pseudocode, memory layout, and additional implementation details are in Appendix C.
4 Experiments
We evaluate CuPH in two distinct roles. First, as a standalone GPU PH method, we benchmark its throughput and scalability against GUDHI, Cripser, and CMP across image resolutions and batch sizes (Table 1). Second, as a drop-in backend for topology-aware learning, we put CuPH into classification pipelines (Table 2) and into two segmentation settings: topology-aware architectures (Table 3), and topology-aware losses (Table 4).
Experimental Setup. Datasets. For classification, we use CBIS-DDSM [19], Prostate Cancer (Prostate) [18], ISIC 2018 Task 3 (T3) [6], and APTOS 2019 [1], following PHG-Net [28] and CMP [16]. For segmentation under the topology-aware architecture setting, we use ISIC 2018 Task 1 (T1) [6], CREMI [11] (resized to 512²), and Synapse [17] (2D axial slices). For topology-aware loss experiments, we follow Topograph [22] on Massachusetts Roads (Roads) [26], Platelet [12], and CREMI (native 1250²). Dataset details are summarized in Table 5 (Appendix D.1).
PH Baselines. We compare four cubical PH methods: GUDHI [23] and Cripser [15] (both CPU), CMP [16] (the only published GPU cubical PH), and CuPH. CuPH discretizes float-valued images into levels, which matches the practical precision of float segmentation probability maps and yields empirical well below the bound of Theorem 5 (Appendix E). To obtain , Cripser, CMP, and CuPH use cubical Alexander duality [3], and GUDHI applies matrix reduction.
Methods. Classification (SwinV2-B backbone [20]): backbone alone (no PH); PHG-Net [28] (original offline-precomputed version and online CuPH variants); TopoSwin-SP/MP [16] (single- and multi-parameter persistence, with CMP and CuPH backends). Segmentation uses a SwinV2-B encoder with a U-Net style decoder [29]; TopoSwin-SP/MP apply persistence as decoder-skip losses, following [16]. Topology-aware losses: HuTopo [14] and BettiMatching [32] (PH-based, with CuPH backend); Topograph [22] (non-PH component-graph reference).
Training. All methods trained with AdamW [21] (, weight decay 0.01) in fp32 with cosine schedule, using the original papers' hyperparameters when available. CuPH-backed variants inherit settings from their CMP-backed counterparts. GPU experiments use a single NVIDIA H100; CPU on AMD EPYC 7543. Full hyperparameters in Appendix D. Code will be released upon acceptance.
Metrics. Accuracy and Dice are mean over 5 seeds; throughput (img/s) is mean over 5 runs. Classification reports top-1 accuracy; segmentation reports Dice and mIoU (ISIC, CREMI) or Dice and HD95 mm (Synapse); topology-aware losses additionally report clDice [30].
Standalone PH Benchmarking. Resolution Scaling (Table 1a). On ISIC with batch 64, CuPH achieves 5,232 img/s at resolution 224², a 93.1× speedup over CMP and 11.4× over Cripser. It sustains the highest throughput across all resolutions tested, from 11,319 img/s at 64² down to 208.4 img/s at 1024². Throughput declines with increasing image size since per-image work scales with
Table 2: Classification accuracy (Acc, %) and training throughput (img/s) at batch size 32.
| Method | ISIC 2018 | CBIS-DDSM | Prostate | APTOS | ||||
|---|---|---|---|---|---|---|---|---|
| Acc | img/s | Acc | img/s | Acc | img/s | Acc | img/s | |
| SwinV2-B | 88.1±1.9 | 206.7 | 69.4±0.3 | 206.1 | 96.0±0.2 | 208.5 | 82.4±1.7 | 55.2 |
| PHG-Net | 88.7±0.9 | 204.0 | 71.8±0.6 | 202.9 | 96.9±0.6 | 202.7 | 84.1±1.7 | 54.9 |
| PHG-Net (CUPH) | 89.5±0.9 | 183.9 | 71.9±1.1 | 183.4 | 96.6±0.3 | 183.7 | 85.0±1.2 | 49.5 |
| TopoSwin-SP | 88.2±0.5 | 16.4 | 73.8±0.2 | 16.8 | 96.6±0.4 | 17.9 | 86.1±1.5 | 2.9 |
| TopoSwin-SP (CUPH) | 89.3±0.4 | 116.9 | 74.1±0.3 | 111.1 | 96.4±0.5 | 118.5 | 86.3±1.4 | 28.8 |
| TopoSwin-MP | 89.8±1.0 | 12.1 | 74.3±0.1 | 12.4 | 96.9±0.2 | 11.9 | 83.9±1.4 | 0.6 |
| TopoSwin-MP (CUPH) | 90.3±0.6 | 52.6 | 74.5±0.2 | 52.6 | 97.0±0.3 | 53.3 | 84.1±1.1 | 10.0 |
while CUPH's per-image thread block keeps the within-image parallelism constant. In contrast, CMP launches one thread per image, and thus its per-image work is fully sequential and its throughput stays near GUDHI's despite running on GPU. Hence, as image size grows, CMP's throughput declines steeply while CUPH's within-image parallelism keeps the decline slow. The speedup ratio of CUPH over CMP grows accordingly, reaching 160.3× at 1024².
Batch Scaling (Table 1b). At image size 224² on ISIC 2018, CuPH scales from 1,452 img/s at batch size 16 to 26,794 img/s at batch size 4,096, leading at every batch size. The CuPH-over-CMP speedup peaks at 99.6× at batch size 128 and narrows at both extremes: at small batch sizes, the GPU is under-utilized for both methods, while at large batch sizes, CMP saturates its only source of parallelism (cross-images) and begins to close the gap. Even so, CMP's reliance on cross-image parallelism alone shows that batch size cannot compensate for limited within-image parallelism. CuPH's memory advantage shows a similar small-batch effect: CuPH uses 3.3–3.7× less GPU memory than CMP at batch size ≥ 64, narrowing to 1.8–2.6× at batch sizes 16 and 32 where CuPH's level-bucketing buffers contribute a larger fixed share of its memory footprint.
Ablation. Removing Level Bucketing slows CuPH by 4.6×, restricting Level Sweeping to a single thread by 21.0×, and removing both jointly by 425.4×. This joint slowdown exceeds the product of the two individual slowdowns (4.6 × 21.0 ≈ 97×) since single-threaded scanning over an unsorted filtration incurs additional sequential overhead. Replacing lock-free Component Tracking by a global lock slows down the kernel by 19.8×. Full ablation is given in Appendix F. Beyond throughput, CuPH produces PDs identical to standard cubical PH on integer images; for floating-point images, the quantization error satisfies Theorem 5 and its empirical verification is given in Appendix E.
Topology-aware Classification. We evaluate CuPH using three topology-aware classification pipelines on four medical image benchmarks (Table 2). PHG-Net [28] originally precomputes PH features offline; the CUPH variant computes them online during training. TopoSwin-SP and TopoSwin-MP [16] originally use CMP, which we replace by CUPH as a drop-in backend.
Based on the results in Table 2, we make three observations. First, replacing CMP by CuPH matches or improves the accuracy across all benchmarks; TopoSwin-MP (CuPH) achieves the best accuracy on ISIC 2018, CBIS-DDSM, and Prostate; on APTOS, TopoSwin-SP (CUPH) leads. Second, replacing PHG-Net's offline-precomputed PH features by CuPH's online-computed features adds 10–11% training overhead while preserving the accuracy within ±1%, eliminating the need for offline PH precomputation. Third, CuPH accelerates TopoSwin training by 4.2–7.1× on the three 224² datasets and 9.9–16.7× on the 512² APTOS, consistent with CuPH's growing advantage at higher resolutions (Table 1a). Minor accuracy differences between PH backends are within typical run-to-run variances; CuPH's PDs match the standard cubical PH exactly on integer images (Appendix E). Peak GPU memory and AUC are reported in Table 7 of the Appendix.
Topology-aware Architectures for Segmentation. We evaluate CuPH as a drop-in PH backend for TopoSwin-SP/TopoSwin-MP on three benchmarks of varying resolutions (Table 3). The architectures and topology loss formulation follow the Experimental Setup; we replace CMP by CuPH.
Table 3 reveals two patterns. (i) Segmentation performance is preserved. In all 12 comparisons between the original and CUPH variants (TopoSwin-SP vs. TopoSwin-SP (CUPH), TopoSwin-MP vs. TopoSwin-MP (CUPH)), each on three benchmarks and two metrics), the largest mean difference is 0.3 points, within cross-seed variance. (ii) Throughput becomes practical. At size 224², CuPH accelerates TopoSwin-SP by 13.3–14.0× over CMP and TopoSwin-MP by 8.3–9.4×; at size 512²
Table 3: Segmentation results with training throughput (img/s). The metrics follow each benchmark's standard convention: Dice and mIoU for ISIC 2018 (T1) and CREMI; Dice and HD95 for Synapse.
| Method | ISIC 2018 (T1) | CREMI | Synapse | ||||||
|---|---|---|---|---|---|---|---|---|---|
| Dice↑ | mIoU↑ | img/s | Dice↑ | mIoU↑ | img/s | Dice↑ | HD95↓ | img/s | |
| Baseline (no PH) | 212.3 | 38.6 | 236.3 | ||||||
| TopoSwin-SP | 12.9 | 1.4 | 13.5 | ||||||
| TopoSwin-SP (CuPH) | 171.5 | 17.8 | 189.1 | ||||||
| TopoSwin-MP | 9.8 | 0.3 | 9.4 | ||||||
| TopoSwin-MP (CuPH) | 81.2 | 13.1 | 88.6 | ||||||
Table 4: CuPH as a drop-in replacement for CPU PH backends in topology-aware segmentation losses, evaluated at full resolution (Dice and clDice in %, training throughput in img/s, batch size 8).
| Method | CREMI | Roads | Platelet | ||||||
|---|---|---|---|---|---|---|---|---|---|
| Dice↑ | clDice↑ | img/s | Dice↑ | clDice↑ | img/s | Dice↑ | clDice↑ | img/s | |
| Topograph (no PH) | 2.51 | 1.42 | 5.47 | ||||||
| HuTopo | 0.19 | 0.08 | 0.44 | ||||||
| HuTopo (CuPH) | 5.54 | 2.46 | 11.01 | ||||||
| BettiMatching | 0.47 | 0.34 | 0.78 | ||||||
| BettiMatching (CuPH) | 14.38 | 10.02 | 24.22 | ||||||
on CREMI, the multi-parameter gap widens to for TopoSwin-MP, taking it from impractical ( img/s) to practical ( img/s) and enabling multi-parameter topology-aware segmentation at this resolution.
Topology-aware Losses for Segmentation. We evaluate CuPH as a drop-in PH backend for HuTopo [14] and BettiMatching [32] on the three topology-aware loss datasets, with Topograph [22] as a non-PH reference. The original HuTopo and BettiMatching compute PH on patches due to CPU backend cost; the CuPH variants compute PH on the full probability map in every training step.
Table 4 reports two findings. First, full-image PH supervision (enabled by CuPH's computational throughput) improves both Dice (+2.2 to +4.6 points) and clDice (+2.0 to +4.4 points) over patch-local PH for both topology losses across all three datasets. Patch-local PH operates on regions rather than the full image, capturing local rather than global topology; this was a workaround for CPU backends [23, 15] where full-image computation was a bottleneck. The accuracy gains therefore reflect the move from patch-local to full-image topology supervision, made practical by CuPH, rather than a pure backend substitution. Second, CuPH accelerates training by over patch-local PH backends, with BettiMatching (CuPH) running faster than Topograph on every dataset, demonstrating that PH-based topology-aware training at full resolution is now practical.
5 Conclusions and Discussion
We presented CuPH, a new GPU algorithm for computing cubical PH that operates directly on pixels rather than cubical cells, reducing parallel depth from to . CuPH produces persistence diagrams identical to standard cubical PH on integer images, with a stability bound for floating-point images, and is faster than the existing GPU baseline.
Extending to Higher Dimensions. CuPH is currently formulated for 2D images, on which Alexander duality reduces to an problem on a padded dual image. In 3D images, Alexander duality relates to , but in the middle dimension is self-dual and still requires matrix reduction. Extending CuPH to 3D thus requires a parallel approach for middle-dimensional homology (for example, through parallel column reduction or matching-based formulations).
Beyond Uniform Quantization. For floating-point images, CuPH relies on uniform -level quantization (Theorem 5). Adaptive or topology-aware quantization could tighten this bound or reduce with similar accuracy, particularly for non-uniformly distributed inputs such as sigmoid model outputs where most mass concentrates near 0 and 1.
References
[1] Asia Pacific Tele-Ophthalmology Society. APTOS 2019 blindness detection. Kaggle, 2019. URL https://www.kaggle.com/c/aptos2019-blindness-detection.
[2] S. Bakas, H. Akbari, A. Sotiras, M. Bilello, M. Rozycki, J. S. Kirby, J. B. Freymann, K. Farahani, and C. Davatzikos. Advancing the cancer genome atlas glioma MRI collections with expert segmentation labels and radiomic features. Scientific Data, 4(1):170117, 2017.
[3] B. Bleile, A. Garin, T. Heiss, K. Maggs, and V. Robins. The persistent homology of dual digital image constructions. In E. Gasparovic, V. Robins, and K. Turner, editors, Research in Computational Topology 2, volume 30 of Association for Women in Mathematics Series, pages 1–26. Springer, Cham, 2022. doi: 10.1007/978-3-030-95519-9_1.
[4] J. Chen, J. Mei, X. Li, Y. Lu, Q. Yu, Q. Wei, X. Luo, Y. Xie, E. Adeli, Y. Wang, M. P. Lungren, S. Zhang, L. Xing, L. Lu, A. L. Yuille, and Y. Zhou. TransUNet: Rethinking the U-Net architecture design for medical image segmentation through the lens of Transformers. Medical Image Analysis, 97:103280, 2024.
[5] J. R. Clough, N. Byrne, I. Oksuz, V. A. Zimmer, J. A. Schnabel, and A. P. King. A topological loss function for deep-learning based image segmentation using persistent homology. IEEE Transactions on Pattern Analysis and Machine Intelligence, 44(12):8766–8778, 2020.
[6] N. C. F. Codella, D. Gutman, M. E. Celebi, B. Helba, M. A. Marchetti, S. W. Dusza, A. Kalloo, K. Liopyris, N. Mishra, H. Kittler, and A. Halpern. Skin lesion analysis toward melanoma detection 2018: A challenge hosted by the international skin imaging collaboration (ISIC), 2019.
[7] D. Cohen-Steiner, H. Edelsbrunner, and J. Harer. Stability of persistence diagrams. Discrete & Computational Geometry, 37(1):103–120, 2007.
[8] H. Edelsbrunner and J. Harer. Computational Topology: An Introduction. American Mathematical Society, 2010.
[9] H. Edelsbrunner and M. Kerber. Alexander duality for functions: The persistent behavior of land and water and shore. In Proceedings of the Annual Symposium on Computational Geometry (SoCG), pages 249–258, 2012.
[10] H. Edelsbrunner, D. Letscher, and A. Zomorodian. Topological persistence and simplification. Discrete & Computational Geometry, 28(4):511–533, 2002.
[11] J. Funke, S. Saalfeld, D. Bock, S. Turaga, and E. Perlman. MICCAI challenge on circuit reconstruction from electron microscopy images (CREMI), 2016. URL https://cremi.org.
[12] M. D. Guay, Z. A. S. Emam, A. B. Anderson, M. A. Aronova, A. A. Sousa, and R. D. Leapman. Dense cellular segmentation for EM using 2D–3D neural network ensembles. Scientific Reports, 11(1):2561, 2021.
[13] M. Harris, S. Sengupta, and J. D. Owens. Parallel prefix sum (scan) with CUDA. In H. Nguyen, editor, GPU Gems 3, chapter 39, pages 851–876. Addison-Wesley, 2007.
[14] X. Hu, F. Li, D. Samaras, and C. Chen. Topology-preserving deep image segmentation. In Proceedings of the Advances in Neural Information Processing Systems, volume 32, pages 5657–5668, 2019.
[15] S. Kaji, T. Sudo, and K. Ahara. Cubical Ripser: Software for computing persistent homology of image and volume data, 2020.
[16] C. Korkmaz, B. Nuwagira, B. Coşkunuzer, and T. Birdal. CuMPerLay: Learning cubical multiparameter persistence vectorizations. In Proceedings of the IEEE/CVF International Conference on Computer Vision (ICCV), 2025.
[17] B. Landman, Z. Xu, J. E. Igelsias, M. Styner, T. Langerak, and A. Klein. MICCAI multi-atlas labeling beyond the cranial vault-workshop and challenge. In Proceedings of the MICCAI Multi-Atlas Labeling Beyond the Cranial Vault Workshop Challenge, volume 5, page 12, 2015.
[18] P. Lawson, A. B. Sholl, J. Q. Brown, B. T. Fasy, and C. Wenk. Persistent homology for the quantitative evaluation of architectural features in prostate cancer histology. Scientific Reports, 9(1):1139, 2019.
[19] R. S. Lee, F. Gimenez, A. Hoogi, K. K. Miyake, M. Gorovoy, and D. L. Rubin. A curated mammography data set for use in computer-aided detection and diagnosis research. Scientific Data, 4(1):170177, 2017. doi: 10.1038/sdata.2017.177.
[20] Z. Liu, H. Hu, Y. Lin, Z. Yao, Z. Xie, Y. Wei, J. Ning, Y. Cao, Z. Zhang, L. Dong, et al. Swin Transformer V2: Scaling up capacity and resolution. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR), pages 12009–12019, 2022.
[21] I. Loshchilov and F. Hutter. Decoupled weight decay regularization. In Proceedings of the International Conference on Learning Representations (ICLR), 2019.
[22] L. Lux, A. H. Berger, A. Weers, N. Stucki, D. Rueckert, U. Bauer, and J. C. Paetzold. Topograph: An efficient graph-based framework for strictly topology preserving image segmentation. In Proceedings of the International Conference on Learning Representations (ICLR), 2025.
[23] C. Maria, J.-D. Boissonnat, M. Glisse, and M. Yvinec. The GUDHI library: Simplicial complexes and persistent homology. In Proceedings of the International Congress on Mathematical Software (ICMS), pages 167–174, 2014.
[24] D. G. Merrill and A. S. Grimshaw. Revisiting sorting for GPGPU stream architectures. In Proceedings of the 19th International Conference on Parallel Architectures and Compilation Techniques (PACT), pages 545–546, 2010.
[25] F. Milletari, N. Navab, and S.-A. Ahmadi. V-Net: Fully convolutional neural networks for volumetric medical image segmentation. In Proceedings of the International Conference on 3D Vision (3DV), pages 565–571, 2016.
[26] V. Mnih. Machine Learning for Aerial Image Labeling. PhD thesis, University of Toronto, 2013.
[27] A. Mosinska, P. Marquez-Neila, M. Kozinski, and P. Fua. Beyond the pixel-wise loss for topology-aware delineation. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR), pages 3136–3145, 2018.
[28] Y. Peng, H. Wang, M. Sonka, and D. Z. Chen. PHG-Net: Persistent homology guided medical image classification. In Proceedings of the IEEE/CVF Winter Conference on Applications of Computer Vision (WACV), pages 7583–7592, 2024.
[29] O. Ronneberger, P. Fischer, and T. Brox. U-Net: Convolutional networks for biomedical image segmentation. In Proceedings of the International Conference on Medical Image Computing and Computer-Assisted Intervention (MICCAI), pages 234–241, 2015.
[30] S. Shit, J. C. Paetzold, A. Sekuboyina, I. Ezhov, A. Unger, A. Zhylka, J. P. W. Pluim, U. Bauer, and B. H. Menze. clDice – a novel topology-preserving loss function for tubular structure segmentation. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR), pages 16560–16569, 2021.
[31] P. Skraba and K. Turner. Wasserstein stability for persistence diagrams, 2020.
[32] N. Stucki, J. C. Paetzold, S. Shit, B. Menze, and U. Bauer. Topologically faithful image segmentation via induced matching of persistence barcodes. In Proceedings of the International Conference on Machine Learning (ICML), volume 202, pages 32698–32727, 2023.
[33] R. E. Tarjan and J. van Leeuwen. Worst-case analysis of set union algorithms. Journal of the ACM, 31(2):245–281, 1984.
[34] A. Zomorodian and G. Carlsson. Computing persistent homology. Discrete & Computational Geometry, 33(2):249–274, 2005.
A Proof of Theorem 1
We prove that CuPH and the standard cubical PH algorithm under the V-construction produce identical non-diagonal persistence diagrams as multisets, for . The proof works at the algorithmic level on Algorithm 1; the GPU implementation in Section 3.3 is a faithful refinement and inherits correctness.
The case proceeds by induction on the filtration level , with three steps at each level: identical inputs (Section A.1), order-invariance (Section A.2), and linearization (Section A.3). The case reduces to via cubical Alexander duality (Section A.5).
Setup. Let be an image on the pixel grid with pixels. Let be the V-construction cubical complex on : pixels are 0-cells, 1-cells join 4-adjacent pixels, 2-cells fill each block, and . We write for the non-diagonal persistence diagram. For each activated pixel , birth[p] denotes its birth level and its lexicographic key. The Elder Rule selects the root with smaller as the survivor; the larger as the dying root.
A.1 Step 1: Identical inputs
Both algorithms process the same set of merges at each level k with the same Elder-Rule semantics.
Lemma 6 (Edge filtration value). For every 1-cell with endpoint pixels , .
Proof. The 0-cell faces of are and , so by definition.
Let denote the set of 1-cells with filtration value . By Lemma 6, an edge has both endpoints activated by level (since ), so is processed at level in any V-construction filtration.
Lemma 7 (Merge realization). Fix a sequential Elder-Rule schedule on starting from the post-Activate state at level . Let have endpoints with current root births . If , no pair is emitted. Otherwise, the schedule emits , non-diagonal iff and .
Proof. The Elder Rule kills the larger- root, which has birth . The pair is non-diagonal iff , equivalently both .
A.2 Step 2: Order-invariance
Lemma 8 (Within-level schedule independence). Fix the union-find state after the Activate phase at level k, comprising pre-level-k components together with newly activated level-k singletons. For any sequential Elder-Rule schedule on :
(i) the resulting partition of activated pixels is the same;
(ii) the multiset of non-diagonal pairs emitted at level k is the same.
Proof. Let be the components active after the Activate phase at level (including newly activated singletons), with keys . Define the auxiliary multigraph on with one edge per joining the components containing its endpoints. Let be the connected components of .
Proof of (i). Two components , end up merged iff they lie in the same , by standard connected-component / union-find equivalence. Hence the post-level- partition is , independent of edge order.
Proof of (ii). Fix and let be its smallest-key component. We claim is the unique survivor in under any sequential Elder-Rule schedule. By the Elder Rule, every union kills the larger- root. At every union involving (or its current super-component, whose root remains , the merge partner's root lies in and has no smaller than ; hence the partner dies and survives. Since is connected, all components in end up unified, leaving as the unique survivor.
The remaining components all die at level , each emitting the pair , non-diagonal iff . The set of dying roots and their births is determined by , so the non-diagonal contribution from is order-independent. Summing over gives the level- non-diagonal multiset.
A.3 Step 3: Linearization
We show that CuPH's concurrent execution at level corresponds to a valid sequential Elder-Rule schedule on .
Lemma 9 (Birth stability). For every pixel , birth[] is written exactly once at activation and never modified. Hence is constant after activation.
Proof. Algorithm 1 writes birth[] only in the Activate phase. FIND reads only label, and MERGE writes only to label.
Lemma 10 (CuPH linearization). Assume the forest invariant holds for every with label[] at the start of CuPH's Connect phase at level . Order the successful CAS operations of Connect by their atomic completion times, denoted . Then:
(i) Coverage. Every is offered to MERGE at least once during Connect.
(ii) Forest invariant. After each and after each path-halving write, the union-find is a valid disjoint-set forest with for all with label[] , and no cycles.
(iii) Schedule realization. The final partition and emitted pair multiset match those of some sequential Elder-Rule schedule on .
Proof. (i) Coverage. Let with endpoints . By Lemma 6, at least one endpoint (say ) lies in bucket[]. The Activate-Connect barrier ensures has label[] when Connect begins. Hence 's thread invokes MERGE().
(ii) Forest invariant. We show every CAS commit and every path-halving write preserves the local invariant , by induction over the linearization order of writes.
A successful CAS(label[], ) requires label[] = at the linearization point, so is a root. The Elder Rule selected at issue time; by Lemma 9, this remains true at the CAS point. After the CAS, label[] = satisfies the invariant. A cycle would require a parent path with strictly decreasing, contradicting .
A path-halving write replaces label[] with a value that the writer observed at label[label[]]. By the local invariant at read time, , so . By Lemma 9, this remains true at write time. Cycles are precluded by the same argument.
CAS writes occur only when is a root; once becomes non-root, subsequent CASes on label[] fail. Path-halving writes target only non-roots. The two write types are temporally disjoint on the same node.
(iii) Schedule realization. For each successful CAS , the CAS premise label[] = at linearization ensures is still the root of one component at that point. Acyclicity (from (ii)) ensures the two roots belong to distinct components, since otherwise the new edge would close a cycle. Hence effects an Elder-Rule union of two distinct components, emitting the pair prescribed by Lemma 7. The sequence realizes Elder-Rule unions on a subset ; edges in have their endpoints already merged via prior CASes. Hence produces the same partition and pair multiset as any sequential schedule on . By Lemma 8, this matches the standard algorithm's output at level .
A.4 Inductive Combination for
Proof of Theorem 1 for . We prove by induction on . The inductive hypothesis is that, at the start of level , both algorithms agree on (A) the activated-pixel partition, (B) the recorded births at roots, and (C) the non-diagonal pair multiset emitted so far, with (D) CuPH's forest satisfying the local invariant.
Base case (k = 0): no pixels activated; (A)–(D) hold vacuously.
Inductive step: assume (A)–(D) hold at the start of level . Both algorithms activate level- pixels as singletons with birth = k, preserving (A), (B), (D). The standard algorithm processes via a sequential Elder-Rule schedule. CuPH's Connect phase, by Lemma 10(iii) (whose forest-invariant assumption is provided by (D)), produces the same final partition and pair multiset as some sequential schedule on . By Lemma 8, all such schedules produce the same outcome. Hence (A)–(C) hold at the start of , and (D) is preserved by Lemma 10(ii).
Essential class. A 4-connected pixel grid has one essential class, born at . Both algorithms record this pair, completing Theorem 1 for .
A.5 via Alexander Duality
The case reduces to via cubical Alexander duality. Define the padded dual image on the enlarged grid by for and on the boundary frame. By cubical Alexander duality [3, 8], as multisets, where is the persistence diagram of under the V-construction with 8-connectivity, excludes the unique essential class from the boundary frame, and .
The equivalence proof above (Lemmas 6–10) makes no use of the specific neighbor relation: Lemma 6 uses only the V-construction max rule, Lemma 8 depends only on the edge set , and Lemma 10's coverage argument requires only that each have at least one endpoint in bucket . These hold for any neighbor relation, including 8-connectivity. Applied to with 8-connectivity, the proof gives .
CuPH's pipeline (Section 3.3) constructs , runs the machinery with 8-connectivity, and applies to each finite pair. Hence
completing Theorem 1.
B Proofs of Theorems 2 and 3
Setup. Let be the number of pixels and the number of discrete intensity levels. Work refers to the total number of operations across all threads; depth refers to the longest sequential dependency chain.
Lemma 11 (Path halving cost under elder-rule linking). For a sequence of FIND and UNION operations on a disjoint-set forest of n elements using path halving with arbitrary linking (in particular, elder-rule linking, where the union step selects the smaller-key root as parent), the total work is , giving amortized cost per operation.
Proof. Lemma 7 of Tarjan and van Leeuwen [33] establishes the bound for path halving with naive (arbitrary-choice) linking: for , the total number of nodes traversed on find paths is at most , which is . The proof relies only on the path-halving invariant (each FIND halves the distance to the root along its path) and on the union step taking constant time; it does not depend on which of the two roots becomes the parent. Hence the bound applies verbatim to elder-rule linking, which deterministically selects the smaller-key root as parent. The classical bound is unavailable here because it requires union-by-rank or union-by-size [33], both of which conflict with elder rule's persistence-driven choice of parent.
Lemma 12 (Sequential CAS does not retry). In the sequential setting (one thread), the total number of CAS retries across all MERGE calls is zero.
Proof. With one thread executing, no other thread modifies label[younger] between the FIND that produced younger and the subsequent CAS. The CAS therefore succeeds on the first attempt. □
Lemma 13 (Sequential dependency across levels). The Connect phase at level k requires the union-find state at the end of level k - 1. The outer loop over levels in Algorithm 1 therefore cannot be parallelized.
Proof. At level , when pixel is in the Connect phase, it examines each 4-neighbor to determine whether is active and the current FIND representative of . Both depend on level 's processing being complete: if has , then became active during level 's Activate phase and may have been merged into other components during level 's Connect phase. Algorithm 1 enforces this dependency through a barrier between consecutive levels: all threads complete level 's Connect phase before any thread begins level 's Activate phase, ensuring that level observes a consistent post-level- union-find state.
B.1 Proof of Theorem 2
Proof. We decompose the work by stage.
Stage 1 (Level Bucketing). The histogram pass performs work per pixel, total . The exclusive prefix sum is . The scatter pass is per pixel, total . Stage 1 total: .
Level Sweeping. The outer loop iterates over L levels. The Activate phase contributes in total across all levels (each pixel activated once). The Connect phase contributes at most 4n merge attempts.
Each merge attempt performs two FIND operations and at most one CAS. By Lemma 11, each FIND costs amortized. By Lemma 12, each CAS succeeds on first attempt and contributes . Total: .
Total. .
B.2 Proof of Theorem 3
Proof. We decompose the depth by stage in the combining-atomic PRAM model.
Stage 1 (Level Bucketing). The histogram pass uses atomic increments to counters. In the combining-atomic model, concurrent atomic increments to one counter complete in depth. The exclusive prefix sum has depth via parallel scan. The scatter pass has depth from atomic contention. Stage 1 depth: .
Level Sweeping. By Lemma 13, the outer loop is sequential, contributing steps. Within each level: Activate has depth (independent writes); the barrier has depth; Connect processes pixels concurrently with up to 4 merge attempts each.
Each merge attempt has depth: FIND cost (under path halving, the union-find tree height remains , so each FIND traverses at most ancestors); CAS attempt ; constant amortized retry rounds, each adding . Per-merge depth: .
Per-level depth: . Total Level Sweeping depth: .
Total. .
Remark 1. Relative to a comparison-sort-based total-order traversal (e.g., Cripser [15]) with sequential depth, the idealized CuPH level sweep reduces the dominant depth to , a factor of . For and , this is approximately . The empirical wall-clock speedups, which incorporate constant-factor effects and finite-P scheduling, are reported in Section 4.
C GPU Implementation Details
This section provides implementation details deferred from Section 3.3.
C.1 Kernel Decomposition
CuPH is realized as a sequence of CUDA kernels following the two-stage structure of algorithm 1. Stage 1 (Level Bucketing) is implemented by three distinct kernels: a histogram kernel that counts pixels per filtration level, an exclusive-prefix-sum kernel that converts these counts into per-level offsets, and a scatter kernel that writes each pixel's index into the corresponding per-level bucket. Stage 2 (Level Sweeping) is implemented by a single processing kernel that performs the Activate-Connect-Merge inner loop for each level. Output packing kernels then convert the internal pair buffers into output tensors and append the essential class corresponding to the global minimum; indexed variants additionally return the pixel indices responsible for each pair, used for gradient assignment in differentiable training.
C.2 Memory Layout
For a batch of images of size with filtration levels, CuPH allocates per-image arrays from a reusable device-memory pool: per-pixel label and birth arrays storing each pixel's union-find representative and birth filtration level; five per-level metadata arrays implementing the bucket structure (a histogram of pixel counts per level, exclusive-scan offsets into the bucket, per-level pixel counts, atomic scatter counters, and the bucketed pixel-index list itself); separate birth and death arrays sized to the maximum possible pairs per image; and per-image scalars (atomic pair counter, accepted-pair count, minimum filtration level). Indexed variants additionally allocate creator and destroyer arrays storing the pixel indices associated with each pair: the creator pixel is the dying root's representative at birth, and the destroyer pixel is the one whose activation triggered the merge. Independent images occupy disjoint regions of each array, allowing concurrent access from different blocks without cross-block synchronization.
C.3 Processing Kernel: Activate-Connect-Merge
Each image is assigned to one CUDA block; threads in the block iterate over filtration levels in ascending order. At each nonempty level, the threads first execute the Activate phase, writing labels and birth values for all pixels in the level's bucket. A block-local barrier separates this from the Connect phase, in which threads visit each newly active pixel's neighbors and invoke the merge primitive whenever an active neighbor lies in an earlier or current level. The barrier ensures that all activations at level complete before any merges at level begin, preserving the level-synchronous invariant required by theorem 1.
C.4 Concurrent Merge Primitive
The merge primitive performs an elder-rule union of the components containing two given pixels. Representatives are located via FIND with path halving: at each step the search reads the current node's grandparent and writes it back as the new parent of the current node, halving the path length for subsequent queries (in contrast to full path compression, which sets every visited node's parent to the root in a second pass). Once the two representatives are found, the elder root (smaller lexicographic key (birth, index)) is selected as the survivor; the dying root is attached to the survivor via atomicCAS on its self-loop label entry. On a successful CAS, non-diagonal pairs reserve an output slot via atomicAdd on the per-image pair counter and write the entry; indexed variants additionally record the creator and destroyer pixel indices. Failed CASes indicate that another thread has updated the dying root's parent in the meantime; the merge retries with refreshed representatives obtained from a new FIND.
The number of CAS retries per merge is bounded by the number of concurrent merges affecting the same root, which is constant amortized in practice (consistent with the assumption in theorem 3). Failed CASes emit no pair, so no spurious pairs are recorded. Forest validity follows from the monotone representative-key invariant proved in theorem 1 (Step 4 of the proof sketch): every
Table 5: Benchmark datasets.
| Task | Dataset | Resolution | Classes | Train / Test | Domain |
|---|---|---|---|---|---|
| Classification | CBIS-DDSM | 2 | 1,247 / 624 | Mammography | |
| Prostate Cancer | 3 | 4,145 / 1,037 | Histopathology | ||
| ISIC 2018 (T3) | 7 | 9,013 / 1,002 | Dermatology | ||
| APTOS 2019 | 5 | 3,296 / 366 | Ophthalmology | ||
| Segmentation | ISIC 2018 (T1) | 2 | 2,698 / 1,002 | Dermatology | |
| CREMI | 1250^2^{\dagger} | 2 | 336 / 39 | Electron microscopy | |
| Synapse | 9 | 2,211 / 1,568 | Abdominal CT | ||
| Topology-aware loss | Roads | 2 | 1,122 / 49 | Aerial imagery | |
| Platelet | 7 | 50 / 24 | Electron microscopy |
† CREMI is used at native for topology-aware loss experiments and resized to for the segmentation.
successful CAS attaches a node to a parent with strictly smaller , precluding cycles regardless of CAS interleaving order.
C.5 via Padded Dual
The pipeline reuses the same kernel sequence as via cubical Alexander duality [3, Theorem 5]. The padded dual image is materialized in a small set of tensor operations preceding the kernel pipeline: pixel values in the interior are complemented as , and a zero-valued boundary frame of width one is attached on all sides. These operations are dispatched as standard PyTorch elementwise GPU kernels, not as part of the CuPH processing kernel; their cost is negligible relative to the level sweep. The processing kernel then runs on with 8-connectivity (the topological dual of 4-connectivity), and the output packing applies the duality pair-transformation to each finite pair, excluding the essential class corresponding to the boundary frame. The result is the persistence diagram of the original image. Superlevel filtrations are handled analogously: the input is mapped via before the sweep, and pairs are transformed correspondingly during output.
D Experimental Details
This appendix collects dataset preprocessing, PH algorithm implementation notes, per-dataset training hyperparameters, and the software and hardware stack used in Section 4.
D.1 Dataset Details and Preprocessing
ISIC 2018 (Task 3). The ISIC 2018 Task 3 challenge [6] contains 10,015 dermoscopy images across 7 diagnostic classes (melanoma, melanocytic nevus, basal cell carcinoma, actinic keratosis, benign keratosis, dermatofibroma, vascular lesion). The class distribution is highly imbalanced, with melanocytic nevus accounting for roughly two-thirds of the training set. We use the official challenge split, combining training and validation for training (9,013 images) and evaluating on the held-out test set (1,002 images). Images are resized to using bilinear interpolation and converted to 8-bit grayscale via the ITU-R BT.601 luma transform () for PH computation; the RGB image is retained as input to the SwinV2-B backbone. Augmentations during training include random horizontal and vertical flips, random rotation (), and color jitter (brightness/contrast/saturation ).
CBIS-DDSM. CBIS-DDSM [19] provides curated mammography regions of interest with binary labels (benign vs. malignant). We use the provider's split, combining training and validation for training (1,247 images) and evaluating on the held-out test set (624 images). We extract the pre-cropped ROI patches, resize to , and apply min-max normalization to on the single-channel DICOM intensities. Augmentations include random horizontal flip and random rotation ().
Prostate Cancer. The Prostate Cancer dataset [18] consists of 5,182 H&E-stained ROIs extracted from 77 whole-slide images, annotated into three Gleason grade categories (benign, Gleason 3, Gleason 4+5). We use a fixed patient-level split that combines training and validation for training (4,145 images) and evaluates on a held-out test set (1,037 images), preventing slide-level leakage across train and test. ROIs are resized to 224², converted to 8-bit grayscale via the BT.601 luma transform, and augmented with random flips, 90° rotations, and stain-neutral color jitter.
APTOS 2019. APTOS 2019 [1] provides 3,662 diabetic retinopathy fundus images labeled on a 5-point severity scale (0: no DR; 1: mild; 2: moderate; 3: severe; 4: proliferative). Since the Kaggle test labels are withheld, we re-split the public training set with a stratified random split (seed 42) that combines training and validation for training (3,296 images) and evaluates on the held-out test set (366 images), preserving the class distribution. Images are resized to 512² using bilinear interpolation and converted to 8-bit grayscale via the BT.601 luma transform. We apply circular field-of-view cropping followed by random flips and rotation (±20°).
Segmentation datasets. ISIC 2018 (Task 1) [6] is used at 224² for the main segmentation experiments, with the official challenge split combining training and validation for training (2,698 images) and the held-out test set (1,002 images). CREMI [11] (electron microscopy; neuron membrane segmentation) is used at two resolutions: 512² crops for the main segmentation results in Table 3, and at the native 1250² for the topology-aware loss experiments in Table 4; both follow the same volume-level train/test split (336/39 slices). Synapse [17] (abdominal CT; 9-class multi-organ segmentation) is used at 224² as 2D axial slices from the standard 18/12 training/testing volume split following [4], yielding 2,211/1,568 slices. Massachusetts Roads [26] is used at native 1500² for the topology-aware loss experiments, with the split defined by Lux et al. [22] (1,122/49). Platelet [12] (electron microscopy; 7-class organelles) is used at native 800² following the same protocol (50/24).
D.2 PH Algorithm Implementation Notes
All four PH algorithms that we compare compute zero- and one-dimensional cubical persistent homology ( and ) on 2D images interpreted as sublevel-set filtrations of a scalar field, but they differ in their cubical complex conventions and internal algorithms.
T-construction vs. V-construction. GUDHI [23] uses the T-construction, in which each pixel becomes a top-dimensional cube (a 2-cell) and lower-dimensional cells arise as shared boundaries. Cripser [15] and CMP [16] use the V-construction, in which each pixel is a vertex (0-cell) and edges/faces arise from adjacency. The two conventions are dual under Alexander duality: under T-construction corresponds to under V-construction and vice versa on a 2D domain with appropriate boundary conditions [3]. CuPH adopts the V-construction to match the convention used by Cripser and CMP, which simplifies direct comparison.
Equivalence of persistence diagrams. For integer-valued 2D inputs, all four algorithms produce identical persistence diagrams (up to the T/V convention swap) modulo the essential class treatment at infinity, which we verify empirically in Table 8. For floating-point inputs, CuPH and CMP require quantization to a finite number of filtration levels, while GUDHI and Cripser operate directly on floats; the quantization error is bounded by Theorem 5 and verified empirically in Table 8.
Parallelism. GUDHI is single-threaded per image but parallelized across a batch (OMP_NUM_THREADS=16). Cripser is similarly single-threaded per image and parallelized across the batch. CMP assigns one GPU thread per image, yielding batch-level but not within-image parallelism. CuPH exploits within-image parallelism via level-synchronous processing with up to 512 threads per image, as detailed in Section 3.3.
D.3 Training Hyperparameters
All experiments use AdamW [21] (lr = 10⁻⁴, weight decay 0.01) in fp32 with a cosine learning-rate schedule and linear warmup over the first 5% of training steps. Classification follows PHG-Net's training setup [28] at batch size 32. Topology-aware loss experiments follow the Topograph protocol [22] (loss weights, image crops, optimization schedule). Segmentation experiments share
Table 6: PH throughput on 224² ISIC and CBIS-DDSM at batch size 64 ( and ). GUDHI and Cripser run on 16 CPU threads. Memory column reports peak GPU allocation.
| Method | Device | ISIC (img/s) | CBIS (img/s) | Memory |
|---|---|---|---|---|
| GUDHI | CPU | 97.5 | 120.5 | — |
| Cripser | CPU | 458.5 | 526.3 | — |
| CMP | GPU | 56.2 | 48.6 | 994 MB |
| CuPH (ours) | GPU | 5,232 | 5,023 | 272 MB |
the classification optimizer and schedule; per-dataset epoch counts and topology loss weights are released with the code.
TopoSwin-SP/MP configurations. We use the released configurations from [16]: TopoSwin-SP uses single-parameter persistence with filt_rows=1, and TopoSwin-MP uses multi-parameter persistence with filt_rows=8. CMP runs with OMP_NUM_THREADS=1 per the authors' documentation, since their implementation contends with the CUDA backend at higher thread counts.
Topology loss weights. For the topology-aware loss experiments (Table 4), we use the loss weightings from [22], each combined with a Dice + cross-entropy pixel loss.
D.4 Software and Hardware Stack
All experiments run on a single NVIDIA H100 (80 GB HBM3) GPU; CPU PH baselines run on 16 threads of an AMD EPYC 7543 32-core processor (OMP_NUM_THREADS=16). The software stack includes CUDA, cuDNN, PyTorch (with torch.compile disabled for timing measurements to avoid JIT compilation overhead), GUDHI, Cripser (CubicalRipser), and CMP (the cubical PH backend in CuMPerLay). CuPH source code will be released upon acceptance.
Timing methodology. All GPU timings use torch.cuda.synchronize() before and after the measured region, with a 5-iteration warmup before recording. Throughput is computed over full-epoch passes where indicated in the table caption and over fixed-size batches otherwise. CPU timings are wall-clock, measured with time.perf_counter(). Accuracy and Dice metrics are reported as mean±std over 5 random seeds; throughput is the mean over 5 runs.
Bit-depth and channel conversion for PH. PH operates on single-channel scalar fields. We process each dataset at its native bit depth to preserve intensity precision:
-
8-bit RGB (ISIC 2018 T1/T3, Prostate Cancer, APTOS 2019, Roads): converted to single-channel 8-bit luminance via the ITU-R BT.601 transform, .
-
16-bit mammography (CBIS-DDSM): raw 16-bit DICOM intensities, linearly rescaled to [0, 65535] per image.
-
12-bit CT (Synapse): Hounsfield units windowed to [-125, 275], then linearly rescaled to the 12-bit range [0, 4095].
-
8-bit EM (CREMI): native uint8 grayscale, used directly.
-
16-bit EM (Platelet): native uint16 grayscale, used directly.
The RGB backbone input (for classification and segmentation models that accept color) uses the original three-channel images without any conversion; only the PH pipeline consumes the single-channel intensities.
D.5 Full Classification Efficiency
Table 7 reports AUC, training throughput, and peak GPU memory for all classification methods, complementing Table 2. Some entries use a smaller batch size where the default (32) exceeds GPU memory; these are marked † (bs = 16) and ‡ (bs = 8). On CBIS-DDSM, AUC is depressed for TopoSwin variants due to binary class imbalance, a regime where Acc and AUC diverge; following [16] we report Acc as the primary metric in Table 2.
Table 7: Full classification efficiency on a single H100. Each cell: AUC (%) / throughput (img/s) / peak GPU memory (GB).
| Method | ISIC 2018 (T3) | CBIS-DDSM | Prostate | APTOS |
|---|---|---|---|---|
| SwinV2-B | ||||
| PHG-Net | ||||
| PHG-Net (CUPH) | ||||
| TopoSwin-SP | ||||
| TopoSwin-SP (CUPH) | ||||
| TopoSwin-MP | ||||
| TopoSwin-MP (CUPH) |
E Correctness Verification
This appendix empirically verifies CUPH's correctness against Cripser [15] as a reference implementation, complementing Theorem 1 (integer correctness) and Theorem 5 (float quantization stability) in the main paper.
Experimental setup. We evaluate numerical agreement between CUPH and Cripser on 500 randomly selected medical images per datatype at resolution (batch 64). Three datatypes are examined: uint8 from ISIC 2018 (T3), uint16 from BraTS [2], and float32 from BraTS with per-volume min-max normalization to . Table 8 reports persistence-diagram agreement and throughput. Pair agreement is the fraction of () pairs that match between CUPH and Cripser, reported separately for and . We also report bottleneck distance (BD) and 2-Wasserstein distance () on the persistence diagrams; speedup is CUPH throughput divided by Cripser throughput on the same inputs.
Integer inputs. For uint8 and uint16 inputs, CUPH matches Cripser exactly: every () pair value agrees, yielding 100% pair agreement and . Both algorithms process the same finite set of integer filtration levels with identical merge-tree logic, so differences in scheduling do not affect the final pair values. Theorem 1 formally establishes this exact correspondence for finite-level filtrations.
Float32 inputs. For float32 inputs, CUPH discretizes the input into filtration levels before its bucket-parallel sweep, while Cripser operates on the native float representation (Cripser internally promotes float32 to float64). The discretization introduces a controlled approximation that satisfies the stability bound:
where denotes the -level discretization of [7]. Table 8 confirms this scaling empirically: BD decreases as , reaching at , and exhibits the same trend, decreasing from at to at . The bound is tight in practice: empirical BD values match the theoretical range()/(2) prediction within a small constant factor across the entire sweep. A residual of pairs remain unmatched at , arising from tie-breaking when two pixels share the same quantized value; the resulting persistence diagrams remain within the BD bound and the unmatched pairs do not affect downstream applications, as confirmed by the matching classification (Table 2) and segmentation (Table 3) results.
Throughput across . Table 8 also reports the speedup of CUPH over Cripser at each . CUPH exceeds Cripser's throughput across the float32 sweep, with the advantage decreasing from at to at as the bucket-sweep cost grows linearly with . We use as the default for uint16 medical data, since the effective per-image entropy of typical 16-bit medical scans is well below distinct values.
Table 8: Persistence-diagram agreement and throughput of CUPH vs. Cripser on 500 images per datatype at 224² (batch 64). For float32 inputs, CUPH discretizes to filtration levels; Cripser uses the native-float representation. Pair agreement is the fraction of pairs that match, reported separately for and . For integer inputs, is the natural number of distinct intensity values.
| Input | pairs | pairs | max BD | max WD₂ | Speedup | |
|---|---|---|---|---|---|---|
| uint8 | 100% | 100% | 0 | 0 | 18.0× | |
| uint16 | 100% | 100% | 0 | 0 | 5.4× | |
| float32 | 83.2% | 85.5% | 13.3× | |||
| float32 | 95.2% | 95.9% | 7.5× | |||
| float32 | 98.7% | 99.0% | 3.8× | |||
| float32 | 99.3% | 99.5% | 2.9× | |||
| float32 | 99.6% | 99.8% | 2.3× | |||
| float32 | 99.8% | 99.8% | 1.8× |
Table 9: Memory footprint for the correctness experiment on 224² images at batch 32 (16-worker Cripser configuration). CUPH memory is GPU allocation; Cripser memory is CPU resident set size (RSS) aggregated across workers.
| Input | CUPH GPU (batch 32) | Cripser CPU RSS (16 workers, aggregate) | |
|---|---|---|---|
| uint8 | ~62 MB | 5.64 GB (352.7 MB ×16) | |
| uint16 | ~65 MB | 5.66 GB (353.9 MB ×16) | |
| float32 | ~62 MB | 5.68 GB (355.0 MB ×16) | |
| float32 | ~109 MB | 5.68 GB |
Memory footprint. Table 9 reports memory usage for the correctness experiment. CUPH’s GPU allocation is 50–90× smaller than Cripser’s aggregated CPU resident set size in the 16-worker configuration across all tested input types and values.
F Ablation: Detailed Results
Table 10 reports ablation results on uint8 ISIC at . This appendix extends those results across datatypes and engineering optimizations.
F.1 Cross-datatype Trends
Table 11 reports throughput and slowdown for each algorithmic ablation across uint16 and float32 inputs (uint8 results are in Table 10). Two patterns emerge.
Level Bucketing’s contribution grows with . At (uint8), removing Level Bucketing yields a slowdown; at (uint16, float32), the slowdown rises to . Larger requires the no-bucket variant to scan all pixels at more filtration levels, increasing the cost of removing the bucket structure proportionally.
Parallel Level Sweep’s contribution shrinks with . At , removing the parallel sweep yields a slowdown; at , the slowdown drops to . Larger means fewer pixels activate per level on average, leaving less within-level parallelism for the sweep to exploit.
The two contributions are complementary across the practical range: bucket sort dominates at high , parallel sweep dominates at low . Both are necessary for the full speedup.
Joint ablation supermultiplicativity intensifies at high . At , removing both contributions yields a slowdown, above the multiplicative prediction of . At , the joint slowdown jumps to (uint16) and (float32), over above the product of individual ablations ( and ). The gap between joint and individual slowdowns widens with .
Table 10: Ablation of CUPH on ISIC at 224², batch 64. Slowdown is the throughput ratio of full CUPH to the variant.
| Variant | img/s | Slowdown |
|---|---|---|
| CUPH (full) | 5,232 | 1.0× |
| without Level Bucketing | 1,139 | 4.6× |
| without Parallel Level Sweep | 249 | 21.0× |
| without Level Bucketing and Parallel Level Sweep | 12.3 | 425.4× |
Table 11: Cross-datatype ablation results at batch 64. Throughput in img/s; slowdown is the throughput ratio of full CUPH to the variant; mean ± std over 5 runs.
| Variant | uint16 () | float32 () |
|---|---|---|
| CUPH (full) | 1,628 ± 16 (1.0×) | 1,542 ± 5 (1.0×) |
| without Level Bucketing | 241 ± 1 (6.7×) | 239 ± 0.3 (6.4×) |
| without Parallel Level Sweep | 197 ± 1 (8.3×) | 197 ± 1 (7.8×) |
| without both | 0.87 ± 0.0001 (1,878×) | 0.87 ± 0.0004 (1,779×) |
because the no-bucket scan compounds across more levels when the parallel sweep is also removed, and a single thread cannot amortize the per-level scan cost.
F.2 Engineering Ablations
Table 12 reports the slowdown when each engineering optimization is removed, across all three datatypes. Four observations:
-
Shared-memory histogram contributes negligibly. Replacing the shared-memory accumulation with global-memory atomic adds yields essentially the same throughput () across all datatypes. The histogram phase is a small fraction of total runtime, and modern global atomics are fast enough on H100.
-
GPU memory pool contributes modestly. Replacing the persistent allocator with cudaMalloc/Free per call yields slowdown. The cost is amortized across the batch but not eliminated.
-
Path halving in union-find has no measurable benefit on these datasets. Removing path halving yields a slight throughput increase ( ratio of full to variant means the variant is 1–3% faster). Component trees on BraTS and ISIC are shallow enough that path halving's amortized advantage is dominated by its constant-factor overhead in the find operation. We retain path halving in the production code because it provides asymptotic guarantees on adversarial inputs.
-
Lock-free Component Tracking is the largest engineering contributor. Replacing the lock-free atomicCAS merge with a global lock that serializes within-level merges yields a slowdown on uint8 ISIC. Activation-phase parallelism contributes only of additional headroom over the no-parallel-sweep variant ( slowdown), confirming that the lock-free design is what allows within-image parallelism to translate into throughput.
Thread-count saturation depends on . Table 13 shows threads-per-block sensitivity. At (uint8), reducing from to yields a slowdown. At (uint16, float32), the same reduction yields only slowdown. At higher , fewer pixels activate per level, so within-level parallelism saturates with fewer threads, and the level loop itself dominates runtime regardless of thread count.
F.3 Correctness Validation
All ablation variants produce persistence diagrams that match CUPH (full) bit-exactly on integer inputs. Validation across 11 variants, 3 datatypes, 5 test images, and both and (330 set-equality checks total) confirms exact correspondence. The path-halving ablation, despite removing
Table 12: Engineering ablation slowdowns at batch 64. Slowdown is the throughput ratio of full CUPH to the variant; mean over 5 runs.
| Removed optimization | uint8 () | uint16 () | float32 () |
|---|---|---|---|
| shared-memory histogram | 1.00× | 1.00× | 1.00× |
| GPU memory pool | 1.19× | 1.09× | 1.08× |
| path halving | 0.99× | 0.97× | 0.98× |
| lock-free Component Tracking | 19.8× | — | — |
Table 13: Threads-per-block sensitivity at batch 64. Slowdown is the throughput ratio of (default) to the variant; mean over 5 runs.
| Threads / block | uint8 () | uint16 () | float32 () |
|---|---|---|---|
| 512 (default) | 1.0× | 1.0× | 1.0× |
| 256 | 0.99× | 1.00× | 1.00× |
| 128 | 1.61× | 1.09× | 1.09× |
| 64 | 2.90× | 1.24× | 1.26× |
the path-shortening optimization, preserves correctness: the union-find merge logic is independent of compression strategy.
F.4 Implementation Notes
Without Level Bucketing. The histogram, prefix-sum, and scatter kernels are skipped entirely. The main kernel iterates all pixels at every level with a per-pixel level-equality check (), activating and connecting only those pixels whose value matches the current level.
Without Parallel Level Sweep. Both the activate and connect phases of cupp_process_levels_kernel are wrapped in if () { ... }. Other threads in the block remain idle. __syncthreads() barriers remain in place to preserve block well-formedness; per-phase synchronization inside the divergent branch would invoke undefined behavior. The atomic-CAS retry loop in cg_merge_components succeeds on the first attempt under single-thread execution, so the backoff path is never exercised.
Without both. Both modifications are combined: histogram/prefix-sum/scatter kernels are skipped, and the main kernel processes all pixels at every level using only thread 0.
Without lock-free Component Tracking. The activation phase remains parallel across 512 threads, but the connect phase serializes all merges within each filtration level: the merge operations are wrapped in if () while the activation phase runs in parallel. Path halving in FIND is retained to isolate the contribution of the lock-free atomicCAS primitive specifically.