Skip to content

Commit bede18b

Browse files
malfetfacebook-github-bot
authored andcommitted
Add support for C++ frontend wrapper on Linux (pytorch#69094)
Summary: Pull Request resolved: pytorch#69094 Partially addresses pytorch#68768 Test Plan: Imported from OSS Reviewed By: seemethere Differential Revision: D32730079 Pulled By: malfet fbshipit-source-id: 854e4215ff66e087bdf354fed7a17e87f2649c87
1 parent 33c3c53 commit bede18b

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

test/test_utils.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -864,5 +864,13 @@ def test_external_module_register(self):
864864
torch._register_device_module('xpu', DummyXPUModule)
865865

866866

867+
class TestCppExtensionUtils(TestCase):
868+
def test_cpp_compiler_is_ok(self):
869+
self.assertTrue(torch.utils.cpp_extension.check_compiler_ok_for_platform('c++'))
870+
871+
def test_cc_compiler_is_ok(self):
872+
self.assertTrue(torch.utils.cpp_extension.check_compiler_ok_for_platform('cc'))
873+
874+
867875
if __name__ == '__main__':
868876
run_tests()

torch/utils/cpp_extension.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,15 +260,18 @@ def check_compiler_ok_for_platform(compiler: str) -> bool:
260260
# Check the compiler name
261261
if any(name in compiler_path for name in _accepted_compilers_for_platform()):
262262
return True
263-
# If ccache is used the compiler path is /usr/bin/ccache. Check by -v flag.
263+
# If compiler wrapper is used try to infer the actual compiler by invoking it with -v flag
264264
version_string = subprocess.check_output([compiler, '-v'], stderr=subprocess.STDOUT).decode(*SUBPROCESS_DECODE_ARGS)
265265
if IS_LINUX:
266-
# Check for 'gcc' or 'g++'
266+
# Check for 'gcc' or 'g++' for sccache warpper
267267
pattern = re.compile("^COLLECT_GCC=(.*)$", re.MULTILINE)
268268
results = re.findall(pattern, version_string)
269269
if len(results) != 1:
270270
return False
271271
compiler_path = os.path.realpath(results[0].strip())
272+
# On RHEL/CentOS c++ is a gcc compiler wrapper
273+
if os.path.basename(compiler_path) == 'c++' and 'gcc version' in version_string:
274+
return True
272275
return any(name in compiler_path for name in _accepted_compilers_for_platform())
273276
if IS_MACOS:
274277
# Check for 'clang' or 'clang++'

0 commit comments

Comments
 (0)