main
h 27 lines 1.08 KB
Raw
1 #pragma once
2
3 #include <Python.h>
4
5 #define _CONCAT(A, B) A##B
6 #define CONCAT(A, B) _CONCAT(A, B)
7
8 #define _STRINGIFY(A) #A
9 #define STRINGIFY(A) _STRINGIFY(A)
10
11 // A version of the TORCH_LIBRARY macro that expands the NAME, i.e. so NAME
12 // could be a macro instead of a literal token.
13 #define TORCH_LIBRARY_EXPAND(NAME, MODULE) TORCH_LIBRARY(NAME, MODULE)
14
15 // A version of the TORCH_LIBRARY_IMPL macro that expands the NAME, i.e. so NAME
16 // could be a macro instead of a literal token.
17 #define TORCH_LIBRARY_IMPL_EXPAND(NAME, DEVICE, MODULE) \
18 TORCH_LIBRARY_IMPL(NAME, DEVICE, MODULE)
19
20 // REGISTER_EXTENSION allows the shared library to be loaded and initialized
21 // via python's import statement.
22 #define REGISTER_EXTENSION(NAME) \
23 PyMODINIT_FUNC CONCAT(PyInit_, NAME)() { \
24 static struct PyModuleDef module = {PyModuleDef_HEAD_INIT, \
25 STRINGIFY(NAME), nullptr, 0, nullptr}; \
26 return PyModule_Create(&module); \
27 }