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 11import torch
22from 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>
25
36#include < vector>
47
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+
526namespace extension_cpp {
627
728at::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():
3838 "cxx" : [
3939 "-O3" if not debug_mode else "-O0" ,
4040 "-fdiagnostics-color=always" ,
41+ "-DPy_LIMITED_API=0x03090000" ,
4142 ],
4243 "nvcc" : [
4344 "-O3" if not debug_mode else "-O0" ,
You can’t perform that action at this time.
0 commit comments