Skip to content

Conversation

@shrit
Copy link
Member

@shrit shrit commented Nov 16, 2024

This PR explains how to crosscompile an mlpack example by analysing the template cmake file we have provided in the examples repository.

@shrit shrit requested a review from rcurtin November 16, 2024 13:41
bindings such as kNN command line program on a Raspberry PI 2. Please refer to that
article first and follow the first part on how to setup cross-compilation toolchain,
and then continue with this article. Or refer to this
[table](supported_boards.md) for a quick start guide.
Copy link
Member

Choose a reason for hiding this comment

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

So just to be clear, it seems like this example is focused on using CMake to set up a project that will do embedded cross-compilation?

Copy link
Member Author

Choose a reason for hiding this comment

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

yes indeed, this is the main idea, because you need a guide if you have your own code

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.

I started reviewing this and adding more suggestions; of course I think it is a great idea to add an example like this. But as I got further into it, I wondered if this is actually the way people will use mlpack inside of a CMake project. I can definitely see that users will fall into one of two camps:

  • They'll either want a fully-working example that they can adapt; or
  • they'll want some kind of Findmlpack.cmake file (which has been requested in various issues, I haven't dug one up) that they can include, and optionally they may want to use the autodownloader too, for convenience

In either case, I think it's important that the CMake file is as simple as possible. So I think we need to start with the Findmlpack.cmake file, and we can put a lot of the logic that searches for mlpack's dependencies in there. Then, the random forest example can be structured like this:

  • define the project and C++ standard and whatever else
  • use the autodownloader to download the dependencies of mlpack
  • call find_package(mlpack) with the locations of all mlpack's dependencies set (and point out that if you don't want to autodownload/compile OpenBLAS, you can just comment all that out)
  • define the actual example compilation

What do you think? I know it will be a bit of an overhaul, but I want to make sure that when people come to use mlpack in their CMake projects that it feels as natural as possible. Happy to help with the Findmlpack.cmake file.

@@ -0,0 +1,194 @@
## Crosscompile mlpack example for an embedded hardware
Copy link
Member

Choose a reason for hiding this comment

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

Just some general thoughts:

  • Once Overhaul documentation homepage #3836 is merged, we should add this to the SVGs, but I'm not 100% sure how. Maybe for now it could be a line in the "Deployment" section, but eventually we'll need to split out and create a landing page for our embedded deployment tutorials.

  • Renaming this to something like "Cross-compiling mlpack in a CMake project" might be more accurate?

  • Up to you, but we could even just make it "Using mlpack in a CMake project", and then keep the stuff specific to cross-compilation at the end.

@shrit
Copy link
Member Author

shrit commented Dec 5, 2024

We can have Findmlpack.cmake, but the problem is that it is not usable in the cross compilation steps.
If you want to have it independently, sure, we can create another tutorial for using cmake and mlpack in a normal project. However, when it comes to cross compilation, I would prefer to use the auto downloader on mlpack to avoid any confusion with the system /usr/includes.
For instance, it will be very hard to make Findmlpack.cmake be sure that it is not in /usr/include or /usr/local/include and if Findmlpack.cmake return true when doing cross compilation, we have a high chance that the entire compilation will fail.
Findmlpack.cmake is a nice addition to make it simple for users. I myself would go into the direction of simplifying the entire process. Users only need the headers and they only thing that matters to them to have them in the target_include_directories. They can point them out by themselves or use Findmlpack.cmake. However, this should be avoided in the case of crosscompilation

@rcurtin
Copy link
Member

rcurtin commented Dec 5, 2024

With all CMake find_package() scripts, you can specify directories to be searched. So you can, say, autodownload Armadillo and compile OpenBLAS, then set ARMADILLO_INCLUDE_DIR before calling find_package(Armadillo) and wherever you downloaded it will be searched first. The same with mlpack, cereal, ensmallen, whatever. So a Findmlpack.cmake script doesn't rule out using the autodownloader---it's just a convenience to find all the dependencies in whatever search path was specified. Setting cross-compilation options is something that's orthogonal to finding the dependencies.

@shrit shrit mentioned this pull request Jan 9, 2025
@shrit shrit closed this Jan 10, 2025
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.

2 participants