From 9668811a2789d8be29c4942b71040c533732ccc5 Mon Sep 17 00:00:00 2001 From: rusty1s Date: Sun, 27 Mar 2022 09:03:42 +0000 Subject: [PATCH 1/2] cuda version impl --- pyg_lib/csrc/macros.h | 22 ++++++++++++++++++++++ pyg_lib/csrc/pyg.cpp | 34 ++++++++++++++++++++++++++++++++++ pyg_lib/csrc/pyg.h | 17 +++++++++++++++++ 3 files changed, 73 insertions(+) create mode 100644 pyg_lib/csrc/macros.h create mode 100644 pyg_lib/csrc/pyg.cpp create mode 100644 pyg_lib/csrc/pyg.h diff --git a/pyg_lib/csrc/macros.h b/pyg_lib/csrc/macros.h new file mode 100644 index 000000000..8dc013ad1 --- /dev/null +++ b/pyg_lib/csrc/macros.h @@ -0,0 +1,22 @@ +#pragma once + +#ifdef _WIN32 +#if defined(pyg_lib_EXPORTS) +#define PYG_API __declspec(dllexport) +#else +#define PYG_API __declspec(dllimport) +#endif +#else +#define PYG_API +#endif + +#if (defined __cpp_inline_variables) || __cplusplus >= 201703L +#define PYG_INLINE_VARIABLE inline +#else +#ifdef _MSC_VER +#define PYG_INLINE_VARIABLE __declspec(selectany) +#define HINT_MSVC_LINKER_INCLUDE_SYMBOL +#else +#define PYG_INLINE_VARIABLE __attribute__((weak)) +#endif +#endif diff --git a/pyg_lib/csrc/pyg.cpp b/pyg_lib/csrc/pyg.cpp new file mode 100644 index 000000000..7b8f8304a --- /dev/null +++ b/pyg_lib/csrc/pyg.cpp @@ -0,0 +1,34 @@ +#include "pyg.h" + +#ifdef USE_PYTHON +#include +#endif + +#ifdef WITH_CUDA +#include +#endif + +#include + +// If we are in a Windows environment, we need to define +// initialization functions for the _custom_ops extension. +// For PyMODINIT_FUNC to work, we need to include Python.h +#ifdef _WIN32 +#ifdef USE_PYTHON +PyMODINIT_FUNC PyInit__C(void) { return NULL; } +#endif // USE_PYTHON +#endif // _WIN32 + +namespace pyg { + +int64_t cuda_version() { +#ifdef WITH_CUDA + return CUDA_VERSION; +#else + return -1; +#endif +} + +TORCH_LIBRARY_FRAGMENT(pyg, m) { m.def("cuda_version", &cuda_version); } + +} // namespace pyg diff --git a/pyg_lib/csrc/pyg.h b/pyg_lib/csrc/pyg.h new file mode 100644 index 000000000..3012184e4 --- /dev/null +++ b/pyg_lib/csrc/pyg.h @@ -0,0 +1,17 @@ +#pragma once + +#include "macros.h" + +namespace pyg { + +PYG_API int64_t cuda_version(); + +namespace detail { + +extern "C" PYG_INLINE_VARIABLE auto _register_ops = &cuda_version; +#ifdef HINT_MSVC_LINKER_INCLUDE_SYMBOL +#pragma comment(linker, "/include:_register_ops") +#endif + +} // namespace detail +} // namespace pyg From d1115154c26cf33d5d37210ad927dd6ba52524c8 Mon Sep 17 00:00:00 2001 From: rusty1s Date: Sun, 27 Mar 2022 09:05:54 +0000 Subject: [PATCH 2/2] rename --- pyg_lib/csrc/{pyg.cpp => library.cpp} | 2 +- pyg_lib/csrc/{pyg.h => library.h} | 0 pyg_lib/csrc/macros.h | 2 +- 3 files changed, 2 insertions(+), 2 deletions(-) rename pyg_lib/csrc/{pyg.cpp => library.cpp} (96%) rename pyg_lib/csrc/{pyg.h => library.h} (100%) diff --git a/pyg_lib/csrc/pyg.cpp b/pyg_lib/csrc/library.cpp similarity index 96% rename from pyg_lib/csrc/pyg.cpp rename to pyg_lib/csrc/library.cpp index 7b8f8304a..ecd136071 100644 --- a/pyg_lib/csrc/pyg.cpp +++ b/pyg_lib/csrc/library.cpp @@ -1,4 +1,4 @@ -#include "pyg.h" +#include "library.h" #ifdef USE_PYTHON #include diff --git a/pyg_lib/csrc/pyg.h b/pyg_lib/csrc/library.h similarity index 100% rename from pyg_lib/csrc/pyg.h rename to pyg_lib/csrc/library.h diff --git a/pyg_lib/csrc/macros.h b/pyg_lib/csrc/macros.h index 8dc013ad1..63db86133 100644 --- a/pyg_lib/csrc/macros.h +++ b/pyg_lib/csrc/macros.h @@ -1,7 +1,7 @@ #pragma once #ifdef _WIN32 -#if defined(pyg_lib_EXPORTS) +#if defined(pyg_EXPORTS) #define PYG_API __declspec(dllexport) #else #define PYG_API __declspec(dllimport)