Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions src/cpp.cc
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -3346,8 +3346,6 @@ void Printer::Cpp::pytorch_makefile(const Options &opts, const AST &ast) {
stream << "CXXFLAGS += -DMALLOC_BATCH" << endl;
stream << "endif" << endl << endl;
}
// pytorch C++ extension doesn't support C++17 yet
stream << "CXXFLAGS := $(CXXFLAGS) | sed 's/c++17/c++14/'" << endl;

stream << "compiler_args := $(CXXFLAGS) | sed -e 's/\\s/\", \"/g'" << endl;
stream << "LDFLAGS := $(LDFLAGS) | sed 's/-L\\//\\//g'" << endl;
Expand All @@ -3357,7 +3355,7 @@ void Printer::Cpp::pytorch_makefile(const Options &opts, const AST &ast) {
<< "sed -e 's/\\s/\", \"-Xlinker\", \"-rpath\", \"-Xlinker\", \"/g'"
<< endl;
stream << "library_dirs := $(LDFLAGS) | sed -e 's/\\s/\", \"/g'" << endl;
stream << "LDLIBS := $(LDLIBS) | sed 's/-l//g'" << endl;
stream << "LDLIBS := $(LDLIBS) | sed -E 's/(^|[[:space:]])-l/\\1/g'" << endl;
Copy link
Member

Choose a reason for hiding this comment

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

not sure if this is relevant here, but sed behaves differently in OSX and Linux
Can you also show an example of what sed should change here?
what does the | mean in the regex? why are you capturing multiple spaces?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The old sed would falsely remove all "-l" within a term for example:
"-l/usr/lib/x86_64-linux-gnu, -lsd" --> "/usr/lib/x86_64inux-gnu, sd" the "64-linux" turns into "64inux" which causes an error.

The new expression makes sure the "-l" is either at the start of a line (^) or (|) behind a space, line break or tab ( [[:SPACE:]] ). The "\1" is needed to keep the capture group that is detected within the "( )" and not fully replace it, otherwise the space between terms would be removed as well and 2 terms would falsely merge into one.

So finally the new expression correctly performs the following:
"-l/usr/lib/x86_64-linux-gnu, -lsd" --> "/usr/lib/x86_64-linux-gnu, sd"

For OSX the regex should do the same thing, at least i tested it on an OSX terminal as well.

stream << "libraries := $(LDLIBS) | sed -e 's/\\s/\", \"/g'" << endl;
stream << "CPPFLAGS := $(CPPFLAGS) | sed 's/-I\\//\\//g'" << endl;
stream << "include_dirs := $(CPPFLAGS) | sed -e 's/\\s/\", \"/g'"
Expand All @@ -3372,7 +3370,8 @@ void Printer::Cpp::pytorch_makefile(const Options &opts, const AST &ast) {
stream << "setup.py:" << endl;
stream << "\t@echo 'from setuptools import setup' > $@" << endl;
stream << "\t@echo -e 'from torch.utils.cpp_extension import "
<< "BuildExtension, CppExtension\\n' >> $@" << endl;
<< "BuildExtension, CppExtension, include_paths, library_paths\\n' >> $@" << endl;
stream << "\t@echo 'import torch' >> $@" << endl;
stream << "\t@echo -n 'compiler_args = [\"' >> $@" << endl;
stream << "\t@echo -n $(compiler_args) >> $@" << endl;
stream << "\t@echo -e '\"]\\n' >> $@" << endl;
Expand All @@ -3399,15 +3398,15 @@ void Printer::Cpp::pytorch_makefile(const Options &opts, const AST &ast) {
<< "[\"pytorch_interface.cc\", ' >> $@" << endl;
stream << "\t@echo '" << out_files << "],' >> $@" << endl;
stream << "\t@echo -e ' include_dirs = "
<< "include_dirs,' >> $@" << endl;
<< "include_dirs + include_paths(),' >> $@" << endl;
stream << "\t@echo -e ' extra_compile_args = "
<< "compiler_args,' >> $@" << endl;
stream << "\t@echo -e ' extra_link_args = "
<< "xlinker_args,' >> $@" << endl;
stream << "\t@echo -e ' libraries = "
<< "libraries,' >> $@" << endl;
stream << "\t@echo -e ' library_dirs = "
<< "library_dirs)\\n' >> $@" << endl;
<< "library_dirs + library_paths())\\n' >> $@" << endl;
stream << "\t@echo 'setup(name = \"" << opts.pytorch_module_mame
<< "\",' >> $@" << endl;
stream << "\t@echo ' version = \"0.0.1\",' >> $@" << endl;
Expand Down