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

Allow build dft on MinGW #540

Merged
merged 6 commits into from
May 31, 2024
Merged

Allow build dft on MinGW #540

merged 6 commits into from
May 31, 2024

Conversation

Andarwinux
Copy link
Contributor

It actually works fine.

It actually works fine.
@Andarwinux
Copy link
Contributor Author

I don't know about gcc, but at least llvm-mingw works fine, I used sleefdft for rubberband's fft library and got better performance than fftw.

@blapie
Copy link
Collaborator

blapie commented May 22, 2024

Hello! We are a bit concerned about the absence of testing for this one. But I suppose DFT can still be disabled manually.
Any chance you could test with gcc?

@blapie
Copy link
Collaborator

blapie commented May 22, 2024

Btw thanks for testing and reporting this, very useful! I'll try to test locally.

These tests don't support MinGW
Some platforms such as MSYS2 provide a broken libcrypto.pc, this is needed to fix statically link build.
To fix cross-compilation compatibility
@Andarwinux
Copy link
Contributor Author

Hello! We are a bit concerned about the absence of testing for this one. But I suppose DFT can still be disabled manually. Any chance you could test with gcc?

I'll try to add a MSYS2 CI that can test gcc and clang. but expect some things to not work. MSYS2 also support clang arm64 and I've done a preliminary evaluation of arm64 build with my cross build toolchain, but that's hard to do in the CI since GHA doesn't support Windows Arm64 runner.

@Andarwinux
Copy link
Contributor Author

Unfortunately, the mingw-w64 gcc does not work at all. But clang passes the test, will add msys2 native build & test and llvm-mingw aarch64 & x86_64 cross build later.

@blapie
Copy link
Collaborator

blapie commented May 23, 2024

I'll try to add a MSYS2 CI that can test gcc and clang. but expect some things to not work.

Yes, it is most likely why we were holding it for now. But we would be ok to start with only a subset of the tests.

MSYS2 also support clang arm64 and I've done a preliminary evaluation of arm64 build with my cross build toolchain, but that's hard to do in the CI since GHA doesn't support Windows Arm64 runner.

Yes, we have also done some work to enable Windows on Arm (for sleef/libm) that is not yet upstream, happy to try and merge that soon if that can help. However as you said it is not available on GH-hosted runners, so we will have to keep testing internally for now.
Another issue with Windows on Arm is that libm tests rely heavily on POSIX, which is an issue with MSYS2. That's a shame because MSYS2 is quite a convenient environment to use. I have not checked if it's also the case for sleef/dft though, but I suspect it is.

@blapie
Copy link
Collaborator

blapie commented May 23, 2024

Thanks for the contribution, impressive GHA skills!

I like the idea of the build/test-msys2 jobs, we were definitely missing testing for Windows (x86).

On the other hand, we did not desperately need a precommit workflow for llvm-mingw, but it is quite handy to be able to (cross-)compile for windows on both x86 and arm64, so happy try and merge that too.

Before getting into the details, would you mind moving both jobs to separate yaml files (even if it means duplicating code for build-native)? We might want to schedule and parametrise the 3 workflows differently. {build,test}-msys2 to build-and-test-windows.yml and build-llvm-mingw to build-cross-windows.yml?

Btw if you are aware of simple/nice ways to re-use bits of workflows (say build-native) in other workflows, please let us know.

@Andarwinux
Copy link
Contributor Author

On the other hand, we did not desperately need a precommit workflow for llvm-mingw, but it is quite handy to be able to (cross-)compile for windows on both x86 and arm64, so happy try and merge that too.

Most MinGW users are cross-compile on Linux because the build are an order of magnitude faster, so I'd prefer cross-compile to be a first-class citizen.

Before getting into the details, would you mind moving both jobs to separate yaml files (even if it means duplicating code for build-native)? We might want to schedule and parametrise the 3 workflows differently. {build,test}-msys2 to build-and-test-windows.yml and build-llvm-mingw to build-cross-windows.yml?

Done. Native build are usually very fast, and since there is no longer need to pass native build files via artifacts, this is actually faster.

Btw if you are aware of simple/nice ways to re-use bits of workflows (say build-native) in other workflows, please let us know.

One possible way to do this is to save native builds to action cache, which is quite a bit faster than artifacts and can across workflows. But I suspect this would still be slower than build native and cross within same instance.

@blapie
Copy link
Collaborator

blapie commented May 29, 2024

One possible way to do this is to save native builds to action cache, which is quite a bit faster than artifacts and can across workflows. But I suspect this would still be slower than build native and cross within same instance.

Thanks for the insight, action cache might be useful for other jobs. I like the present solution though, hopefully in the future a native build isn't even needed to cross-compile.

@blapie
Copy link
Collaborator

blapie commented May 29, 2024

Regarding the libm and quad tests on msys2, would you be able to link us to the build or test failures?
The main reason I expect the build to fail is that wait.h is not available on msys2, since it is POSIX. For this reason I think the suggested changes to CMakeLists are acceptable, until we find a workaround.

Do you have suggestions on ways to port a code that relies on wait.h (wait, fork, ...) to mingw/msys2?

@shibatch Have you ever considered ways to make the libm tester compatible with mingw?

@shibatch
Copy link
Owner

Since tester1 does not need to be compiled with mingw, the test should be possible by combining tester1 for Cygwin or linux, although it may be a bit troublesome to write the script for the test.

Another idea could be to add a new tester using tlfloat, which I am currently developing. With tlfloat, testing is possible even if libmpfr is not available.

@blapie
Copy link
Collaborator

blapie commented May 29, 2024

Since tester1 does not need to be compiled with mingw, the test should be possible by combining tester1 for Cygwin or linux, although it may be a bit troublesome to write the script for the test.

Fair, it's true that they can be compiled independently, but I'm afraid this will confuse things more than they already are on Windows.

Another idea could be to add a new tester using tlfloat, which I am currently developing. With tlfloat, testing is possible even if libmpfr is not available.

That could be interesting! Looks like you already have support for several OS-es there too. Mpfr is not the worst dependency to have, but always good to remove dependencies I suppose.

Would tlfloat resolve the dependency on wait.h and POSIX in general? Is it able to handle multithreading too?
My suggestion would have been to just brutally remove multithreading/calls to wait.h in tester1 on windows, but I'm not sure how to do that.

Alternatively, we could look at straight windows port for wait.h https://github.com/win32ports/sys_wait_h ?

@shibatch
Copy link
Owner

The new tester can be made pipe-free and multi-threading capable.

@blapie
Copy link
Collaborator

blapie commented May 29, 2024

The new tester can be made pipe-free and multi-threading capable.

I suggest we create an issue specifically for this?

@shibatch
Copy link
Owner

Writing an Issue is fine, but there are other things to consider regarding this.
First is how to link tlfloat from sleef.

If we implement the fp16 support mentioned here, it could be related to that as well.
#320

_install-*
if: always()

test-msys2:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could we display information on the cpu in this job at least? Equivalent to what we have in the linux workflow:
https://github.com/shibatch/sleef/actions/runs/8845094575/workflow#L102
Ideally in all jobs but that might be a bit much.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

Comment on lines 90 to 95
-DCMAKE_INSTALL_PREFIX="$(pwd)/_install-${{ matrix.arch }}" \
-DCMAKE_SYSROOT="$(pwd)/llvm-mingw/${{ matrix.arch }}-w64-mingw32" \
-DNATIVE_BUILD_DIR="$(pwd)/_build-native" \
${COMMON_CMAKE_FLAGS} \
-DCMAKE_C_COMPILER=${{ matrix.arch }}-w64-mingw32-clang \
-DCMAKE_ASM_COMPILER=${{ matrix.arch }}-w64-mingw32-clang \
-DCMAKE_SYSTEM_NAME=Windows \
-DCMAKE_SYSTEM_PROCESSOR=${{ matrix.arch }} \
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do you think we can rely on a toolchain file for most of these options? Our toolchain files are located in https://github.com/shibatch/sleef/tree/master/toolchains.

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 don't think this makes sense, ideally llvm-mingw is multi-target, in order to support multiple targets, toolchain.cmake only include platform specific not architecture specific, which actually means that toolchain.cmake only include CMAKE_SYSTEM_NAME=Windows.

Comment on lines 36 to 38
#- mingw64
#- ucrt64
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could we have a quick comment saying why these are commented out?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

mingw64 and ucrt64 are gcc envs, and gcc is completely broken.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Do you have any more details on that, maybe a link? Is the compiler broken or is it SLEEF when compiled in a gcc envs?

Copy link
Contributor Author

@Andarwinux Andarwinux May 29, 2024

Choose a reason for hiding this comment

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

-DNATIVE_BUILD_DIR="$(pwd)/_build-native" \
${COMMON_CMAKE_FLAGS} \
-DCMAKE_C_COMPILER=${{ matrix.arch }}-w64-mingw32-clang \
-DCMAKE_ASM_COMPILER=${{ matrix.arch }}-w64-mingw32-clang \
Copy link
Collaborator

Choose a reason for hiding this comment

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

CMAKE_ASM_COMPILER one does not seem to be used, could just rm?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

@Andarwinux Andarwinux force-pushed the mingw branch 2 times, most recently from 904a57d to d663a23 Compare May 29, 2024 18:10
@Andarwinux
Copy link
Contributor Author

Made some fixes and cleanups, and enabled LTO for clang.

</tr>
<tr align="center"><th>x86_64</th><th>SSE2, SSE4,<br>AVX, AVX2, AVX512F</th>
<td>:green_circle:</td><td>:green_circle:</td><td>:white_circle:</td>
<td>:white_circle:</td><td>:white_circle:</td>
<td>:white_circle:</td><td>:white_circle:</td><td>:white_circle:</td>
<td>:white_circle:</td><td>:green_circle:</td><td>:white_circle:</td><td>:white_circle:</td>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks for taking the time to document that.
In this case only DFT is tested though. What we do at the moment is at least add a comment in the following subsections, here Component support section should indicate that on Windows only DFT is tested but everything is built.

Let's not bother in this patch but we should probably use a different colour scheme when only part of the library is tested, or when component is compiled only and not tested. Ultimately, this could probably be mapped to the workflow/job status.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

msys2 clang and llvm-mingw cross
Subdivided Windows LLVM into llvm-gnu and llvm-msvc to distinguish between *-w64-mingw32 (aka *-pc-windows-gnu) and *-pc-windows-msvc targets.

Updated Windows AArch64 from N/A to Not tested in CI.
run: |
EXTRA_CMAKE_FLAGS=""
if [[ ${{ matrix.sys }} = "clang64" ]]; then
EXTRA_CMAKE_FLAGS="$EXTRA_CMAKE_FLAGS -DSLEEF_ENABLE_LTO=ON"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we please test without LTO for now? I would like to test SLEEF's basic features primarily, and test LTO separately if that's ok.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added lto matrix.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ok, works for me. But please refrain from adding too many variants/parameters as we have limited resources to address failures. Also special casing for combinations of parameters is a bit gross in GHA workflow files.

EXTRA_CMAKE_FLAGS="$EXTRA_CMAKE_FLAGS -DSLEEF_ENABLE_LTO=ON"
EXTRA_CMAKE_FLAGS="$EXTRA_CMAKE_FLAGS -DSLEEF_ENFORCE_SSE2=ON -DSLEEF_ENFORCE_SSE4=ON -DSLEEF_ENFORCE_AVX=ON -DSLEEF_ENFORCE_AVX2=ON -DSLEEF_ENFORCE_AVX512F=ON -DSLEEF_ENFORCE_FMA4=ON"
elif [[ ${{ matrix.sys }} = "clangarm64" ]]; then
EXTRA_CMAKE_FLAGS="$EXTRA_CMAKE_FLAGS -DSLEEF_ENABLE_LTO=ON"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here, can we remove LTO for now.

-DSLEEF_BUILD_SCALAR_LIB=ON
-DSLEEF_BUILD_STATIC_TEST_BINS=ON
-DSLEEF_BUILD_TESTS=OFF
-DSLEEF_ENABLE_LTO=ON
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here.

@Andarwinux
Copy link
Contributor Author

Rename yml to msys2 and llvm-mingw to avoid conflicts with future msvc/llvm-msvc{msvc-style, gnu-style}/llvm-msvc-cross{msvc-style, gnu-style}.

@blapie
Copy link
Collaborator

blapie commented May 31, 2024

Are you happy for me to merge?

@Andarwinux
Copy link
Contributor Author

Yes, LGTM.

@blapie blapie merged commit 0f25148 into shibatch:master May 31, 2024
39 checks passed
@Andarwinux Andarwinux deleted the mingw branch June 1, 2024 09:33
@blapie blapie mentioned this pull request Jun 3, 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.

3 participants