-
Notifications
You must be signed in to change notification settings - Fork 577
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
Add VmModule.mmap() to Python API. #14124
Conversation
We really need page aligned flatbuffer blobs vs normal malloc alignment. The best way to be loading a file is via mmap, so just make that available as an API. This could be done in Python by the caller but is error-prone. The public API will make this more robust. Provides the mechanism to fix #13887
May need some tweaking for Windows |
-- This commit is based on [VmModule.mmap() API](iree-org/iree#14124). -- It thereby adds capability to mmap vmfbs in SHARK. Signed-off-by: Abhishek Varma <[email protected]>
with tempfile.NamedTemporaryFile() as tf: | ||
tf.write(binary) | ||
tf.flush() | ||
m = iree.runtime.VmModule.mmap(self.instance, tf.name) |
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.
May need some tweaking for Windows
Indeed. https://github.com/openxla/iree/actions/runs/5275962562/jobs/9542060597#step:9:2321
ERROR: test_mmap (__main__.VmTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\a\iree\iree\runtime\bindings\python\tests\vm_test.py", line 122, in test_mmap
m = iree.runtime.VmModule.mmap(self.instance, tf.name)
PermissionError: [Errno 13] Permission denied: 'C:\\Users\\RUNNER~1\\AppData\\Local\\Temp\\tmpr4u5ldjo'
Maybe related to #13148 (comment)
See https://stackoverflow.com/a/23212515 - NamedTemporaryFile creates and opens the file, and the file cannot be opened again... on Windows (it can be opened again on Unix).
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.
I've added a fix for that in SHARK to deal with this very issue - perhaps that can be used.
But the other issue in Windows which I bumped into is mentioned here - it's API related instead of the use case.
CC: @powderluv
-- This commit is based on [VmModule.mmap() API](iree-org/iree#14124). -- It thereby adds capability to mmap vmfbs in SHARK. Signed-off-by: Abhishek Varma <[email protected]>
-- This commit is based on [VmModule.mmap() API](iree-org/iree#14124). -- It thereby adds capability to mmap vmfbs in SHARK. Signed-off-by: Abhishek Varma <[email protected]>
Python mmap on Windows has a slightly different signature. Reverting for now to unbreak the Windows CI. Will re-apply when have access to test it there. This reverts commit 3345b76.
-- This commit is based on [VmModule.mmap() API](iree-org/iree#14124). -- It thereby adds capability to mmap vmfbs in SHARK. Signed-off-by: Abhishek Varma <[email protected]>
-- This commit is based on [VmModule.mmap() API](iree-org/iree#14124). -- It thereby adds capability to mmap vmfbs in SHARK. Signed-off-by: Abhishek Varma <[email protected]>
-- This commit is based on [VmModule.mmap() API](iree-org/iree#14124). -- It thereby adds capability to mmap vmfbs in SHARK. Signed-off-by: Abhishek Varma <[email protected]>
-- This commit is based on [VmModule.mmap() API](iree-org/iree#14124). -- It thereby adds capability to mmap vmfbs in SHARK. Signed-off-by: Abhishek Varma <[email protected]>
We really need page aligned flatbuffer blobs vs normal malloc alignment. The best way to be loading a file is via mmap, so just make that available as an API. This could be done in Python by the caller but is error-prone. The public API will make this more robust. Provides the mechanism to fix iree-org#13887
Python mmap on Windows has a slightly different signature. Reverting for now to unbreak the Windows CI. Will re-apply when have access to test it there. This reverts commit 3345b76.
We really need page aligned flatbuffer blobs vs normal malloc alignment. The best way to be loading a file is via mmap, so just make that available as an API.
This could be done in Python by the caller but is error-prone. The public API will make this more robust.
Provides the mechanism to fix #13887