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

Enable arm64 for MSVC on Windows #5811

Merged
merged 2 commits into from Feb 2, 2022

Conversation

gaborkertesz-linaro
Copy link
Contributor

This patch enabled win-arm64 as a new platform for Windows.
Platform query and documentation is updated accordingly.

@gaborkertesz-linaro
Copy link
Contributor Author

@nulano
Copy link
Contributor

nulano commented Nov 4, 2021

Could you please post the full Pytest output? In particular, I would be interested in seeing the skips and the list of loaded dependencies (at the start of the output).

@gaborkertesz-linaro
Copy link
Contributor Author

x64_pytests_full.txt
win-arm64_pytests_full.txt

I attach the x64 results as a reference also as it looks that there 3 common failing tests.

@@ -42,8 +42,8 @@ behaviour of ``build_prepare.py``:
If ``PYTHON`` is unset, the version of Python used to run
``build_prepare.py`` will be used. If only ``PYTHON`` is set,
``EXECUTABLE`` defaults to ``python.exe``.
* ``ARCHITECTURE`` is used to select a ``x86`` or ``x64`` build. By default,
uses same architecture as the version of Python used to run ``build_prepare.py``.
* ``ARCHITECTURE`` is used to select a ``x86``, ``x64`` or ``x86_arm64`` (for win-arm64) build.
Copy link
Contributor

Choose a reason for hiding this comment

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

x86_arm64 seems very odd to see... why not simply arm64?

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 agree it's strange.
It's coming from vcvarsall.bat (attached) and the fact the win-arm64 MSVC compiler is basically a cross-compiler, not native arm64. The host is working in x86 emulation mode.
vcvarsall.bat.txt

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, got it. Thanks.

Copy link
Contributor

Choose a reason for hiding this comment

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

Since this is an internal value only used by Pillow, there is nothing preventing the use of arm64. In fact, while vcvarsall uses x86_arm64, MSBuild uses ARM64 (according to this PR, I haven't checked myself). The x64 value already disagrees with vcvarsall's x86_amd64. So I would also vote for either arm64 or ARM64. Of the two, I would probably prefer ARM64 to match platform.machine(), but either is fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, updated!

@hugovk
Copy link
Member

hugovk commented Nov 7, 2021

Is this testable on GitHub Actions?

@gaborkertesz-linaro
Copy link
Contributor Author

gaborkertesz-linaro commented Nov 8, 2021

Not yet unfortunately.

@gaborkertesz-linaro
Copy link
Contributor Author

gaborkertesz-linaro commented Nov 10, 2021

I've investigated the following test: test_image_access.py::TestEmbeddable::test_embeddable

It's only enabled local Windows run: https://github.com/python-pillow/Pillow/blob/main/Tests/test_image_access.py#L399
https://github.com/python-pillow/Pillow/runs/4152656413?check_suite_focus=true#step:25:2227
However it fails for me on x64 and win-arm64 as well.

I tend to think this test should be removed or fix for all platforms as it should be a platform agnostic test as embedding into C/C++ code should be universal.

I see several issues:

  1. First error: LINK : fatal error LNK1104: cannot open file 'python310.lib'
  1. Next error: "python310.dll not found"
  • I was able to fix that by adding the required directory to the path in test_image_access.py also.
  1. Next error: "ModuleNotFoundError: No module named 'encodings'"
  1. Next error: https://github.com/python-pillow/Pillow/blob/main/Tests/test_image_access.py#L416 returns with error, which results AssertionError: assert 3221225477 == 0

@nulano
Copy link
Contributor

nulano commented Nov 10, 2021

  1. Next error: https://github.com/python-pillow/Pillow/blob/main/Tests/test_image_access.py#L416 returns with error, which results AssertionError: assert 3221225477 == 0

For reference, 3221225477 == 0xC0000005, i.e. access violation. From MSDN:

Specifically, a C0000005 error is an access violation error caused by a buffer overrun.

@gaborkertesz-linaro
Copy link
Contributor Author

gaborkertesz-linaro commented Nov 10, 2021

Thanks!

However my main question is:
Would you welcome if I investigate this issue further? I'm hesitating a bit as this test is disabled by most cases. If you would prefer to see this to be fixed, I'll investigate it further.

@nulano
Copy link
Contributor

nulano commented Nov 10, 2021

Would you welcome if I investigate this issue further?

As far as I'm concerned, I wasn't around when the test was added, and I haven't seen it pass on Windows in the past 2 years. I've also not looked into it further myself.

@gaborkertesz-linaro
Copy link
Contributor Author

Would you welcome if I investigate this issue further?

As far as I'm concerned, I wasn't around when the test was added, and I haven't seen it pass on Windows in the past 2 years. I've also not looked into it further myself.

Wouldn't it be a right time to remove this test to avoid further confusion?

@gaborkertesz-linaro
Copy link
Contributor Author

@radarhere @nulano @hugovk Sorry for the reminder, but can I do anything to close this PR?

# commit: Merge branch 'master' into msvc (matches 2.16.0 tag)
"url": "https://github.com/ImageOptim/libimagequant/archive/f41ee301ff3a407b16991af3dbe03910919bbdc3.zip", # noqa: E501
"filename": "libimagequant-f41ee301ff3a407b16991af3dbe03910919bbdc3.zip",
"dir": "libimagequant-f41ee301ff3a407b16991af3dbe03910919bbdc3",
Copy link
Member

Choose a reason for hiding this comment

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

Why switch to the master branch here? As the comment says, previously this used the msvc branch, so the 2.17.0 equivalent would be ImageOptim/libimagequant@e4c1334

Copy link
Member

Choose a reason for hiding this comment

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

I've updated to the 2.17.0 version of the msvc branch in #5916

* ``ARCHITECTURE`` is used to select a ``x86`` or ``x64`` build. By default,
uses same architecture as the version of Python used to run ``build_prepare.py``.
* ``ARCHITECTURE`` is used to select a ``x86``, ``x64`` or ``ARM64``build.
By default, uses same architecture as the version of Python used to run ``build_prepare.py``.
is used.
Copy link
Contributor

@nulano nulano Dec 29, 2021

Choose a reason for hiding this comment

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

This change seems to have disappered in a force-push. Is there any reason not to include it anymore?

Suggested change
is used.
is used. Note that the ``ARM64`` build is not fully supported and some dependencies may fail to build. Pull requests are welcome.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry I didn't mention that LittleCMS is the last dependency and VS2019 update is merged, just not released yet:
mm2/Little-CMS#288
Patch to use VS2019 project: gaborkertesz-linaro@0af6042

So if either VS2019 project is accepted or VS2017 will be updated for ARM64 as well and LCMS2 is released, all external dependencies will be enabled.
Probably this pull request can be blocked until updated LCMS2 is released.

Copy link
Member

Choose a reason for hiding this comment

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

lcms2 2.13 has now been released.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the heads up, I'm going to rebase my changes and run the tests!

@gaborkertesz-linaro
Copy link
Contributor Author

@nulano
Copy link
Contributor

nulano commented Jan 31, 2022

Could you please re-run the tests with C:\kg\python_test\github_packages\Pillow\winbuild\build\bin added to PATH? It seems fribidi.dll wasn't found, likely because of this. Looks mostly OK otherwise. The commands should probably be something like:

PATH %PATH%;C:\kg\python_test\github_packages\Pillow\winbuild\build\bin
"C:\kg\python_test\venv_310_new\Scripts\python.exe" -m pytest -v Tests

This patch enables ARM64 as a new platform for Windows.
Platform query and documentation is updated accordingly.
In order to enable win-arm64, VS2019 should be used, while other
platforms should work with newer version as well.
Tested on x64-win10.
@gaborkertesz-linaro
Copy link
Contributor Author

05_Tests2.log
Tests are repeated with Pillow\winbuild\build\bin added to the path.

Copy link
Contributor

@nulano nulano left a comment

Choose a reason for hiding this comment

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

Thank you, looks mostly good.

The first three failures seem to be a difference in floating point rounding:

FAILED Tests/test_color_lut.py::TestTransformColorLut3D::test_3_to_4_channels
    At index 4 diff: 0.04000000000000001 != 0.04
FAILED Tests/test_color_lut.py::TestTransformColorLut3D::test_4_to_4_channels
    At index 4 diff: 0.04000000000000001 != 0.04
FAILED Tests/test_color_lut.py::TestTransformColorLut3D::test_with_normals_3_channels
    At index 12 diff: 0.15999999999999992 != 0.16000000000000003

The next two could be caused by a similar difference, being a small margin above the epsilon (but hard to be sure without visually inspecting the images):

FAILED Tests/test_file_wmf.py::test_load_raw - AssertionError:  average pixel value difference 2.0479 > epsilon 2.0000
FAILED Tests/test_file_wmf.py::test_load_set_dpi - AssertionError:  average pixel value difference 2.6547 > epsilon 2.1000

The next failed test I have never seen pass on Windows:

FAILED Tests/test_image_access.py::TestEmbeddable::test_embeddable - distutil...

And the last one could be due to how the tests are being run. Are you running the tests directly in a desktop session, or are you using some sort of terminal without a desktop, e.g. SSH? Either way this seems like a separate issue unrelated to ARM.

FAILED Tests/test_imagegrab.py::TestImageGrab::test_grab - OSError: screen grab failed

@gaborkertesz-linaro
Copy link
Contributor Author

And the last one could be due to how the tests are being run. Are you running the tests directly in a desktop session, or are you using some sort of terminal without a desktop, e.g. SSH? Either way this seems like a separate issue unrelated to ARM.

I connect to my local PC via remote desktop and run the tests in Windows Terminal, so I'd expect this shouldn't prevent screengrab. Probably as a follow-up taks this could be investigated.

@radarhere radarhere merged commit c74313a into python-pillow:main Feb 2, 2022
@radarhere radarhere changed the title Windows: Enable win-arm64 for MSVC Enable arm64 for MSVC on Windows Feb 2, 2022
@gaborkertesz-linaro
Copy link
Contributor Author

Thanks for the thorough and persistent support!
If anybody ever interested about Pillow and dependencies porting to WoA, I've created a confluence page summary:
https://linaro.atlassian.net/wiki/spaces/WOAR/pages/28654632982/A+tale+of+a+dependency+chain+Pillow+and+the+crew

@nulano
Copy link
Contributor

nulano commented Feb 2, 2022

If anybody ever interested about Pillow and dependencies porting to WoA, I've created a confluence page summary: https://linaro.atlassian.net/wiki/spaces/WOAR/pages/28654632982/A+tale+of+a+dependency+chain+Pillow+and+the+crew

A small clarification: Pillow doesn't use libpng, HarfBuzz, FriBiDi directly. These are only listed in build_prepare because they are used by the other libraries.

Specifically, libpng is used by FreeType to support color fonts in CBDT/SBIX format, and HarfBuzz/FriBiDi are dependencies of Raqm. Raqm used to be built directly, but as of Pillow 8.2.0 a modified version is included in the sources and is now the default on Windows. For details see: https://pillow.readthedocs.io/en/stable/installation.html#external-libraries

@gaborkertesz-linaro
Copy link
Contributor Author

gaborkertesz-linaro commented Feb 2, 2022

Thanks, I'll fix these issues!
Why libpng is needed to be imported directly by Pillow, while FreeType imports for itself anyway?

@nulano
Copy link
Contributor

nulano commented Feb 2, 2022

Why libpng is needed to be imported directly by Pillow, while FreeType imports for itself anyway?

I don't understand your question. Doing a grep for libpng in Pillow only shows build_prepare.py and test-windows.yml for me, the latter containing a comment that libpng is only used by FreeType.

Are you asking why build_prepare generates a script to compile the indirect dependencies? The VS2010 build of FreeType doesn't build libpng directly, libpng must already be present and compiled somewhere, so build_prepare takes care of that.

@gaborkertesz-linaro
Copy link
Contributor Author

Thanks, yes, that was my concern that FreeTypes includes libpng dependency in its source and I'd expect that ideally it should take care of build dependencies:
https://gitlab.freedesktop.org/freetype/freetype/-/blob/master/subprojects/libpng.wrap
However I see the released package doesn't include the subprojects.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants