Skip to content

Windows x64 Build with support for xnnpack and llama example #6979

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

Closed
wants to merge 16 commits into from

Conversation

vortex-captain
Copy link

@vortex-captain vortex-captain commented Nov 20, 2024

Summary

This PR introduces support for out-of-the-box builds on Windows x64 with xnnpack, simplifying the setup process for developers using executorch on Windows. Additionally, it lays the groundwork for future Windows build pipelines and prebuilt PyPI packages.

Fixes #4661

Test plan

PR tested by running minimal executor_runner example (https://pytorch.org/executorch/stable/getting-started-setup.html#run-your-program) in the following environment:

  • Windows 11 x64
  • Visual Studio Enterprise 2022 with these components installed:
    • C++ Clang tools for Windows
    • MSBuild support for LLVM (clang-cl) toolset
    • C++ CMake tools for Windows

Steps:

# run the following in command prompt
cd executorch/  # contains code of this PR
git pull
git submodule sync
git submodule update --init

./install_requirements.bat --pybind xnnpack
Remove-Item -Path "add.pte" -ErrorAction SilentlyContinue
python .\export_add.py  # export_add.py from https://pytorch.org/executorch/stable/getting-started-setup.html#export-a-program
msbuild pip-out\temp.win-amd64-cpython-310\cmake-out\executorch.sln /t:Rebuild
pip-out\temp.win-amd64-cpython-310\cmake-out\Debug\executor_runner.exe --model-path add.pte

References

#4681
#5252
#4899
#5164
#4993

Copy link

pytorch-bot bot commented Nov 20, 2024

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/6979

Note: Links to docs will display an error until the docs builds have been completed.

❌ 6 New Failures

As of commit 8e2b8bd with merge base 3475707 (image):

NEW FAILURES - The following jobs have failed:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Nov 20, 2024
Copy link

pytorch-bot bot commented Nov 21, 2024

❌ 🤖 pytorchbot command failed:

@pytorchbot: error: argument command: invalid choice: 'Release' (choose from 'merge', 'revert', 'rebase', 'label', 'drci', 'cherry-pick', 'close')

usage: @pytorchbot [-h] {merge,revert,rebase,label,drci,cherry-pick,close} ...

Try @pytorchbot --help for more info.

@vortex-captain
Copy link
Author

@pytorchbot label "Release notes: build"

Copy link

pytorch-bot bot commented Nov 21, 2024

Didn't find following labels among repository labels: Release notes: build

@vortex-captain
Copy link
Author

@pytorchbot label "release notes: build"

@pytorch-bot pytorch-bot bot added the release notes: build Changes related to build, including dependency upgrades, build flags, optimizations, etc. label Nov 21, 2024
@vortex-captain vortex-captain marked this pull request as ready for review November 21, 2024 03:24
@vortex-captain
Copy link
Author

Hi @kirklandsign and @dbort! Could you kindly help assign reviewers to this PR? Many thanks!

@kirklandsign kirklandsign requested a review from dbort November 21, 2024 18:42
vortex-captain and others added 2 commits November 22, 2024 09:48
- attempt to fix extension/data_loader/file_data_loader.cpp:20:10: fatal error: 'executorch/runtime/platform/unistd.h' file not found
@vortex-captain
Copy link
Author

Hi @dbort I attempted to address the issues in the checks, could you kindly help rerun them? Thanks 😄

@vortex-captain vortex-captain changed the title Windows x64 Build Support Windows x64 Build Support with xnnpack Dec 3, 2024
@vortex-captain vortex-captain changed the title Windows x64 Build Support with xnnpack Windows x64 Build with support for xnnpack and llama example Dec 4, 2024
@mergennachin mergennachin requested a review from tarun292 December 5, 2024 17:18
Copy link
Contributor

@malfet malfet left a comment

Choose a reason for hiding this comment

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

IMO this change would benefit from splitting it into several separate PRs, namely:

  • Please rename unistd.h to compat_unistd.h as redefining system headers might create some hard to debug confusions
  • Submit a separate PR for adding dataloader on Windows
  • Submit smaller fixes for individual changes in headers/cpp files explaining why they are needed
  • Submit a separate PR with generic build system changes

Copy link
Contributor

@mcr229 mcr229 left a comment

Choose a reason for hiding this comment

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

XNN related changes look good to me

endif()


if (WIN32)
Copy link
Contributor

Choose a reason for hiding this comment

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

this looks fine to me, i'm assuming this has to be done for every flatbuffer outputted header file

Copy link
Author

@vortex-captain vortex-captain Dec 6, 2024

Choose a reason for hiding this comment

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

this looks fine to me, i'm assuming this has to be done for every flatbuffer outputted header file

Thanks for the review! As suggested, we will split into smaller PRs (#7217), and apply these "platform-dependent shell command" changes everywhere in a later PR

// There currently doesn't seem to be a great way to do this in Windows and
// given that weak linkage is not really critical on Windows, we'll just leave
// it as a stub.
#define ET_WEAK
Copy link
Contributor

Choose a reason for hiding this comment

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

@vortex-captain does this work with MSVC now? Is there a certain version of MSVC this works for, because i remember it didn't work for the older versions.

Copy link
Author

Choose a reason for hiding this comment

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

@vortex-captain does this work with MSVC now? Is there a certain version of MSVC this works for, because i remember it didn't work for the older versions.

yes, Windows x64 build uses clang-cl compiler, which supports __attribute__((weak))

@@ -0,0 +1,251 @@
/*
* Copyright (c) Google Inc. and affiliates.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think as @malfet mentioned, isolating these changes to a separate PR would be much more easier to review.

Copy link
Author

Choose a reason for hiding this comment

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

I think as @malfet mentioned, isolating these changes to a separate PR would be much more easier to review.

Sure! We plan to split into 3 smaller PRs: #7217

@@ -0,0 +1,75 @@
/*
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel like we should maybe create a separate folder for this like runtime/platform/windows and put this under there. @dbort what do you think?

Copy link
Author

Choose a reason for hiding this comment

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

I feel like we should maybe create a separate folder for this like runtime/platform/windows and put this under there. @dbort what do you think?

As @malfet suggested, We renamed unistd.h to compat_unistd.h in the new PR which would serve as a wrapper of <unistd.h> used in different platforms. Would it be clearer to put it in runtime/platform/windows? Thanks!

@vortex-captain
Copy link
Author

IMO this change would benefit from splitting it into several separate PRs, namely:

  • Please rename unistd.h to compat_unistd.h as redefining system headers might create some hard to debug confusions
  • Submit a separate PR for adding dataloader on Windows
  • Submit smaller fixes for individual changes in headers/cpp files explaining why they are needed
  • Submit a separate PR with generic build system changes

Thanks for the great suggestions! We plan to split this PR into 3 smaller ones, please find details in the new PR here, in which unistd.h has been renamed to compat_unistd.h

@SS-JIA
Copy link
Contributor

SS-JIA commented Mar 17, 2025

Closing this PR now, as the changes contained in this PR are now merged as a part of the recent Windows support effort i.e. #9198

@SS-JIA SS-JIA closed this Mar 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. release notes: build Changes related to build, including dependency upgrades, build flags, optimizations, etc.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support build on native Windows
7 participants