Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example of possible makefile for mlpack examples #75

Merged
merged 18 commits into from
May 3, 2020

Conversation

shrit
Copy link
Member

@shrit shrit commented Apr 7, 2020

Signed-off-by: Omar Shrit shrit@lri.fr

@shrit
Copy link
Member Author

shrit commented Apr 7, 2020

@rcurtin I think this is a possible example for a Makefile. I only made it for one example, if it is good, I will copy it everywhere with minor modifications.

@birm
Copy link
Member

birm commented Apr 8, 2020

Maybe we could add this makefile to our CI tests.

@zoq
Copy link
Member

zoq commented Apr 8, 2020

Do we want to keep the current folder structure or do we want to put everything in the root directory? Depending on the decision, I think a single Makefile as all we need?

@shrit
Copy link
Member Author

shrit commented Apr 8, 2020

@zoq I would prefer to have separate Makefile by example. This will reduce the compilation time, and will be much easier to manage and debug. This is only a prototype if you find it well I will only copy it for all examples.

@zoq
Copy link
Member

zoq commented Apr 8, 2020

Maybe we can make it work for other examples? Like point users to this makefile and we make sure it works across all examples, and a user could call make example-name and that's it?

@shrit
Copy link
Member Author

shrit commented Apr 8, 2020

@zoq I agree, that is a good point, this will reduce non-useful duplication of Makefiles. Let us have @rcurtin opinion on this?

@rcurtin
Copy link
Member

rcurtin commented Apr 9, 2020

@shrit thanks for writing this up! I think I would agree that we should have one Makefile in each directory. My impression is that a user will come along and look at an individual directory, not at the whole project. But it seems like it would be easy to have the best of both worlds... just have a top-level Makefile call out recursively to all the subdirectories?

This is a really generic Makefile, which is nice because we could just drop it in other directories, but it might be a little hard to understand for people not too familiar with the (really weird!) Makefile language. In some sense even the Makefile itself is an example, so I'd hope to keep it as simple as we can. But I'm not sure exactly where the right level is. The configurable parameters at the top are really nice, but maybe we can hardcode the sources and compilation commands, so we get something like this?

all: mnist_simple

# Probably best to keep the non-optional parts of linking hard-coded in the command?
# Maybe good to add $(INCLFLAGS) containing any -I directories in case mlpack is not installed but only built locally?
mnist_simple:
    # If you're not using the Armadillo wrapper, replace `-larmadillo` with linker commands for the
    # BLAS and LAPACK libraries that you are using.
    $(CXX) -o mnist_simple mnist_simple.cpp $(CXXFLAGS) $(LDFLAGS) -lmlpack -larmadillo -lboost_serialization

clean:
    @rm mnist_simple

Might be good to put a disclaimer at the top or something, too, that says "you might need to modify this to get it to work on your system, but it should work in most places", or something like that. It's just an example after all, not meant to build in every possible place. 😄

Anyway, let me know what you think, these are just my opinions. We could go with something else if desired.

@shrit
Copy link
Member Author

shrit commented Apr 11, 2020

I agree, one makefile by example seems to be a good idea, with a recursive call for the entire project.
I have made it generic because I do not want users to touch the Target and OBJS. They can change only source files, and add libraries if they want to add new dependencies. I will try to remove some redundant stuff and see what we can get.

Copy link
Member

@rcurtin rcurtin left a comment

Choose a reason for hiding this comment

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

Hey @shrit, looks good! Thanks for simplifying. I left a couple comments about the experiences I had while trying to use it; let me know what you think. Personally I think this looks good overall; want to deploy it to the other directories too? 👍

mnist_simple/Makefile Outdated Show resolved Hide resolved
mnist_simple/Makefile Outdated Show resolved Hide resolved
mnist_simple/Makefile Outdated Show resolved Hide resolved
default: all

$(TARGET): $(OBJS)
$(CXX) $(CXXFLAGS) $(INCLFLAGS) $(LIBS) $(LDFLAGS) $(OBJS) -o $(TARGET)
Copy link
Member

Choose a reason for hiding this comment

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

To make this work right on my system (I have to specify -L/home/ryan/src/mlpack/build/lib/ in LDFLAGS and -I/home/ryan/src/mlpack/build/include/ -I/home/ryan/src/mlpack/build/deps/ensmallen-2.11.5/include/ in INCLFLAGS), I had to move $(OBJS) -o $(TARGET) to the beginning of the command:

$(TARGET): $(OBJS)
        $(CXX) $(CXXFLAGS) $(OBJS) -o $(TARGET) $(INCLFLAGS) $(LDFLAGS) $(LIBS)

@shrit
Copy link
Member Author

shrit commented Apr 27, 2020

I think it is ready to be deployed on other examples.

# LDFLAGS := -L/path/to/mlpack/library/ # if installed locally
INCLFLAGS := -I . #Add header directories for any includes that aren't on the default compiler search path.

OBJS := $(SRC:.cpp=.o)
Copy link
Member

Choose a reason for hiding this comment

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

Maybe do we need to specify a separate rule for the .cpp -> .o compilation? The .cpps are being compiled without the INCLFLAGS or CXXFLAGS:

$ head -18 Makefile 
# This is a simple Makefile used to build the example source code.
# This example might requires some modifications in order to work correctly on
# your system.
# If you're not using the Armadillo wrapper, replace `armadillo` with linker commands
# for the BLAS and LAPACK libraries that you are using.

TARGET := mnist_simple
SRC := mnist_simple.cpp
LIBS_NAME := armadillo mlpack boost_serialization

CXX := g++
CXXFLAGS := -std=c++11 -Wall -Wextra -O3 -DNDEBUG
# Use these CXXFLAGS instead if you want to compile with debugging symbols and without optimizations.
# CXXFLAGS := -std=c++11 -Wall -Wextra -g -O0
LDFLAGS  := -fopenmp
LDFLAGS := -L/home/ryan/src/mlpack/build/lib/    # if installed locally
INCLFLAGS := -I/home/ryan/src/mlpack/build/include/ -I/home/ryan/src/mlpack/build/deps/ensmallen-2.11.5/include/ #Add header directories for any includes that aren't on the default compiler search path.

$ make
g++ -std=c++11 -Wall -Wextra -O3 -DNDEBUG   -c -o mnist_simple.o mnist_simple.cpp
mnist_simple.cpp:16:10: fatal error: mlpack/core.hpp: No such file or directory
   16 | #include <mlpack/core.hpp>
      |          ^~~~~~~~~~~~~~~~~
compilation terminated.
make: *** [<builtin>: mnist_simple.o] Error 1

@shrit
Copy link
Member Author

shrit commented Apr 28, 2020

@rcurtin This one seems to be working, I kept one rule. If it seems good to you, I will deploy these modifications on other examples

@rcurtin
Copy link
Member

rcurtin commented Apr 29, 2020

Nice, that seems to work. It seems also like you could use += instead and CXXFLAGS everywhere? Here's a slightly modified version that might be cleaner:

CXX := g++
CXXFLAGS += -std=c++11 -Wall -Wextra -O3 -DNDEBUG -fopenmp
# Use these CXXFLAGS instead if you want to compile with debugging symbols and without optimizations.
# CXXFLAGS += -std=c++11 -Wall -Wextra -g -O0

LDFLAGS := -fopenmp -L/home/ryan/src/mlpack/build/lib/    # if installed locally
INCLFLAGS := -I/home/ryan/src/mlpack/build/include/ -I/home/ryan/src/mlpack/build/deps/ensmallen-2.11.5/include/ #Add header directories for any includes that aren't on the default compiler search path.

CXXFLAGS += $(INCLFLAGS)

(Of course, you would want to include the default INCLFLAGS and LDFLAGS that you have already.)

I think that using += everywhere could mean that I could set some CXXFLAGS in my environment and have those propagate to the Makefile, which is nice:

$ CXXFLAGS="-fail" make
g++ -fail -std=c++11 -Wall -Wextra -O3 -DNDEBUG -fopenmp -I/home/ryan/src/mlpack/build/include/ -I/home/ryan/src/mlpack/build/deps/ensmallen-2.11.5/include/    -c -o mnist_simple.o mnist_simple.cpp
g++: error: unrecognized command line option ‘-fail’; did you mean ‘-fnil’?
make: *** [<builtin>: mnist_simple.o] Error 1

Anyway, up to you what you want to do. Overall it looks great to me---want to apply that the changes to all the other Makefiles? I think this PR is ready once you do that. 👍

shrit and others added 10 commits April 29, 2020 11:40
Signed-off-by: Omar Shrit <shrit@lri.fr>
Signed-off-by: Omar Shrit <shrit@lri.fr>
Co-Authored-By: Ryan Curtin <ryan@ratml.org>
Co-Authored-By: Ryan Curtin <ryan@ratml.org>
Signed-off-by: Omar Shrit <shrit@lri.fr>
Signed-off-by: Omar Shrit <shrit@lri.fr>
Signed-off-by: Omar Shrit <shrit@lri.fr>
Signed-off-by: Omar Shrit <shrit@lri.fr>
Signed-off-by: Omar Shrit <shrit@lri.fr>
Signed-off-by: Omar Shrit <shrit@lri.fr>
Signed-off-by: Omar Shrit <shrit@lri.fr>
Signed-off-by: Omar Shrit <shrit@lri.fr>
Signed-off-by: Omar Shrit <shrit@lri.fr>
Signed-off-by: Omar Shrit <shrit@lri.fr>
@shrit
Copy link
Member Author

shrit commented Apr 30, 2020

@rcurtin I think we can merge it now,

Copy link
Member

@rcurtin rcurtin left a comment

Choose a reason for hiding this comment

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

Awesome, thanks @shrit! It looks good to me and works on my setup. My last super minor comment: maybe it's better to use += for the LDFLAGS too? Up to you if you want to make the change.

Signed-off-by: Omar Shrit <shrit@lri.fr>
@@ -0,0 +1,36 @@
# This is a simple Makefile used to build the example source code.
# This example might requires some modifications in order to work correctly on
Copy link
Member

Choose a reason for hiding this comment

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

I think we are using the same style guidelines here as for the mlpack repo, so maybe we should adjust the line length here; see https://github.com/mlpack/mlpack/wiki/DesignGuidelines#line-length-and-wrapping for more details.

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed, I need to apply this on all files

lstm_electricity_consumption/Makefile Outdated Show resolved Hide resolved
lstm_electricity_consumption/Makefile Outdated Show resolved Hide resolved
@@ -0,0 +1,36 @@
# This is a simple Makefile used to build the example source code.
Copy link
Member

Choose a reason for hiding this comment

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

Wondering if we should print a similar message in the build step, not sure the first thing a user will do is to look into the Makefile for more information. Let me know what you think.

Copy link
Member Author

Choose a reason for hiding this comment

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

I am not sure, If any system supports posix and have gcc installed, the user should not have any issue with this makefiles. The only possible modifications are setting LD_FLAGS and INCLUDES if required

Copy link
Member

Choose a reason for hiding this comment

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

I guess if there are issues we will see them, so fine with me to go with the current version.

shrit and others added 2 commits May 2, 2020 00:21
Co-authored-by: Marcus Edel <marcus.edel@fu-berlin.de>
Co-authored-by: Marcus Edel <marcus.edel@fu-berlin.de>
Copy link

@mlpack-bot mlpack-bot bot left a comment

Choose a reason for hiding this comment

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

Second approval provided automatically after 24 hours. 👍

Signed-off-by: Omar Shrit <shrit@lri.fr>
@shrit
Copy link
Member Author

shrit commented May 3, 2020

@rcurtin we can merge now

Copy link
Member

@zoq zoq left a comment

Choose a reason for hiding this comment

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

Thanks for putting everything together!

@rcurtin
Copy link
Member

rcurtin commented May 3, 2020

Thanks @shrit! 👍

@rcurtin rcurtin merged commit 97d2707 into mlpack:master May 3, 2020
@shrit shrit deleted the makefiles branch May 3, 2020 22:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants