Skip to content

[Windows] [mmap_data_loader.cpp] mmap equivalent for Windows #8916

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

Merged
merged 5 commits into from
Mar 5, 2025

Conversation

SamGondelman
Copy link
Contributor

Summary

#5164 with the code suggestions applied.

Test plan

I am not familiar with how to test this area of the code. On non-Windows systems, it should be functionally the same.
#5164 suggests a command to run some relevant tests?

jsidewhite and others added 2 commits March 3, 2025 19:38
There is no sys/mman.h or posix-compatible mmap() implementation
on Windows.  The extension data loaders use it to map in data
files, so adding an implementation.

Test-run,

   & .\cmake-out\extension\data_loader\test\Debug\extension_data_loader_test.exe --gtest_brief=1 --gtest_filter=MmapDataLoader*
   Running main() from ...\executorch\third-party\googletest\googletest\src\gtest_main.cc
   [==========] 8 tests from 1 test suite ran. (50 ms total)
   [  PASSED  ] 8 tests.
Copy link

pytorch-bot bot commented Mar 4, 2025

🔗 Helpful Links

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

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

❌ 1 New Failure

As of commit 4e6b973 with merge base 24671a9 (image):

NEW FAILURE - The following job has 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 Mar 4, 2025
@@ -63,14 +62,16 @@ MmapDataLoader::~MmapDataLoader() {
std::free(const_cast<char*>(file_name_));
// fd_ can be -1 if this instance was moved from, but closing a negative fd is
// safe (though it will return an error).
::close(fd_);
if (fd_ != -1) {
::close(fd_);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm surprised this (and open, etc.) works, since it was the problem in #8913. I haven't built this file on Windows myself yet, but maybe a similar fix is necessary?

@SamGondelman SamGondelman added the release notes: build Changes related to build, including dependency upgrades, build flags, optimizations, etc. label Mar 5, 2025
@SamGondelman
Copy link
Contributor Author

hm:

/usr/bin/ld: /pytorch/executorch/build-x86/lib/libextension_module.so: undefined reference to `vtable for executorch::extension::MmapDataLoader'
/usr/bin/ld: /pytorch/executorch/build-x86/lib/libextension_module.so: undefined reference to `executorch::extension::MmapDataLoader::~MmapDataLoader()'
/usr/bin/ld: /pytorch/executorch/build-x86/lib/libextension_module.so: undefined reference to `executorch::extension::MmapDataLoader::from(char const*, executorch::extension::MmapDataLoader::MlockConfig)'

Copy link
Contributor

@SS-JIA SS-JIA left a comment

Choose a reason for hiding this comment

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

@SamGondelman figured out what was causing the linker error you're seeing.

Btw, if you want to repro it yourself, you can do so on a linux machine (e.g. Devserver). You can follow https://pytorch.org/executorch/main/getting-started-setup.html on how to set up the repo. Then

First, build/install ExecuTorch libraries

(rm -rf cmake-out && \
  pp cmake . \
  -DCMAKE_INSTALL_PREFIX=cmake-out \
  -DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON \
  -DEXECUTORCH_BUILD_EXTENSION_MODULE=ON \
  -DEXECUTORCH_BUILD_EXTENSION_RUNNER_UTIL=ON \
  -DEXECUTORCH_BUILD_EXTENSION_TENSOR=ON \
  -DEXECUTORCH_BUILD_KERNELS_OPTIMIZED=ON \
  -DEXECUTORCH_BUILD_KERNELS_CUSTOM=ON \
  -DEXECUTORCH_BUILD_KERNELS_QUANTIZED=ON \
  -DEXECUTORCH_BUILD_VULKAN=ON \
  -Bcmake-out && \
  cmake --build cmake-out -j64 --target install)

The above command should work.

Next, try to build the Llama runner binary. This is where it will fail because the binary will try to link the data loader

(rm -rf cmake-out/examples/models/llama && \
  pp cmake examples/models/llama \
    -DCMAKE_INSTALL_PREFIX=cmake-out \
    -Bcmake-out/examples/models/llama && \
  cmake --build cmake-out/examples/models/llama -j16)

The pp in my commands are to set up fwdproxy.

@SS-JIA
Copy link
Contributor

SS-JIA commented Mar 5, 2025

LGTM. The one test failure does not appear to be related...

@SS-JIA SS-JIA merged commit 286f1fe into pytorch:main Mar 5, 2025
49 of 50 checks passed
@SamGondelman SamGondelman deleted the windows-mmap-data-loader branch March 6, 2025 00:04
zonglinpeng pushed a commit that referenced this pull request Mar 6, 2025
* [Windows Build] Implement MMAP for mmap_data_loader.cpp

There is no sys/mman.h or posix-compatible mmap() implementation
on Windows.  The extension data loaders use it to map in data
files, so adding an implementation.

Test-run,

   & .\cmake-out\extension\data_loader\test\Debug\extension_data_loader_test.exe --gtest_brief=1 --gtest_filter=MmapDataLoader*
   Running main() from ...\executorch\third-party\googletest\googletest\src\gtest_main.cc
   [==========] 8 tests from 1 test suite ran. (50 ms total)
   [  PASSED  ] 8 tests.

* apply code suggestions

* fix src -> srcs typo

* try to fix build

* fix src/headers brackets

---------

Co-authored-by: Jeff Whiteside <[email protected]>
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.

5 participants