Skip to content

Commit 9ca282b

Browse files
committed
Add Triton support
1 parent cd01935 commit 9ca282b

9 files changed

Lines changed: 35 additions & 8 deletions

File tree

csrc/cluster.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,3 @@ TORCH_LIBRARY(torch_cluster, m) {
5050
m.def("neighbor_sampler(Tensor start, Tensor rowptr, int count, float factor) -> Tensor");
5151
m.def("cuda_version() -> int");
5252
}
53-
54-
}

csrc/fps.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,7 @@ TORCH_LIBRARY_IMPL(torch_cluster, CPU, m) {
4141
TORCH_LIBRARY_IMPL(torch_cluster, CUDA, m) {
4242
m.impl("fps", &fps_cuda);
4343
}
44+
TORCH_LIBRARY_IMPL(torch_cluster, HIP, m) {
45+
m.impl("fps", &fps_cuda);
46+
}
4447
#endif

csrc/graclus.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,7 @@ TORCH_LIBRARY_IMPL(torch_cluster, CPU, m) {
4141
TORCH_LIBRARY_IMPL(torch_cluster, CUDA, m) {
4242
m.impl("graclus", &graclus_cuda);
4343
}
44+
TORCH_LIBRARY_IMPL(torch_cluster, HIP, m) {
45+
m.impl("graclus", &graclus_cuda);
46+
}
4447
#endif

csrc/grid.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,7 @@ TORCH_LIBRARY_IMPL(torch_cluster, CPU, m) {
4242
TORCH_LIBRARY_IMPL(torch_cluster, CUDA, m) {
4343
m.impl("grid", &grid_cuda);
4444
}
45+
TORCH_LIBRARY_IMPL(torch_cluster, HIP, m) {
46+
m.impl("grid", &grid_cuda);
47+
}
4548
#endif

csrc/knn.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,16 @@ TORCH_LIBRARY_IMPL(torch_cluster, CPU, m) {
5050
}
5151

5252
#ifdef WITH_CUDA
53-
TORCH_LIBRARY_IMPL(torch_cluster, CUDA, m) {
54-
m.impl("knn", &knn_cuda);
55-
}
53+
torch::Tensor knn_cuda_wrap(torch::Tensor x, torch::Tensor y,
54+
std::optional<torch::Tensor> ptr_x,
55+
std::optional<torch::Tensor> ptr_y, int64_t k, bool cosine,
56+
int64_t num_workers) {
57+
return knn_cuda(x, y, ptr_x, ptr_y, k, cosine);
58+
}
59+
TORCH_LIBRARY_IMPL(torch_cluster, CUDA, m) {
60+
m.impl("knn", &knn_cuda_wrap);
61+
}
62+
TORCH_LIBRARY_IMPL(torch_cluster, HIP, m) {
63+
m.impl("knn", &knn_cuda_wrap);
64+
}
5665
#endif

csrc/nearest.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,7 @@ CLUSTER_API torch::Tensor nearest(torch::Tensor x, torch::Tensor y, torch::Tenso
3737
TORCH_LIBRARY_IMPL(torch_cluster, CUDA, m) {
3838
m.impl("nearest", &nearest_cuda);
3939
}
40+
TORCH_LIBRARY_IMPL(torch_cluster, HIP, m) {
41+
m.impl("nearest", &nearest_cuda);
42+
}
4043
#endif

csrc/radius.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,7 @@ TORCH_LIBRARY_IMPL(torch_cluster, CPU, m) {
4444
TORCH_LIBRARY_IMPL(torch_cluster, CUDA, m) {
4545
m.impl("radius", &radius_cuda);
4646
}
47+
TORCH_LIBRARY_IMPL(torch_cluster, HIP, m) {
48+
m.impl("radius", &radius_cuda);
49+
}
4750
#endif

csrc/rw.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,8 @@ TORCH_LIBRARY_IMPL(torch_cluster, CPU, m) {
4242
TORCH_LIBRARY_IMPL(torch_cluster, CUDA, m) {
4343
m.impl("random_walk", &random_walk_cuda);
4444
}
45+
46+
TORCH_LIBRARY_IMPL(torch_cluster, HIP, m) {
47+
m.impl("random_walk", &random_walk_cuda);
48+
}
4549
#endif

csrc/version.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
#ifdef WITH_PYTHON
22
#include <Python.h>
33
#endif
4+
5+
#include <torch/library.h>
6+
47
#include "cluster.h"
58
#include "macros.h"
6-
#include <torch/torch.h>
7-
#include <torch/library.h>
89

910
#ifdef WITH_CUDA
1011
#ifdef USE_ROCM
@@ -38,6 +39,6 @@ CLUSTER_API int64_t cuda_version() noexcept {
3839
}
3940
} // namespace cluster
4041

41-
TORCH_LIBRARY_IMPL(torch_cluster, m) {
42+
TORCH_LIBRARY_IMPL(torch_cluster, CompositeImplicitAutograd, m) {
4243
m.impl("cuda_version", [] { return cluster::cuda_version(); });
4344
}

0 commit comments

Comments
 (0)