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

mlpack Header only initiative #3091

Merged
merged 50 commits into from
Apr 17, 2022
Merged

mlpack Header only initiative #3091

merged 50 commits into from
Apr 17, 2022

Conversation

shrit
Copy link
Member

@shrit shrit commented Nov 13, 2021

This is a first attempt to move mlpack to a header-only, I am not managing to push anything further to this PR, I think we can merge this one first and then open another one for the rest.
This is only to make the reviewing process easier.

Signed-off-by: Omar Shrit <omar@shrit.me>
Signed-off-by: Omar Shrit <omar@shrit.me>
Signed-off-by: Omar Shrit <omar@shrit.me>
Signed-off-by: Omar Shrit <omar@shrit.me>
Signed-off-by: Omar Shrit <omar@shrit.me>
Signed-off-by: Omar Shrit <omar@shrit.me>
Signed-off-by: Omar Shrit <omar@shrit.me>
Signed-off-by: Omar Shrit <omar@shrit.me>
Signed-off-by: Omar Shrit <omar@shrit.me>
Signed-off-by: Omar Shrit <omar@shrit.me>
Signed-off-by: Omar Shrit <omar@shrit.me>
Signed-off-by: Omar Shrit <omar@shrit.me>
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.

(requesting changes just so mlpack-bot doesn't auto-approve and this gets accidentally merged before it's ready)

@shrit
Copy link
Member Author

shrit commented Nov 20, 2021

I will have to check for these compilation errors, since I do not remember having any on my machine

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

shrit commented Nov 20, 2021

@rcurtin, do you have an idea what is happening with the macOS builds?
The fix is simple, we only need to remove the math:: and declare that we are using the mlpack::math namespace.
However, I do not understand why the error is happening in the first place, this will require more refactoring everywhere, sure I can do that but I can not understand the reason, let me know if you have an idea about it.

@rcurtin
Copy link
Member

rcurtin commented Dec 1, 2021

@rcurtin, do you have an idea what is happening with the macOS builds? The fix is simple, we only need to remove the math:: and declare that we are using the mlpack::math namespace. However, I do not understand why the error is happening in the first place, this will require more refactoring everywhere, sure I can do that but I can not understand the reason, let me know if you have an idea about it.

Just to write what we figured out while digging into this together today, the issue appears to be caused by various using namespaces hidden in some header files throughout the codebase. I think if we fix those, the MacOS build should succeed... I hope! 😄

@shrit
Copy link
Member Author

shrit commented Jan 23, 2022

@rcurtin 👌
The patch works perfectly. It compiles without any issue locally, let us see if this passes on the CI
I am not going to add anything further for this PR, let us merge this one and then I will open another one for the remaining parts.
Whenever you have time one review should be fine.

@rcurtin
Copy link
Member

rcurtin commented Jan 24, 2022

Yeah, I have seen that, therefore I commented everything related to STB to check if it is compiling, and it was passing locally. The ideal solution is to find a header-only library that supports image loading, otherwise, it will become a nightmare to make STB header-only and in this case, we will have to ship our own modified STB with mlpack, which will add maintenance overhead
In fact, if we can find a header-only library for image loading this will simplify the code and remove a lot of #ifdef macros for finding STB, it will be like catch and it will update automatically with github action.
Also, I do not think the replacement will be that hard, maybe we need to rewrite 2 functions?

Which functions to rewrite? Maybe I can do that.

@shubham1206agra let's hold off on that one---I think that we can make STB work here. Maybe someday we can refactor our data loading utilities into a separate library.

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.

Nice, great to see this all builds! I only have a couple small cleanup comments, and then I agree, we should go ahead and merge it. 👍

src/mlpack/core/data/image_info_impl.hpp Outdated Show resolved Hide resolved
src/mlpack/core/data/image_info_impl.hpp Outdated Show resolved Hide resolved
@@ -1,5 +1,5 @@
/**
* @file core/data/save_image.cpp
* @file core/data/save_image.hpp
Copy link
Member

Choose a reason for hiding this comment

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

This comment still applies---do you think we can handle it before merge?

*/
inline void RandVector(arma::vec& v)
{
v.zeros();
Copy link
Member

Choose a reason for hiding this comment

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

Agreed, I think we can remove this line (I know it was not part of the purpose of your PR, but it's a cleanup we could do anyway).

@@ -95,7 +93,7 @@ void ExtractSplits(std::vector<std::pair<ElemType, size_t>>& splitVec,
const size_t minLeafSize)
{
// It's common sense, but we also use it in a check later.
Log::Assert(minLeafSize > 0);
mlpack::Log::Assert(minLeafSize > 0);
Copy link
Member

Choose a reason for hiding this comment

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

I am not sure, but I think that you can revert most of the changes to this file, since these functions are now in the mlpack::det namespace.

shrit and others added 3 commits January 24, 2022 19:51
Co-authored-by: Ryan Curtin <ryan@ratml.org>
Co-authored-by: Ryan Curtin <ryan@ratml.org>
Signed-off-by: Omar Shrit <omar@shrit.me>
src/mlpack/core/data/load_image_impl.hpp Outdated Show resolved Hide resolved
src/mlpack/core/data/save_image.hpp Outdated Show resolved Hide resolved
Signed-off-by: Omar Shrit <omar@shrit.me>
Signed-off-by: Omar Shrit <omar@shrit.me>
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.

Everything looks good to me here---I think if you handle the comments in dtree_impl.hpp then the build will succeed, and once the build succeeds then from my side everything seems good and I think we should merge it. 👍

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

shrit commented Feb 4, 2022

@rcurtin All tests are passing now, the main issue is the memory check

Signed-off-by: Omar Shrit <omar@shrit.me>
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, the check is looking good; hopefully the comments are helpful. 👍

CMake/TestForSTB.cmake Outdated Show resolved Hide resolved
CMake/TestForSTB.cmake Outdated Show resolved Hide resolved
CMake/stb/CMakeLists.txt Outdated Show resolved Hide resolved
CMake/stb/main.cpp Outdated Show resolved Hide resolved
CMake/stb/blib.hpp Outdated Show resolved Hide resolved
@rcurtin
Copy link
Member

rcurtin commented Apr 13, 2022

@shrit I spent some time today trying to debug the CMake checks, and after my debugging I put them together into two patches you could apply to this branch with git am:

https://gist.github.com/rcurtin/4e54a7163533045cf4297dd91ba03383
https://gist.github.com/rcurtin/4fddb8784868b8e2f70f6aa985f8ac79

I tested this CMake script on both working and non-working versions of STB, and got the expected output. Once you apply these, I guess we'll have to update the version of STB in the mlpack jenkins Dockerfile (but that's easy enough).

Take a look and let me know what you think. 👍

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

shrit commented Apr 16, 2022

@rcurtin Great. Thank you for the patch, much better than what I have done before.
We should merge this one now, nothing to add here.

@rcurtin
Copy link
Member

rcurtin commented Apr 16, 2022

@mlpack-jenkins test this please

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.

Everything seems fine to me now! It will be great to get this merged. It looks like the Go job is failing perhaps because gonum uploaded a failing version (I see the failure also in #3186).

Co-authored-by: Marcus Edel <marcus.edel@fu-berlin.de>
@shrit
Copy link
Member Author

shrit commented Apr 16, 2022

Yeah, the same for the python build.
I will merge it tomorrow morning.

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.

Looks good to me.

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

5 participants