-
Notifications
You must be signed in to change notification settings - Fork 536
[Build] fix file_data_loader.cpp build issues for windows #4899
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
base: main
Are you sure you want to change the base?
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/4899
Note: Links to docs will display an error until the docs builds have been completed. This comment was automatically generated by Dr. CI and updates every 15 minutes. |
Thank you @python3kgae ! I would prefer that we use a single file.h, and check for cc @dbort |
Two build issues have been addressed in this pull request: 1. Avoid closing when fd_ is -1, as this would cause a crash on Windows. 2. Introduce separate headers for Windows and Unix, enabling Windows builds to utilize a distinct header and implement pread. For pytorch#4661
54a7016
to
be77d20
Compare
Changed into single file.h. |
Thank you! One more request: in extension/data_loader/targets.bzl line 43, can you add a line
|
Like this?
|
Yes |
Done. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Normally we try to avoid using platform-based #ifdefs
for implementations, and will create separate .cpp files that the build system brings in as necessary. But this is pretty light-weight and self-contained, so it seems fine.
extension/data_loader/file.h
Outdated
@@ -0,0 +1,57 @@ | |||
/* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please call this file pread.h
to make its purpose more clear.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated.
extension/data_loader/file.h
Outdated
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a comment describing the purpose of this header: i.e., it ensures that a pread
-compatible function is defined in the global namespace for windows and posix environments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated.
extension/data_loader/file.h
Outdated
|
||
#include <windows.h> | ||
|
||
inline ssize_t pread(int __fd, void* __buf, size_t __nbytes, size_t __offset) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove the leading underscores from the param names. Since this is our code and not part of the standard library, we shouldn't define any names beginning with underscore.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated.
extension/data_loader/file.h
Outdated
overlapped.Offset = __offset; | ||
overlapped.OffsetHigh = __offset >> 32; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will this do the right thing on both 32-bit and 64-bit architectures? Seems like it should, but I don't know enough about the definition of DWORD on different architectures
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DWORD will always be 32 bits on both 32-bit and 64-bit Windows systems.
It's important to note that the nNumberOfBytesToRead parameter for ReadFile is a DWORD. Therefore, if we need to read more than 4GB of data at once, the current implementation needs to be updated to handle larger file sizes.
extension/data_loader/file.h
Outdated
// To avoid conflicts with std::numeric_limits<int32_t>::max() in | ||
// file_data_loader.cpp. | ||
#undef max |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please move this to the top of the file, closer to the header that defined it. If you know, please mention which header defined it, since on its own it's not clear why this file should bother undefining a macro that it didn't define.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
@tarun292, @kirklandsign can you take a look please? |
Two Windows build issues have been addressed in this pull request:
For #4661