File tree Expand file tree Collapse file tree 3 files changed +25
-9
lines changed Expand file tree Collapse file tree 3 files changed +25
-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 consisting of this file
11+ in this extension, so that the TORCH_LIBRARY static initializers
12+ below are run. */
13+ PyObject* PyInit__C (void )
14+ {
15+ static struct PyModuleDef module_def = {
16+ PyModuleDef_HEAD_INIT,
17+ " _C" , /* name of module */
18+ NULL , /* module documentation, may be NULL */
19+ -1 , /* size of per-interpreter state of the module,
20+ or -1 if the module keeps state in global variables. */
21+ NULL , /* methods */
22+ };
23+ return PyModule_Create (&module_def);
24+ }
25+ }
26+
527namespace extension_cpp {
628
729at::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" , # min CPython version 3.9
4142 ],
4243 "nvcc" : [
4344 "-O3" if not debug_mode else "-O0" ,
You can’t perform that action at this time.
0 commit comments