Skip to content

Commit a864dbb

Browse files
malfetfacebook-github-bot
authored andcommitted
Make _C extension a thin C wrapper (pytorch#39375)
Summary: It just depends on a single `torch_python` library. C library does not depend on standard C++ library and as result it closes pytorch#36941 Pull Request resolved: pytorch#39375 Reviewed By: orionr Differential Revision: D21840645 Pulled By: malfet fbshipit-source-id: 777c189feee9d6fc686816d92cb9f109b8aac7ca
1 parent 09bea13 commit a864dbb

File tree

5 files changed

+24
-21
lines changed

5 files changed

+24
-21
lines changed

BUILD.bazel

+1-1
Original file line numberDiff line numberDiff line change
@@ -1961,7 +1961,7 @@ cc_library(
19611961

19621962
pybind_extension(
19631963
name = "_C",
1964-
srcs = ["torch/csrc/stub.cpp"],
1964+
srcs = ["torch/csrc/stub.c"],
19651965
deps = [
19661966
":torch_python"
19671967
],

setup.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,6 @@ def configure_extension_build():
579579
else:
580580
extra_link_args = []
581581
extra_compile_args = [
582-
'-std=c++14',
583582
'-Wall',
584583
'-Wextra',
585584
'-Wno-strict-overflow',
@@ -604,9 +603,9 @@ def configure_extension_build():
604603
library_dirs.append(lib_path)
605604

606605
main_compile_args = []
607-
main_libraries = ['shm', 'torch_python']
606+
main_libraries = ['torch_python']
608607
main_link_args = []
609-
main_sources = ["torch/csrc/stub.cpp"]
608+
main_sources = ["torch/csrc/stub.c"]
610609

611610
if cmake_cache_vars['USE_CUDA']:
612611
library_dirs.append(
@@ -647,7 +646,7 @@ def make_relative_rpath(path):
647646
C = Extension("torch._C",
648647
libraries=main_libraries,
649648
sources=main_sources,
650-
language='c++',
649+
language='c',
651650
extra_compile_args=main_compile_args + extra_compile_args,
652651
include_dirs=[],
653652
library_dirs=library_dirs,
@@ -661,7 +660,7 @@ def make_relative_rpath(path):
661660
extensions.append(DL)
662661

663662
# These extensions are built by cmake and copied manually in build_extensions()
664-
# inside the build_ext implementaiton
663+
# inside the build_ext implementation
665664
extensions.append(
666665
Extension(
667666
name=str('caffe2.python.caffe2_pybind11_state'),

torch/csrc/Module.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,7 @@ static void LogAPIUsageOnceFromPython(const std::string& event) {
621621
}
622622
}
623623

624+
extern "C"
624625
#ifdef _WIN32
625626
__declspec(dllexport)
626627
#endif

torch/csrc/stub.c

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#include <Python.h>
2+
3+
#ifdef _WIN32
4+
__declspec(dllimport)
5+
#endif
6+
extern PyObject* initModule(void);
7+
8+
#ifndef _WIN32
9+
#ifdef __cplusplus
10+
extern "C"
11+
#endif
12+
__attribute__((visibility("default"))) PyObject* PyInit__C(void);
13+
#endif
14+
15+
PyMODINIT_FUNC PyInit__C(void)
16+
{
17+
return initModule();
18+
}

torch/csrc/stub.cpp

-15
This file was deleted.

0 commit comments

Comments
 (0)