File tree Expand file tree Collapse file tree 3 files changed +24
-9
lines changed Expand file tree Collapse file tree 3 files changed +24
-9
lines changed Original file line number Diff line number Diff line change 1
1
import torch
2
2
from pathlib import Path
3
-
4
- so_files = list (Path (__file__ ).parent .glob ("_C*.so" ))
5
- assert (
6
- len (so_files ) == 1
7
- ), f"Expected one _C*.so file, found { len (so_files )} "
8
- torch .ops .load_library (so_files [0 ])
9
-
10
- from . import ops
3
+ from . import _C , ops
Original file line number Diff line number Diff line change 1
- #include < torch/extension.h>
1
+ #include < Python.h>
2
+ #include < ATen/Operators.h>
3
+ #include < torch/all.h>
4
+ #include < torch/library.h>
2
5
3
6
#include < vector>
4
7
8
+ extern " C" {
9
+ /* Creates a dummy empty _C module that can be imported from Python.
10
+ The import from Python will load the .so associated with this extension
11
+ built from this file, so that all the TORCH_LIBRARY calls below are run.*/
12
+ PyObject* PyInit__C (void )
13
+ {
14
+ static struct PyModuleDef module_def = {
15
+ PyModuleDef_HEAD_INIT,
16
+ " _C" , /* name of module */
17
+ NULL , /* module documentation, may be NULL */
18
+ -1 , /* size of per-interpreter state of the module,
19
+ or -1 if the module keeps state in global variables. */
20
+ NULL , /* methods */
21
+ };
22
+ return PyModule_Create (&module_def);
23
+ }
24
+ }
25
+
5
26
namespace extension_cpp {
6
27
7
28
at::Tensor mymuladd_cpu (const at::Tensor& a, const at::Tensor& b, double c) {
Original file line number Diff line number Diff line change @@ -38,6 +38,7 @@ def get_extensions():
38
38
"cxx" : [
39
39
"-O3" if not debug_mode else "-O0" ,
40
40
"-fdiagnostics-color=always" ,
41
+ "-DPy_LIMITED_API=0x03090000" ,
41
42
],
42
43
"nvcc" : [
43
44
"-O3" if not debug_mode else "-O0" ,
You can’t perform that action at this time.
0 commit comments