Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,41 @@ def _commit_accepted_candidates(
accepted_radii[accepted_idx] = candidate_radii[candidate_idx]


# Deterministically prune any conflicts left by the parallel candidate pass.
@wp.kernel
def _mark_accepted_conflicts(
hashgrid_id: wp.uint64,
accepted_positions: wp.array(dtype=wp.vec3f),
accepted_radii: wp.array(dtype=wp.float32),
accepted_alive: wp.array(dtype=wp.int32),
search_radius: wp.float32,
):
sample_idx = wp.tid()
if accepted_alive[sample_idx] == 0:
return

sample_position = accepted_positions[sample_idx]
sample_radius = accepted_radii[sample_idx]

neighbor_idx = int(0)
query = wp.hash_grid_query(hashgrid_id, sample_position, search_radius)
while wp.hash_grid_query_next(query, neighbor_idx):
if neighbor_idx >= sample_idx:
continue
if neighbor_idx >= accepted_positions.shape[0]:
continue

neighbor_radius = accepted_radii[neighbor_idx]
min_radius = wp.min(sample_radius, neighbor_radius)
if _points_too_close(
sample_position,
accepted_positions[neighbor_idx],
min_radius,
):
accepted_alive[sample_idx] = 0
return
Comment on lines +229 to +243
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Transitive over-pruning due to missing alive check on neighbors

The kernel never checks accepted_alive[neighbor_idx] before deciding to kill sample_idx. Every thread starts with all entries equal to 1 (from torch.ones), so in a chain A (idx=3) → B (idx=5) → C (idx=7) where A–B and B–C are both too close but A–C are not: thread 5 kills itself (conflict with 3), and thread 7 also kills itself (conflict with 5) — even though 5 will be removed and C is actually valid. The fix would be to add if accepted_alive[neighbor_idx] == 0: continue before the _points_too_close call, but a single parallel pass cannot see writes from sibling threads; correcting this correctly requires iterating the kernel until no more kills occur, or performing the pruning serially.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@loliverhennigh is this a valid concern?



# Compute Yuksel sample-elimination contribution for one pairwise distance.
@wp.func
def _wse_pair_weight(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
_count_wse_neighbors,
_generate_surface_candidates,
_initialize_wse_weights_from_csr,
_mark_accepted_conflicts,
_mark_wse_deleted_batch,
_reject_candidates_vs_accepted,
_resolve_candidate_conflicts,
Expand Down Expand Up @@ -851,7 +852,36 @@ def _run_dart_throwing_pass(
pass_seed=random_seed,
pass_limit=max_points,
)
return accepted_positions[:final_count].contiguous()
if final_count <= 1:
return accepted_positions[:final_count].contiguous()

final_positions = accepted_positions[:final_count]
final_radii = accepted_radii[:final_count]
final_alive = torch.ones(
(final_count,),
device=mesh_vertices.device,
dtype=torch.int32,
)
final_search_radius = max(min_distance, adaptive_max_radius)
accepted_grid.build(
points=wp.from_torch(final_positions, dtype=wp.vec3f),
radius=final_search_radius,
)
wp.launch(
kernel=_mark_accepted_conflicts,
dim=final_count,
inputs=[
accepted_grid.id,
wp.from_torch(final_positions, dtype=wp.vec3f, return_ctype=True),
wp.from_torch(final_radii, dtype=wp.float32, return_ctype=True),
wp.from_torch(final_alive, dtype=wp.int32, return_ctype=True),
float(final_search_radius),
],
device=wp_launch_device,
stream=wp_launch_stream,
)
kept_indices = torch.nonzero(final_alive != 0, as_tuple=False).squeeze(1)
return final_positions.index_select(0, kept_indices).contiguous()


# Public alias used by the FunctionSpec wrapper.
Expand Down