Skip to content

Commit 437500e

Browse files
committed
Make radius func consistent with knn
1 parent f717cb7 commit 437500e

2 files changed

Lines changed: 8 additions & 24 deletions

File tree

torch_cluster/triton/_kernels.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -561,8 +561,7 @@ def _radius_segmented_kernel(
561561
y_ptr,
562562
ptr_x_ptr,
563563
example_idx_ptr,
564-
row_ptr,
565-
col_ptr,
564+
grid_ptr,
566565
M,
567566
N,
568567
D,
@@ -652,7 +651,7 @@ def _radius_segmented_kernel(
652651
order=(0, 1),
653652
)
654653

655-
for nd in tl.static_range(NUM_D_BLOCKS):
654+
for nd in range(NUM_D_BLOCKS):
656655
if EVEN_D:
657656
x = tl.load(x_block_ptr)
658657
y = tl.load(y_row_ptr)
@@ -684,7 +683,7 @@ def _radius_segmented_kernel(
684683
write = mask & (pos < max_neighbors)
685684
pos_safe = tl.where(write, pos, 0)
686685
out_offset = n_y * MAX_NEIGHBORS + pos_safe
687-
tl.store(row_ptr + out_offset, n_y, mask=write)
688-
tl.store(col_ptr + out_offset, x_idx, mask=write)
686+
tl.store(grid_ptr + out_offset, n_y, mask=write)
687+
tl.store(grid_ptr + M * MAX_NEIGHBORS + out_offset, x_idx, mask=write)
689688
count += tl.sum(write, axis=0).to(tl.int32)
690689
xb += 1

torch_cluster/triton/radius.py

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -75,31 +75,17 @@ def radius(
7575
else:
7676
max_candidates = 0
7777

78-
row = torch.full(
79-
(M * max_num_neighbors,),
80-
-1,
81-
device=y.device,
82-
dtype=torch.int64,
83-
)
84-
col = torch.full(
85-
(M * max_num_neighbors,),
86-
-1,
87-
device=y.device,
88-
dtype=torch.int64,
89-
)
90-
9178
if max_candidates == 0 or max_num_neighbors <= 0:
92-
mask = row != -1
93-
return torch.stack([row[mask], col[mask]], dim=0)
79+
return torch.empty(2, 0, device=x.device, dtype=torch.int64)
9480

81+
grid_out = torch.full((2, M * max_num_neighbors), -1, device=x.device, dtype=torch.int64)
9582
grid = (M,)
9683
_radius_segmented_kernel[grid](
9784
x,
9885
y,
9986
ptr_x,
10087
example_idx,
101-
row,
102-
col,
88+
grid_out,
10389
M,
10490
N,
10591
D,
@@ -113,5 +99,4 @@ def radius(
11399
IGNORE_SAME_INDEX=ignore_same_index,
114100
)
115101

116-
mask = row != -1
117-
return torch.stack([row[mask], col[mask]], dim=0)
102+
return grid_out[:, grid_out[0] != -1]

0 commit comments

Comments
 (0)