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

Export symbols for Windows DLL and MSVC build compatibility (#294)



* Mark exported symbols with SCATTER_API so they are available in the DLL on Windows

* macro definition for python package installation

* move macros definitions to separate file

* unlink?

* update

* linting
Co-authored-by: default avatarMatthias Fey <matthias.fey@tu-dortmund.de>
parent 06321b59
#pragma once
#ifdef _WIN32
#if defined(torchscatter_EXPORTS)
#define SCATTER_API __declspec(dllexport)
#else
#define SCATTER_API __declspec(dllimport)
#endif
#else
#define SCATTER_API
#endif
#if (defined __cpp_inline_variables) || __cplusplus >= 201703L
#define SCATTER_INLINE_VARIABLE inline
#else
#ifdef _MSC_VER
#define SCATTER_INLINE_VARIABLE __declspec(selectany)
#else
#define SCATTER_INLINE_VARIABLE __attribute__((weak))
#endif
#endif
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#include <torch/script.h> #include <torch/script.h>
#include "cpu/scatter_cpu.h" #include "cpu/scatter_cpu.h"
#include "macros.h"
#include "utils.h" #include "utils.h"
#ifdef WITH_CUDA #ifdef WITH_CUDA
...@@ -226,9 +227,10 @@ public: ...@@ -226,9 +227,10 @@ public:
} }
}; };
torch::Tensor scatter_sum(torch::Tensor src, torch::Tensor index, int64_t dim, SCATTER_API torch::Tensor
torch::optional<torch::Tensor> optional_out, scatter_sum(torch::Tensor src, torch::Tensor index, int64_t dim,
torch::optional<int64_t> dim_size) { torch::optional<torch::Tensor> optional_out,
torch::optional<int64_t> dim_size) {
return ScatterSum::apply(src, index, dim, optional_out, dim_size)[0]; return ScatterSum::apply(src, index, dim, optional_out, dim_size)[0];
} }
...@@ -238,13 +240,14 @@ torch::Tensor scatter_mul(torch::Tensor src, torch::Tensor index, int64_t dim, ...@@ -238,13 +240,14 @@ torch::Tensor scatter_mul(torch::Tensor src, torch::Tensor index, int64_t dim,
return ScatterMul::apply(src, index, dim, optional_out, dim_size)[0]; return ScatterMul::apply(src, index, dim, optional_out, dim_size)[0];
} }
torch::Tensor scatter_mean(torch::Tensor src, torch::Tensor index, int64_t dim, SCATTER_API torch::Tensor
torch::optional<torch::Tensor> optional_out, scatter_mean(torch::Tensor src, torch::Tensor index, int64_t dim,
torch::optional<int64_t> dim_size) { torch::optional<torch::Tensor> optional_out,
torch::optional<int64_t> dim_size) {
return ScatterMean::apply(src, index, dim, optional_out, dim_size)[0]; return ScatterMean::apply(src, index, dim, optional_out, dim_size)[0];
} }
std::tuple<torch::Tensor, torch::Tensor> SCATTER_API std::tuple<torch::Tensor, torch::Tensor>
scatter_min(torch::Tensor src, torch::Tensor index, int64_t dim, scatter_min(torch::Tensor src, torch::Tensor index, int64_t dim,
torch::optional<torch::Tensor> optional_out, torch::optional<torch::Tensor> optional_out,
torch::optional<int64_t> dim_size) { torch::optional<int64_t> dim_size) {
...@@ -252,7 +255,7 @@ scatter_min(torch::Tensor src, torch::Tensor index, int64_t dim, ...@@ -252,7 +255,7 @@ scatter_min(torch::Tensor src, torch::Tensor index, int64_t dim,
return std::make_tuple(result[0], result[1]); return std::make_tuple(result[0], result[1]);
} }
std::tuple<torch::Tensor, torch::Tensor> SCATTER_API std::tuple<torch::Tensor, torch::Tensor>
scatter_max(torch::Tensor src, torch::Tensor index, int64_t dim, scatter_max(torch::Tensor src, torch::Tensor index, int64_t dim,
torch::optional<torch::Tensor> optional_out, torch::optional<torch::Tensor> optional_out,
torch::optional<int64_t> dim_size) { torch::optional<int64_t> dim_size) {
......
...@@ -2,76 +2,76 @@ ...@@ -2,76 +2,76 @@
#include <torch/extension.h> #include <torch/extension.h>
#if (defined __cpp_inline_variables) || __cplusplus >= 201703L #include "macros.h"
#define SCATTER_INLINE_VARIABLE inline
#else
#ifdef _MSC_VER
#define SCATTER_INLINE_VARIABLE __declspec(selectany)
#else
#define SCATTER_INLINE_VARIABLE __attribute__((weak))
#endif
#endif
namespace scatter { namespace scatter {
int64_t cuda_version() noexcept; SCATTER_API int64_t cuda_version() noexcept;
namespace detail { namespace detail {
SCATTER_INLINE_VARIABLE int64_t _cuda_version = cuda_version(); SCATTER_INLINE_VARIABLE int64_t _cuda_version = cuda_version();
} // namespace detail } // namespace detail
} // namespace scatter } // namespace scatter
torch::Tensor scatter_sum(torch::Tensor src, torch::Tensor index, int64_t dim, SCATTER_API torch::Tensor
torch::optional<torch::Tensor> optional_out, scatter_sum(torch::Tensor src, torch::Tensor index, int64_t dim,
torch::optional<int64_t> dim_size); torch::optional<torch::Tensor> optional_out,
torch::optional<int64_t> dim_size);
torch::Tensor scatter_mean(torch::Tensor src, torch::Tensor index, int64_t dim, SCATTER_API torch::Tensor
torch::optional<torch::Tensor> optional_out, scatter_mean(torch::Tensor src, torch::Tensor index, int64_t dim,
torch::optional<int64_t> dim_size); torch::optional<torch::Tensor> optional_out,
torch::optional<int64_t> dim_size);
std::tuple<torch::Tensor, torch::Tensor> SCATTER_API std::tuple<torch::Tensor, torch::Tensor>
scatter_min(torch::Tensor src, torch::Tensor index, int64_t dim, scatter_min(torch::Tensor src, torch::Tensor index, int64_t dim,
torch::optional<torch::Tensor> optional_out, torch::optional<torch::Tensor> optional_out,
torch::optional<int64_t> dim_size); torch::optional<int64_t> dim_size);
std::tuple<torch::Tensor, torch::Tensor> SCATTER_API std::tuple<torch::Tensor, torch::Tensor>
scatter_max(torch::Tensor src, torch::Tensor index, int64_t dim, scatter_max(torch::Tensor src, torch::Tensor index, int64_t dim,
torch::optional<torch::Tensor> optional_out, torch::optional<torch::Tensor> optional_out,
torch::optional<int64_t> dim_size); torch::optional<int64_t> dim_size);
torch::Tensor segment_sum_coo(torch::Tensor src, torch::Tensor index, SCATTER_API torch::Tensor
torch::optional<torch::Tensor> optional_out, segment_sum_coo(torch::Tensor src, torch::Tensor index,
torch::optional<int64_t> dim_size); torch::optional<torch::Tensor> optional_out,
torch::optional<int64_t> dim_size);
torch::Tensor segment_mean_coo(torch::Tensor src, torch::Tensor index, SCATTER_API torch::Tensor
torch::optional<torch::Tensor> optional_out, segment_mean_coo(torch::Tensor src, torch::Tensor index,
torch::optional<int64_t> dim_size); torch::optional<torch::Tensor> optional_out,
torch::optional<int64_t> dim_size);
std::tuple<torch::Tensor, torch::Tensor> SCATTER_API std::tuple<torch::Tensor, torch::Tensor>
segment_min_coo(torch::Tensor src, torch::Tensor index, segment_min_coo(torch::Tensor src, torch::Tensor index,
torch::optional<torch::Tensor> optional_out, torch::optional<torch::Tensor> optional_out,
torch::optional<int64_t> dim_size); torch::optional<int64_t> dim_size);
std::tuple<torch::Tensor, torch::Tensor> SCATTER_API std::tuple<torch::Tensor, torch::Tensor>
segment_max_coo(torch::Tensor src, torch::Tensor index, segment_max_coo(torch::Tensor src, torch::Tensor index,
torch::optional<torch::Tensor> optional_out, torch::optional<torch::Tensor> optional_out,
torch::optional<int64_t> dim_size); torch::optional<int64_t> dim_size);
torch::Tensor gather_coo(torch::Tensor src, torch::Tensor index, SCATTER_API torch::Tensor
torch::optional<torch::Tensor> optional_out); gather_coo(torch::Tensor src, torch::Tensor index,
torch::optional<torch::Tensor> optional_out);
torch::Tensor segment_sum_csr(torch::Tensor src, torch::Tensor indptr, SCATTER_API torch::Tensor
torch::optional<torch::Tensor> optional_out); segment_sum_csr(torch::Tensor src, torch::Tensor indptr,
torch::optional<torch::Tensor> optional_out);
torch::Tensor segment_mean_csr(torch::Tensor src, torch::Tensor indptr, SCATTER_API torch::Tensor
torch::optional<torch::Tensor> optional_out); segment_mean_csr(torch::Tensor src, torch::Tensor indptr,
torch::optional<torch::Tensor> optional_out);
std::tuple<torch::Tensor, torch::Tensor> SCATTER_API std::tuple<torch::Tensor, torch::Tensor>
segment_min_csr(torch::Tensor src, torch::Tensor indptr, segment_min_csr(torch::Tensor src, torch::Tensor indptr,
torch::optional<torch::Tensor> optional_out); torch::optional<torch::Tensor> optional_out);
std::tuple<torch::Tensor, torch::Tensor> SCATTER_API std::tuple<torch::Tensor, torch::Tensor>
segment_max_csr(torch::Tensor src, torch::Tensor indptr, segment_max_csr(torch::Tensor src, torch::Tensor indptr,
torch::optional<torch::Tensor> optional_out); torch::optional<torch::Tensor> optional_out);
torch::Tensor gather_csr(torch::Tensor src, torch::Tensor indptr, SCATTER_API torch::Tensor
torch::optional<torch::Tensor> optional_out); gather_csr(torch::Tensor src, torch::Tensor indptr,
torch::optional<torch::Tensor> optional_out);
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#include <torch/script.h> #include <torch/script.h>
#include "cpu/segment_coo_cpu.h" #include "cpu/segment_coo_cpu.h"
#include "macros.h"
#include "utils.h" #include "utils.h"
#ifdef WITH_CUDA #ifdef WITH_CUDA
...@@ -195,19 +196,21 @@ public: ...@@ -195,19 +196,21 @@ public:
} }
}; };
torch::Tensor segment_sum_coo(torch::Tensor src, torch::Tensor index, SCATTER_API torch::Tensor
torch::optional<torch::Tensor> optional_out, segment_sum_coo(torch::Tensor src, torch::Tensor index,
torch::optional<int64_t> dim_size) { torch::optional<torch::Tensor> optional_out,
torch::optional<int64_t> dim_size) {
return SegmentSumCOO::apply(src, index, optional_out, dim_size)[0]; return SegmentSumCOO::apply(src, index, optional_out, dim_size)[0];
} }
torch::Tensor segment_mean_coo(torch::Tensor src, torch::Tensor index, SCATTER_API torch::Tensor
torch::optional<torch::Tensor> optional_out, segment_mean_coo(torch::Tensor src, torch::Tensor index,
torch::optional<int64_t> dim_size) { torch::optional<torch::Tensor> optional_out,
torch::optional<int64_t> dim_size) {
return SegmentMeanCOO::apply(src, index, optional_out, dim_size)[0]; return SegmentMeanCOO::apply(src, index, optional_out, dim_size)[0];
} }
std::tuple<torch::Tensor, torch::Tensor> SCATTER_API std::tuple<torch::Tensor, torch::Tensor>
segment_min_coo(torch::Tensor src, torch::Tensor index, segment_min_coo(torch::Tensor src, torch::Tensor index,
torch::optional<torch::Tensor> optional_out, torch::optional<torch::Tensor> optional_out,
torch::optional<int64_t> dim_size) { torch::optional<int64_t> dim_size) {
...@@ -215,7 +218,7 @@ segment_min_coo(torch::Tensor src, torch::Tensor index, ...@@ -215,7 +218,7 @@ segment_min_coo(torch::Tensor src, torch::Tensor index,
return std::make_tuple(result[0], result[1]); return std::make_tuple(result[0], result[1]);
} }
std::tuple<torch::Tensor, torch::Tensor> SCATTER_API std::tuple<torch::Tensor, torch::Tensor>
segment_max_coo(torch::Tensor src, torch::Tensor index, segment_max_coo(torch::Tensor src, torch::Tensor index,
torch::optional<torch::Tensor> optional_out, torch::optional<torch::Tensor> optional_out,
torch::optional<int64_t> dim_size) { torch::optional<int64_t> dim_size) {
...@@ -223,8 +226,9 @@ segment_max_coo(torch::Tensor src, torch::Tensor index, ...@@ -223,8 +226,9 @@ segment_max_coo(torch::Tensor src, torch::Tensor index,
return std::make_tuple(result[0], result[1]); return std::make_tuple(result[0], result[1]);
} }
torch::Tensor gather_coo(torch::Tensor src, torch::Tensor index, SCATTER_API torch::Tensor
torch::optional<torch::Tensor> optional_out) { gather_coo(torch::Tensor src, torch::Tensor index,
torch::optional<torch::Tensor> optional_out) {
return GatherCOO::apply(src, index, optional_out)[0]; return GatherCOO::apply(src, index, optional_out)[0];
} }
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#include <torch/script.h> #include <torch/script.h>
#include "cpu/segment_csr_cpu.h" #include "cpu/segment_csr_cpu.h"
#include "macros.h"
#include "utils.h" #include "utils.h"
#ifdef WITH_CUDA #ifdef WITH_CUDA
...@@ -192,32 +193,35 @@ public: ...@@ -192,32 +193,35 @@ public:
} }
}; };
torch::Tensor segment_sum_csr(torch::Tensor src, torch::Tensor indptr, SCATTER_API torch::Tensor
torch::optional<torch::Tensor> optional_out) { segment_sum_csr(torch::Tensor src, torch::Tensor indptr,
torch::optional<torch::Tensor> optional_out) {
return SegmentSumCSR::apply(src, indptr, optional_out)[0]; return SegmentSumCSR::apply(src, indptr, optional_out)[0];
} }
torch::Tensor segment_mean_csr(torch::Tensor src, torch::Tensor indptr, SCATTER_API torch::Tensor
torch::optional<torch::Tensor> optional_out) { segment_mean_csr(torch::Tensor src, torch::Tensor indptr,
torch::optional<torch::Tensor> optional_out) {
return SegmentMeanCSR::apply(src, indptr, optional_out)[0]; return SegmentMeanCSR::apply(src, indptr, optional_out)[0];
} }
std::tuple<torch::Tensor, torch::Tensor> SCATTER_API std::tuple<torch::Tensor, torch::Tensor>
segment_min_csr(torch::Tensor src, torch::Tensor indptr, segment_min_csr(torch::Tensor src, torch::Tensor indptr,
torch::optional<torch::Tensor> optional_out) { torch::optional<torch::Tensor> optional_out) {
auto result = SegmentMinCSR::apply(src, indptr, optional_out); auto result = SegmentMinCSR::apply(src, indptr, optional_out);
return std::make_tuple(result[0], result[1]); return std::make_tuple(result[0], result[1]);
} }
std::tuple<torch::Tensor, torch::Tensor> SCATTER_API std::tuple<torch::Tensor, torch::Tensor>
segment_max_csr(torch::Tensor src, torch::Tensor indptr, segment_max_csr(torch::Tensor src, torch::Tensor indptr,
torch::optional<torch::Tensor> optional_out) { torch::optional<torch::Tensor> optional_out) {
auto result = SegmentMaxCSR::apply(src, indptr, optional_out); auto result = SegmentMaxCSR::apply(src, indptr, optional_out);
return std::make_tuple(result[0], result[1]); return std::make_tuple(result[0], result[1]);
} }
torch::Tensor gather_csr(torch::Tensor src, torch::Tensor indptr, SCATTER_API torch::Tensor
torch::optional<torch::Tensor> optional_out) { gather_csr(torch::Tensor src, torch::Tensor indptr,
torch::optional<torch::Tensor> optional_out) {
return GatherCSR::apply(src, indptr, optional_out)[0]; return GatherCSR::apply(src, indptr, optional_out)[0];
} }
......
#include <Python.h> #include <Python.h>
#include <torch/script.h> #include <torch/script.h>
#include "scatter.h"
#include "macros.h"
#ifdef WITH_CUDA #ifdef WITH_CUDA
#include <cuda.h> #include <cuda.h>
...@@ -14,7 +16,7 @@ PyMODINIT_FUNC PyInit__version_cpu(void) { return NULL; } ...@@ -14,7 +16,7 @@ PyMODINIT_FUNC PyInit__version_cpu(void) { return NULL; }
#endif #endif
namespace scatter { namespace scatter {
int64_t cuda_version() noexcept { SCATTER_API int64_t cuda_version() noexcept {
#ifdef WITH_CUDA #ifdef WITH_CUDA
return CUDA_VERSION; return CUDA_VERSION;
#else #else
......
...@@ -35,6 +35,10 @@ def get_extensions(): ...@@ -35,6 +35,10 @@ def get_extensions():
for main, suffix in product(main_files, suffices): for main, suffix in product(main_files, suffices):
define_macros = [] define_macros = []
if sys.platform == 'win32':
define_macros += [('torchscatter_EXPORTS', None)]
extra_compile_args = {'cxx': ['-O2']} extra_compile_args = {'cxx': ['-O2']}
if not os.name == 'nt': # Not on Windows: if not os.name == 'nt': # Not on Windows:
extra_compile_args['cxx'] += ['-Wno-sign-compare'] extra_compile_args['cxx'] += ['-Wno-sign-compare']
......
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