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

[hannk] Add support for building/running for wasm #6361

Merged
merged 5 commits into from
Nov 1, 2021

Conversation

steven-johnson
Copy link
Contributor

Adds limited support for building and running hannk under WebAssembly. (Note that this requires #6360 to land first.)

Requirements:

  • You must use CMake to build (Make isn't supported).
  • You must have Emscripten v2.0.32 (or later) installed and activated.
  • You must have Node.js v16.13 (or later) installed for testing. Note that (as of this writing), EMSDK includes an older version of Node that will not work.

Caveats: this uses some seriously janky tricks for cross-compiling (all in apps/hannk/halide/CMakeLists.txt); the basic idea is that when crosscompiling, we re-run CMake on the subdirectory, but with an attempt to revert to the default host tooling (rather than what Emscripten has put in place), then set up dependencies to build and run the Generators that way, and then re-connect the generated libraries in the enclosing CMake file.

This works for me locally, and may be acceptable for an app of this sort. (Whether it is robust enough for "real" apps is not clear.) As usual, @alexreinking, I welcome your cmake-fu to let me know whether this is liable to break immediately and/or could be improved. (If this approach actually seems reasonable, it might be good to find a way to generalize it to allow easier wasm builds of other apps...)

I'm going to go ahead and request a review for this, but it may well need more attention before landing.

Preparatory work for allowing building of hannk with Emscripten; TFLite (and its dependees) problematic to build in that environment, but this will allow us to build a tflite-parser-only environment.

(Note that more work is needed to get this working for wasm, as crosscompiling in CMake is still pretty painful; this work was split out to make subsequent reviews simpler)
Base automatically changed from srj/hannk-no-tflite to master October 28, 2021 21:14
@alexreinking
Copy link
Member

alexreinking commented Oct 28, 2021

Caveats: this uses some seriously janky tricks for cross-compiling

Cross-compiling in CMake is always a train-wreck... do you mind if I push some changes to this branch to clean up the CMake? I can also do it as a PR-to-PR if you prefer.

@steven-johnson
Copy link
Contributor Author

do you mind if I push some changes to this branch

Nah, please, go right ahead :-)

* Ignore local emsdk clone

* Fix usage of CMAKE_BUILD_TYPE

* Only print the Halide target info once per CMake run

* Fix Halide "cmake" target detection for Emscripten

* Prefer target_link_options to _link_libraries when applicable

* Validate, rather than find, NODE_JS_EXECUTABLE (set by emsdk)

* Emscripten already wraps tests with node.

* Add dependency on Android logging library.

* For cross-compiling, find host tools instead of recursive call.

Rather than shelling out via execute_process and potentially
guessing the toolchain options wrong, expect to find our host
tools (i.e. generators) in a package called "hannk_tools".

The package is created by the host build via the CMake export()
command. Importing this package in the cross build creates
IMPORTED targets with the same names as our generators. We then
use these generators rather than creating generators for the
target build.

* Rework cross-compiling script.

* Respond to (easy) reviewer comments.

* Add HANNK_AOT_HOST_ONLY option. Use in script.

* [hannk] tests should only process .tflite files (#6368)

currently, random dotfiles (e.g. .DS_Store on OSX) can creep in, causing bogus failures

* Add comment about node wrapping.

* Rename hannk_tools to hannk-halide_generators

* Add comment about exporting targets.

* Bump version to Halide 14.0.0 (#6369)

Co-authored-by: Steven Johnson <srj@google.com>
@steven-johnson
Copy link
Contributor Author

With #6365 merged into this branch, this should be good to go once the buildbots go green

@alexreinking
Copy link
Member

alexreinking commented Nov 1, 2021

With #6365 merged into this branch, this should be good to go once the buildbots go green

Sounds good to me. I have another PR queued up that switches HANNK over to using the helpers introduced in #6366. It also reworks cross-compiling detection and makes one call to ninja rebuild the world 👍

It's ready to go, provided we can get both PRs merged.

@steven-johnson steven-johnson merged commit 1a1c97f into master Nov 1, 2021
@steven-johnson steven-johnson deleted the srj/hannk-wasm-build branch November 1, 2021 20:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants