Skip to content

Commit c77ed13

Browse files
authored
add capability to optionally include python during compile (#136)
1 parent 113e8a6 commit c77ed13

File tree

13 files changed

+48
-7
lines changed

13 files changed

+48
-7
lines changed

CMakeLists.txt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ set(CMAKE_CXX_STANDARD 14)
44
set(TORCHCLUSTER_VERSION 1.6.0)
55

66
option(WITH_CUDA "Enable CUDA support" OFF)
7+
option(WITH_PYTHON "Link to Python when building" ON)
78

89
if(WITH_CUDA)
910
enable_language(CUDA)
@@ -12,7 +13,10 @@ if(WITH_CUDA)
1213
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} --expt-relaxed-constexpr")
1314
endif()
1415

15-
find_package(Python3 COMPONENTS Development)
16+
if (WITH_PYTHON)
17+
add_definitions(-DWITH_PYTHON)
18+
find_package(Python3 COMPONENTS Development)
19+
endif()
1620
find_package(Torch REQUIRED)
1721

1822
file(GLOB HEADERS csrc/*.h)
@@ -22,7 +26,10 @@ if(WITH_CUDA)
2226
endif()
2327

2428
add_library(${PROJECT_NAME} SHARED ${OPERATOR_SOURCES})
25-
target_link_libraries(${PROJECT_NAME} PRIVATE ${TORCH_LIBRARIES} Python3::Python)
29+
target_link_libraries(${PROJECT_NAME} PRIVATE ${TORCH_LIBRARIES})
30+
if (WITH_PYTHON)
31+
target_link_libraries(${PROJECT_NAME} PRIVATE Python3::Python)
32+
endif()
2633
set_target_properties(${PROJECT_NAME} PROPERTIES EXPORT_NAME TorchCluster)
2734

2835
target_include_directories(${PROJECT_NAME} INTERFACE

csrc/cluster.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#pragma once
22

3-
#include <torch/extension.h>
4-
5-
#include "macros.h"
3+
#include "extensions.h"
64

75
namespace cluster {
86
CLUSTER_API int64_t cuda_version() noexcept;

csrc/extensions.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
#include "macros.h"
2-
#include <torch/extension.h>
2+
#include <torch/torch.h>

csrc/fps.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
#ifdef WITH_PYTHON
12
#include <Python.h>
3+
#endif
24
#include <torch/script.h>
35

46
#include "cpu/fps_cpu.h"
@@ -8,12 +10,14 @@
810
#endif
911

1012
#ifdef _WIN32
13+
#ifdef WITH_PYTHON
1114
#ifdef WITH_CUDA
1215
PyMODINIT_FUNC PyInit__fps_cuda(void) { return NULL; }
1316
#else
1417
PyMODINIT_FUNC PyInit__fps_cpu(void) { return NULL; }
1518
#endif
1619
#endif
20+
#endif
1721

1822
CLUSTER_API torch::Tensor fps(torch::Tensor src, torch::Tensor ptr, torch::Tensor ratio,
1923
bool random_start) {

csrc/graclus.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
#ifdef WITH_PYTHON
12
#include <Python.h>
3+
#endif
24
#include <torch/script.h>
35

46
#include "cpu/graclus_cpu.h"
@@ -8,12 +10,14 @@
810
#endif
911

1012
#ifdef _WIN32
13+
#ifdef WITH_PYTHON
1114
#ifdef WITH_CUDA
1215
PyMODINIT_FUNC PyInit__graclus_cuda(void) { return NULL; }
1316
#else
1417
PyMODINIT_FUNC PyInit__graclus_cpu(void) { return NULL; }
1518
#endif
1619
#endif
20+
#endif
1721

1822
CLUSTER_API torch::Tensor graclus(torch::Tensor rowptr, torch::Tensor col,
1923
torch::optional<torch::Tensor> optional_weight) {

csrc/grid.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
#ifdef WITH_PYTHON
12
#include <Python.h>
3+
#endif
24
#include <torch/script.h>
35

46
#include "cpu/grid_cpu.h"
@@ -8,12 +10,14 @@
810
#endif
911

1012
#ifdef _WIN32
13+
#ifdef WITH_PYTHON
1114
#ifdef WITH_CUDA
1215
PyMODINIT_FUNC PyInit__grid_cuda(void) { return NULL; }
1316
#else
1417
PyMODINIT_FUNC PyInit__grid_cpu(void) { return NULL; }
1518
#endif
1619
#endif
20+
#endif
1721

1822
CLUSTER_API torch::Tensor grid(torch::Tensor pos, torch::Tensor size,
1923
torch::optional<torch::Tensor> optional_start,

csrc/knn.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
#ifdef WITH_PYTHON
12
#include <Python.h>
3+
#endif
24
#include <torch/script.h>
35

46
#include "cpu/knn_cpu.h"
@@ -8,12 +10,14 @@
810
#endif
911

1012
#ifdef _WIN32
13+
#ifdef WITH_PYTHON
1114
#ifdef WITH_CUDA
1215
PyMODINIT_FUNC PyInit__knn_cuda(void) { return NULL; }
1316
#else
1417
PyMODINIT_FUNC PyInit__knn_cpu(void) { return NULL; }
1518
#endif
1619
#endif
20+
#endif
1721

1822
CLUSTER_API torch::Tensor knn(torch::Tensor x, torch::Tensor y,
1923
torch::optional<torch::Tensor> ptr_x,

csrc/nearest.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
#ifdef WITH_PYTHON
12
#include <Python.h>
3+
#endif
24
#include <torch/script.h>
35

46
#include "extensions.h"
@@ -8,12 +10,14 @@
810
#endif
911

1012
#ifdef _WIN32
13+
#ifdef WITH_PYTHON
1114
#ifdef WITH_CUDA
1215
PyMODINIT_FUNC PyInit__nearest_cuda(void) { return NULL; }
1316
#else
1417
PyMODINIT_FUNC PyInit__nearest_cpu(void) { return NULL; }
1518
#endif
1619
#endif
20+
#endif
1721

1822
CLUSTER_API torch::Tensor nearest(torch::Tensor x, torch::Tensor y, torch::Tensor ptr_x,
1923
torch::Tensor ptr_y) {

csrc/radius.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
#ifdef WITH_PYTHON
12
#include <Python.h>
3+
#endif
24
#include <torch/script.h>
35

46
#include "cpu/radius_cpu.h"
@@ -8,12 +10,14 @@
810
#endif
911

1012
#ifdef _WIN32
13+
#ifdef WITH_PYTHON
1114
#ifdef WITH_CUDA
1215
PyMODINIT_FUNC PyInit__radius_cuda(void) { return NULL; }
1316
#else
1417
PyMODINIT_FUNC PyInit__radius_cpu(void) { return NULL; }
1518
#endif
1619
#endif
20+
#endif
1721

1822
CLUSTER_API torch::Tensor radius(torch::Tensor x, torch::Tensor y,
1923
torch::optional<torch::Tensor> ptr_x,

csrc/rw.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
#ifdef WITH_PYTHON
12
#include <Python.h>
3+
#endif
24
#include <torch/script.h>
35

46
#include "cpu/rw_cpu.h"
@@ -8,12 +10,14 @@
810
#endif
911

1012
#ifdef _WIN32
13+
#ifdef WITH_PYTHON
1114
#ifdef WITH_CUDA
1215
PyMODINIT_FUNC PyInit__rw_cuda(void) { return NULL; }
1316
#else
1417
PyMODINIT_FUNC PyInit__rw_cpu(void) { return NULL; }
1518
#endif
1619
#endif
20+
#endif
1721

1822
CLUSTER_API std::tuple<torch::Tensor, torch::Tensor>
1923
random_walk(torch::Tensor rowptr, torch::Tensor col, torch::Tensor start,

0 commit comments

Comments
 (0)