Skip to content

Commit

Permalink
Make _C extension a thin C wrapper (#39422)
Browse files Browse the repository at this point in the history
Summary:
It just depends on a single `torch_python` library.
C library does not depend on standard C++ library and as result it closes #36941
This is a cherry-pick of #39375 into release/1.5 branch
  • Loading branch information
malfet committed Jun 3, 2020
1 parent 5d01f87 commit c5424a8
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
9 changes: 4 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,6 @@ def configure_extension_build():
else:
extra_link_args = []
extra_compile_args = [
'-std=c++14',
'-Wall',
'-Wextra',
'-Wno-strict-overflow',
Expand All @@ -616,9 +615,9 @@ def configure_extension_build():
library_dirs.append(lib_path)

main_compile_args = []
main_libraries = ['shm', 'torch_python']
main_libraries = ['torch_python']
main_link_args = []
main_sources = ["torch/csrc/stub.cpp"]
main_sources = ["torch/csrc/stub.c"]

if cmake_cache_vars['USE_CUDA']:
library_dirs.append(
Expand Down Expand Up @@ -659,7 +658,7 @@ def make_relative_rpath(path):
C = Extension("torch._C",
libraries=main_libraries,
sources=main_sources,
language='c++',
language='c',
extra_compile_args=main_compile_args + extra_compile_args,
include_dirs=[],
library_dirs=library_dirs,
Expand All @@ -673,7 +672,7 @@ def make_relative_rpath(path):
extensions.append(DL)

# These extensions are built by cmake and copied manually in build_extensions()
# inside the build_ext implementaiton
# inside the build_ext implementation
extensions.append(
Extension(
name=str('caffe2.python.caffe2_pybind11_state'),
Expand Down
1 change: 1 addition & 0 deletions torch/csrc/Module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,7 @@ static void LogAPIUsageOnceFromPython(const std::string& event) {
}
}

extern "C"
#ifdef _WIN32
__declspec(dllexport)
#endif
Expand Down
6 changes: 3 additions & 3 deletions torch/csrc/stub.cpp → torch/csrc/stub.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
#ifdef _WIN32
__declspec(dllimport)
#endif
extern PyObject* initModule();
extern PyObject* initModule(void);

#if PY_MAJOR_VERSION == 2
PyMODINIT_FUNC init_C()
PyMODINIT_FUNC init_C(void)
{
initModule();
}
#else
PyMODINIT_FUNC PyInit__C()
PyMODINIT_FUNC PyInit__C(void)
{
return initModule();
}
Expand Down

0 comments on commit c5424a8

Please sign in to comment.