Skip to content

Commit

Permalink
polish code
Browse files Browse the repository at this point in the history
  • Loading branch information
Aurelius84 committed Sep 6, 2021
1 parent a3beefe commit 09db77b
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions python/paddle/utils/cpp_extension/cpp_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,8 @@ def __init__(self, *args, **kwargs):
super(BuildExtension, self).__init__(*args, **kwargs)
self.no_python_abi_suffix = kwargs.get("no_python_abi_suffix", True)
self.output_dir = kwargs.get("output_dir", None)
# whether containing cuda source file in Extensions
self.contain_cuda_file = False

def initialize_options(self):
super(BuildExtension, self).initialize_options()
Expand Down Expand Up @@ -432,8 +434,8 @@ def unix_custom_single_compiler(obj, src, ext, cc_args, extra_postargs,
# shared library have same ABI suffix with core_(no)avx.so.
# See https://stackoverflow.com/questions/34571583/understanding-gcc-5s-glibcxx-use-cxx11-abi-or-the-new-abi
add_compile_flag(['-D_GLIBCXX_USE_CXX11_ABI=1'], cflags)

if not is_cuda_file(src):
# Append this macor only when jointly compiling .cc with .cu
if not is_cuda_file(src) and self.contain_cuda_file:
cflags.append('-DPADDLE_WITH_CUDA')

add_std_without_repeat(
Expand Down Expand Up @@ -509,6 +511,9 @@ def win_custom_spawn(cmd):
elif isinstance(self.cflags, list):
cflags = MSVC_COMPILE_FLAGS + self.cflags
cmd += cflags
# Append this macor only when jointly compiling .cc with .cu
if not is_cuda_file(src) and self.contain_cuda_file:
cmd.append('-DPADDLE_WITH_CUDA')

return original_spawn(cmd)

Expand Down Expand Up @@ -636,6 +641,8 @@ def _record_op_info(self):

for i, extension in enumerate(self.extensions):
sources = [os.path.abspath(s) for s in extension.sources]
if not self.contain_cuda_file:
self.contain_cuda_file = any([is_cuda_file(s) for s in sources])
op_names = parse_op_name_from(sources)

for op_name in op_names:
Expand Down

1 comment on commit 09db77b

@paddle-bot-old
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Congratulation! Your pull request passed all required CI. You could ask reviewer(s) to approve and merge. 🎉

Please sign in to comment.