Skip to content

Commit b693b30

Browse files
authored
Merge branch 'master' into triton
2 parents 102736e + a266f8e commit b693b30

3 files changed

Lines changed: 35 additions & 7 deletions

File tree

torch_cluster/fps.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,32 @@
55

66
import torch_cluster.typing
77

8+
@torch.library.register_fake("torch_cluster::fps")
9+
def _(src, ptr, ratio, random_start = True):
10+
torch._check(src.device == ptr.device)
11+
torch._check(ptr.ndim == 1)
12+
13+
ctx = torch.library.get_ctx()
14+
nnz = ctx.new_dynamic_size()
15+
return ptr.new_empty((nnz,))
16+
17+
@torch.library.register_fake("torch_cluster::fps")
18+
def _(src, ptr, ratio, random_start=True):
19+
torch._check(src.device == ptr.device)
20+
torch._check(ptr.ndim == 1)
21+
22+
ctx = torch.library.get_ctx()
23+
nnz = ctx.new_dynamic_size()
24+
return ptr.new_empty((nnz,))
25+
26+
@torch.library.register_fake("torch_cluster::fps")
27+
def _(src, ptr, ratio, random_start=True):
28+
torch._check(src.device == ptr.device)
29+
torch._check(ptr.ndim == 1)
30+
31+
ctx = torch.library.get_ctx()
32+
nnz = ctx.new_dynamic_size()
33+
return ptr.new_empty((nnz,))
834

935
@torch.library.register_fake("torch_cluster::fps")
1036
def _(src, ptr, ratio, random_start=True):

torch_cluster/triton/_kernels.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,16 +99,16 @@ def _nearest_kernel(
9999
offs_n = pid * BLOCK_N + tl.arange(0, BLOCK_N) # X indices.
100100
mask_x = offs_n < N # Valid x rows.
101101
if EVEN_N:
102-
tl.multiple_of(offs_n, 8)
103-
tl.max_contiguous(offs_n, 8)
102+
tl.multiple_of(offs_n, 8) # Hint contiguous access.
103+
tl.max_contiguous(offs_n, 8) # Hint vectorization.
104104

105105
best_dist = tl.full((BLOCK_N,), float('inf'), tl.float32) # Best dist.
106106
best_idx = tl.zeros((BLOCK_N,), dtype=tl.int32) # Best y index.
107107

108108
if USE_BATCH:
109-
batch_id = tl.load(batch_x_ptr + offs_n, mask=mask_x, other=0)
110-
left = tl.load(ptr_y_ptr + batch_id, mask=mask_x, other=0)
111-
right = tl.load(ptr_y_ptr + batch_id + 1, mask=mask_x, other=0)
109+
batch_id = tl.load(batch_x_ptr + offs_n, mask=mask_x, other=0) # Batch id per x.
110+
left = tl.load(ptr_y_ptr + batch_id, mask=mask_x, other=0) # y range start.
111+
right = tl.load(ptr_y_ptr + batch_id + 1, mask=mask_x, other=0) # y range end.
112112
else:
113113
left = 0 # Full y range.
114114
right = M
@@ -194,7 +194,7 @@ def _nearest_kernel(
194194
inv_y = tl.rsqrt(y_sq + EPS) # 1/||y||.
195195
dist = 1.0 - acc * (inv_y[:, None] * inv_x[None, :])
196196
else:
197-
dist = tl.fma(-2.0, acc, y_sq[:, None] + x_sq[None, :])
197+
dist = tl.fma(-2.0, acc, y_sq[:, None] + x_sq[None, :]) # L2^2 distance.
198198

199199
if full_y:
200200
valid = tl.broadcast_to(mask_x[None, :], (BLOCK_M, BLOCK_N))
@@ -218,7 +218,7 @@ def _nearest_kernel(
218218
best_dist = tl.where(better, block_min, best_dist)
219219
best_idx = tl.where(better, block_idx, best_idx)
220220

221-
tl.store(out_ptr + offs_n, best_idx.to(tl.int64), mask=mask_x)
221+
tl.store(out_ptr + offs_n, best_idx.to(tl.int64), mask=mask_x) # Write output.
222222

223223

224224
@triton.autotune(

torch_cluster/triton/knn.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
from __future__ import annotations
2+
import math
3+
import triton
24
from typing import Optional
35

46
import triton

0 commit comments

Comments
 (0)