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

Fix params_test on Windows. #7

Merged
merged 1 commit into from
Apr 30, 2024
Merged

Conversation

ScottTodd
Copy link
Member

Fix was similar to iree-org/iree@11d2259

Once a temporary file is opened on Windows, it can't be reopened unless some extra conditions are met. From https://docs.python.org/3/library/tempfile.html:

Opening the temporary file again by its name while it is still open works as follows:

  • On POSIX the file can always be opened again.
  • On Windows, make sure that at least one of the following conditions are fulfilled:
    • delete is false
    • additional open shares delete access (e.g. by calling os.open() with the flag O_TEMPORARY)
    • delete is true but delete_on_close is false. Note, that in this case the additional opens that do not share delete access (e.g. created via builtin open()) must be closed before exiting the context manager, else the os.unlink() call on context manager exit will fail with a PermissionError.

We were setting delete=False, but I still saw these errors:

__________________________________ ParamsTest.testCreateArchive ___________________________________

self = <params_test.ParamsTest testMethod=testCreateArchive>

    def testCreateArchive(self):
        with tempfile.NamedTemporaryFile("wb", delete=False, suffix=".irpa") as f:
            file_path = Path(f.name)
            try:
                m = SimpleParamsModule()
>               save_module_parameters(file_path, m)

tests\aot\params_test.py:43:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ shark_turbine\aot\params.py:136: in save_module_parameters
    builder.save(file_path)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <shark_turbine.aot.params.ParameterArchiveBuilder object at 0x00000216279F0A50>
file_path = WindowsPath('C:/Users/Scott/AppData/Local/Temp/tmpj0_157nn.irpa')

    def save(self, file_path: Union[str, Path]):
        """Saves the archive."""
>       self._index.create_archive_file(str(file_path))
E       RuntimeError: Error building parameter archive: D:\a\iree\iree\c\runtime\src\iree\base\internal\file_io.c:381: UNKNOWN; failed to open file 'C:\Users\Scott\AppData\Local\Temp\tmpj0_157nn.irpa'

shark_turbine\aot\params.py:261: RuntimeError

```
__________________________________ ParamsTest.testCreateArchive ___________________________________

self = <params_test.ParamsTest testMethod=testCreateArchive>

    def testCreateArchive(self):
        with tempfile.NamedTemporaryFile("wb", delete=False, suffix=".irpa") as f:
            file_path = Path(f.name)
            try:
                m = SimpleParamsModule()
>               save_module_parameters(file_path, m)

tests\aot\params_test.py:43:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ shark_turbine\aot\params.py:136: in save_module_parameters
    builder.save(file_path)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <shark_turbine.aot.params.ParameterArchiveBuilder object at 0x00000216279F0A50>
file_path = WindowsPath('C:/Users/Scott/AppData/Local/Temp/tmpj0_157nn.irpa')

    def save(self, file_path: Union[str, Path]):
        """Saves the archive."""
>       self._index.create_archive_file(str(file_path))
E       RuntimeError: Error building parameter archive: D:\a\iree\iree\c\runtime\src\iree\base\internal\file_io.c:381: UNKNOWN; failed to open file 'C:\Users\Scott\AppData\Local\Temp\tmpj0_157nn.irpa'

shark_turbine\aot\params.py:261: RuntimeError
```
@ScottTodd ScottTodd merged commit 63a2411 into iree-org:main Apr 30, 2024
3 checks passed
@ScottTodd ScottTodd deleted the test-windows-fix branch April 30, 2024 16:41
erman-gurses pushed a commit to erman-gurses/iree-turbine that referenced this pull request Aug 22, 2024
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