Unverified Commit c77ed131 authored by Gerico Vidanes's avatar Gerico Vidanes Committed by GitHub
Browse files

add capability to optionally include python during compile (#136)

parent 113e8a6a
...@@ -4,6 +4,7 @@ set(CMAKE_CXX_STANDARD 14) ...@@ -4,6 +4,7 @@ set(CMAKE_CXX_STANDARD 14)
set(TORCHCLUSTER_VERSION 1.6.0) set(TORCHCLUSTER_VERSION 1.6.0)
option(WITH_CUDA "Enable CUDA support" OFF) option(WITH_CUDA "Enable CUDA support" OFF)
option(WITH_PYTHON "Link to Python when building" ON)
if(WITH_CUDA) if(WITH_CUDA)
enable_language(CUDA) enable_language(CUDA)
...@@ -12,7 +13,10 @@ if(WITH_CUDA) ...@@ -12,7 +13,10 @@ if(WITH_CUDA)
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} --expt-relaxed-constexpr") set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} --expt-relaxed-constexpr")
endif() endif()
find_package(Python3 COMPONENTS Development) if (WITH_PYTHON)
add_definitions(-DWITH_PYTHON)
find_package(Python3 COMPONENTS Development)
endif()
find_package(Torch REQUIRED) find_package(Torch REQUIRED)
file(GLOB HEADERS csrc/*.h) file(GLOB HEADERS csrc/*.h)
...@@ -22,7 +26,10 @@ if(WITH_CUDA) ...@@ -22,7 +26,10 @@ if(WITH_CUDA)
endif() endif()
add_library(${PROJECT_NAME} SHARED ${OPERATOR_SOURCES}) add_library(${PROJECT_NAME} SHARED ${OPERATOR_SOURCES})
target_link_libraries(${PROJECT_NAME} PRIVATE ${TORCH_LIBRARIES} Python3::Python) target_link_libraries(${PROJECT_NAME} PRIVATE ${TORCH_LIBRARIES})
if (WITH_PYTHON)
target_link_libraries(${PROJECT_NAME} PRIVATE Python3::Python)
endif()
set_target_properties(${PROJECT_NAME} PROPERTIES EXPORT_NAME TorchCluster) set_target_properties(${PROJECT_NAME} PROPERTIES EXPORT_NAME TorchCluster)
target_include_directories(${PROJECT_NAME} INTERFACE target_include_directories(${PROJECT_NAME} INTERFACE
......
#pragma once #pragma once
#include <torch/extension.h> #include "extensions.h"
#include "macros.h"
namespace cluster { namespace cluster {
CLUSTER_API int64_t cuda_version() noexcept; CLUSTER_API int64_t cuda_version() noexcept;
......
#include "macros.h" #include "macros.h"
#include <torch/extension.h> #include <torch/torch.h>
#ifdef WITH_PYTHON
#include <Python.h> #include <Python.h>
#endif
#include <torch/script.h> #include <torch/script.h>
#include "cpu/fps_cpu.h" #include "cpu/fps_cpu.h"
...@@ -8,12 +10,14 @@ ...@@ -8,12 +10,14 @@
#endif #endif
#ifdef _WIN32 #ifdef _WIN32
#ifdef WITH_PYTHON
#ifdef WITH_CUDA #ifdef WITH_CUDA
PyMODINIT_FUNC PyInit__fps_cuda(void) { return NULL; } PyMODINIT_FUNC PyInit__fps_cuda(void) { return NULL; }
#else #else
PyMODINIT_FUNC PyInit__fps_cpu(void) { return NULL; } PyMODINIT_FUNC PyInit__fps_cpu(void) { return NULL; }
#endif #endif
#endif #endif
#endif
CLUSTER_API torch::Tensor fps(torch::Tensor src, torch::Tensor ptr, torch::Tensor ratio, CLUSTER_API torch::Tensor fps(torch::Tensor src, torch::Tensor ptr, torch::Tensor ratio,
bool random_start) { bool random_start) {
......
#ifdef WITH_PYTHON
#include <Python.h> #include <Python.h>
#endif
#include <torch/script.h> #include <torch/script.h>
#include "cpu/graclus_cpu.h" #include "cpu/graclus_cpu.h"
...@@ -8,12 +10,14 @@ ...@@ -8,12 +10,14 @@
#endif #endif
#ifdef _WIN32 #ifdef _WIN32
#ifdef WITH_PYTHON
#ifdef WITH_CUDA #ifdef WITH_CUDA
PyMODINIT_FUNC PyInit__graclus_cuda(void) { return NULL; } PyMODINIT_FUNC PyInit__graclus_cuda(void) { return NULL; }
#else #else
PyMODINIT_FUNC PyInit__graclus_cpu(void) { return NULL; } PyMODINIT_FUNC PyInit__graclus_cpu(void) { return NULL; }
#endif #endif
#endif #endif
#endif
CLUSTER_API torch::Tensor graclus(torch::Tensor rowptr, torch::Tensor col, CLUSTER_API torch::Tensor graclus(torch::Tensor rowptr, torch::Tensor col,
torch::optional<torch::Tensor> optional_weight) { torch::optional<torch::Tensor> optional_weight) {
......
#ifdef WITH_PYTHON
#include <Python.h> #include <Python.h>
#endif
#include <torch/script.h> #include <torch/script.h>
#include "cpu/grid_cpu.h" #include "cpu/grid_cpu.h"
...@@ -8,12 +10,14 @@ ...@@ -8,12 +10,14 @@
#endif #endif
#ifdef _WIN32 #ifdef _WIN32
#ifdef WITH_PYTHON
#ifdef WITH_CUDA #ifdef WITH_CUDA
PyMODINIT_FUNC PyInit__grid_cuda(void) { return NULL; } PyMODINIT_FUNC PyInit__grid_cuda(void) { return NULL; }
#else #else
PyMODINIT_FUNC PyInit__grid_cpu(void) { return NULL; } PyMODINIT_FUNC PyInit__grid_cpu(void) { return NULL; }
#endif #endif
#endif #endif
#endif
CLUSTER_API torch::Tensor grid(torch::Tensor pos, torch::Tensor size, CLUSTER_API torch::Tensor grid(torch::Tensor pos, torch::Tensor size,
torch::optional<torch::Tensor> optional_start, torch::optional<torch::Tensor> optional_start,
......
#ifdef WITH_PYTHON
#include <Python.h> #include <Python.h>
#endif
#include <torch/script.h> #include <torch/script.h>
#include "cpu/knn_cpu.h" #include "cpu/knn_cpu.h"
...@@ -8,12 +10,14 @@ ...@@ -8,12 +10,14 @@
#endif #endif
#ifdef _WIN32 #ifdef _WIN32
#ifdef WITH_PYTHON
#ifdef WITH_CUDA #ifdef WITH_CUDA
PyMODINIT_FUNC PyInit__knn_cuda(void) { return NULL; } PyMODINIT_FUNC PyInit__knn_cuda(void) { return NULL; }
#else #else
PyMODINIT_FUNC PyInit__knn_cpu(void) { return NULL; } PyMODINIT_FUNC PyInit__knn_cpu(void) { return NULL; }
#endif #endif
#endif #endif
#endif
CLUSTER_API torch::Tensor knn(torch::Tensor x, torch::Tensor y, CLUSTER_API torch::Tensor knn(torch::Tensor x, torch::Tensor y,
torch::optional<torch::Tensor> ptr_x, torch::optional<torch::Tensor> ptr_x,
......
#ifdef WITH_PYTHON
#include <Python.h> #include <Python.h>
#endif
#include <torch/script.h> #include <torch/script.h>
#include "extensions.h" #include "extensions.h"
...@@ -8,12 +10,14 @@ ...@@ -8,12 +10,14 @@
#endif #endif
#ifdef _WIN32 #ifdef _WIN32
#ifdef WITH_PYTHON
#ifdef WITH_CUDA #ifdef WITH_CUDA
PyMODINIT_FUNC PyInit__nearest_cuda(void) { return NULL; } PyMODINIT_FUNC PyInit__nearest_cuda(void) { return NULL; }
#else #else
PyMODINIT_FUNC PyInit__nearest_cpu(void) { return NULL; } PyMODINIT_FUNC PyInit__nearest_cpu(void) { return NULL; }
#endif #endif
#endif #endif
#endif
CLUSTER_API torch::Tensor nearest(torch::Tensor x, torch::Tensor y, torch::Tensor ptr_x, CLUSTER_API torch::Tensor nearest(torch::Tensor x, torch::Tensor y, torch::Tensor ptr_x,
torch::Tensor ptr_y) { torch::Tensor ptr_y) {
......
#ifdef WITH_PYTHON
#include <Python.h> #include <Python.h>
#endif
#include <torch/script.h> #include <torch/script.h>
#include "cpu/radius_cpu.h" #include "cpu/radius_cpu.h"
...@@ -8,12 +10,14 @@ ...@@ -8,12 +10,14 @@
#endif #endif
#ifdef _WIN32 #ifdef _WIN32
#ifdef WITH_PYTHON
#ifdef WITH_CUDA #ifdef WITH_CUDA
PyMODINIT_FUNC PyInit__radius_cuda(void) { return NULL; } PyMODINIT_FUNC PyInit__radius_cuda(void) { return NULL; }
#else #else
PyMODINIT_FUNC PyInit__radius_cpu(void) { return NULL; } PyMODINIT_FUNC PyInit__radius_cpu(void) { return NULL; }
#endif #endif
#endif #endif
#endif
CLUSTER_API torch::Tensor radius(torch::Tensor x, torch::Tensor y, CLUSTER_API torch::Tensor radius(torch::Tensor x, torch::Tensor y,
torch::optional<torch::Tensor> ptr_x, torch::optional<torch::Tensor> ptr_x,
......
#ifdef WITH_PYTHON
#include <Python.h> #include <Python.h>
#endif
#include <torch/script.h> #include <torch/script.h>
#include "cpu/rw_cpu.h" #include "cpu/rw_cpu.h"
...@@ -8,12 +10,14 @@ ...@@ -8,12 +10,14 @@
#endif #endif
#ifdef _WIN32 #ifdef _WIN32
#ifdef WITH_PYTHON
#ifdef WITH_CUDA #ifdef WITH_CUDA
PyMODINIT_FUNC PyInit__rw_cuda(void) { return NULL; } PyMODINIT_FUNC PyInit__rw_cuda(void) { return NULL; }
#else #else
PyMODINIT_FUNC PyInit__rw_cpu(void) { return NULL; } PyMODINIT_FUNC PyInit__rw_cpu(void) { return NULL; }
#endif #endif
#endif #endif
#endif
CLUSTER_API std::tuple<torch::Tensor, torch::Tensor> CLUSTER_API std::tuple<torch::Tensor, torch::Tensor>
random_walk(torch::Tensor rowptr, torch::Tensor col, torch::Tensor start, random_walk(torch::Tensor rowptr, torch::Tensor col, torch::Tensor start,
......
#ifdef WITH_PYTHON
#include <Python.h> #include <Python.h>
#endif
#include <torch/script.h> #include <torch/script.h>
#include "cpu/sampler_cpu.h" #include "cpu/sampler_cpu.h"
#ifdef _WIN32 #ifdef _WIN32
#ifdef WITH_PYTHON
#ifdef WITH_CUDA #ifdef WITH_CUDA
PyMODINIT_FUNC PyInit__sampler_cuda(void) { return NULL; } PyMODINIT_FUNC PyInit__sampler_cuda(void) { return NULL; }
#else #else
PyMODINIT_FUNC PyInit__sampler_cpu(void) { return NULL; } PyMODINIT_FUNC PyInit__sampler_cpu(void) { return NULL; }
#endif #endif
#endif #endif
#endif
CLUSTER_API torch::Tensor neighbor_sampler(torch::Tensor start, torch::Tensor rowptr, CLUSTER_API torch::Tensor neighbor_sampler(torch::Tensor start, torch::Tensor rowptr,
int64_t count, double factor) { int64_t count, double factor) {
......
#ifdef WITH_PYTHON
#include <Python.h> #include <Python.h>
#endif
#include <torch/script.h> #include <torch/script.h>
#include "cluster.h" #include "cluster.h"
#include "macros.h" #include "macros.h"
...@@ -8,12 +10,14 @@ ...@@ -8,12 +10,14 @@
#endif #endif
#ifdef _WIN32 #ifdef _WIN32
#ifdef WITH_PYTHON
#ifdef WITH_CUDA #ifdef WITH_CUDA
PyMODINIT_FUNC PyInit__version_cuda(void) { return NULL; } PyMODINIT_FUNC PyInit__version_cuda(void) { return NULL; }
#else #else
PyMODINIT_FUNC PyInit__version_cpu(void) { return NULL; } PyMODINIT_FUNC PyInit__version_cpu(void) { return NULL; }
#endif #endif
#endif #endif
#endif
namespace cluster { namespace cluster {
......
...@@ -33,7 +33,7 @@ def get_extensions(): ...@@ -33,7 +33,7 @@ def get_extensions():
main_files = glob.glob(osp.join(extensions_dir, '*.cpp')) main_files = glob.glob(osp.join(extensions_dir, '*.cpp'))
for main, suffix in product(main_files, suffices): for main, suffix in product(main_files, suffices):
define_macros = [] define_macros = [('WITH_PYTHON', None)]
if sys.platform == 'win32': if sys.platform == 'win32':
define_macros += [('torchcluster_EXPORTS', None)] define_macros += [('torchcluster_EXPORTS', None)]
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment