Skip to content

Some changes for basic support of MinGW - #76

Closed
mmuetzel wants to merge 7 commits into
mpimd-csc:masterfrom
mmuetzel:mingw
Closed

Some changes for basic support of MinGW#76
mmuetzel wants to merge 7 commits into
mpimd-csc:masterfrom
mmuetzel:mingw

Conversation

@mmuetzel

@mmuetzel mmuetzel commented Mar 17, 2025

Copy link
Copy Markdown
Contributor

These changes are still a hot mess. They compile on MINGW64 with the compilers from MSYS2.
But all tests are failing with errors like the following:

Start testing: Mar 17 21:14 Mitteleuropäische Zeit
----------------------------------------------------------
1/119 Testing: BLAS-xblat1s
1/119 Test: BLAS-xblat1s
Command: "C:/msys64/mingw64/bin/cmake.exe" "-DTEST=D:/repo/flexiblas/build/bin/xblat1s.exe" "-DINTDIR=." "-P" "D:/repo/flexiblas/test/blas/runtest.cmake"
Directory: D:/repo/flexiblas/build/test/blas
"BLAS-xblat1s" start time: Mar 17 21:14 Mitteleuropäische Zeit
Output:
----------------------------------------------------------
-- "D:/repo/flexiblas/build/lib" -- PATH
Running: D:/repo/flexiblas/build/bin/xblat1s.exe
ARGS= 
�[0;2;36m<flexiblas> Config D:\repo\flexiblas\etc/flexiblasrc does not exist.
�[0m�[0;2;36m<flexiblas> Configuration directory D:\repo\flexiblas\etc/flexiblasrc.d does not exists.
�[0m�[0;2;36m<flexiblas> User config C:\Users\Markus\AppData\Roaming\flexiblasrc does not exist.
�[0m�[0;2;36m<flexiblas> Host config (null) does not exist.
�[0m<flexiblas> Load enviroment config D:/repo/flexiblas/build/flexiblasrc
�[1;2;31mflexiblas Unable to load library: D:/repo/flexiblas/build/lib\libflexiblas_hook_dummy.dll.a
�[0m�[1;2;31mflexiblas Unable to load library: D:/repo/flexiblas/build/lib\libflexiblas_hook_profile.dll.a
�[0m�[1;2;31mflexiblas  Failed to load the BLAS fallback library 'flexiblas_netlib.dll'.  Abort!
�[0mCMake Error at D:/repo/flexiblas/test/blas/runtest.cmake:53 (message):
  Test D:/repo/flexiblas/build/bin/xblat1s.exe returned 3


<end of output>
Test time =   0.10 sec
----------------------------------------------------------
Test Failed.
"BLAS-xblat1s" end time: Mar 17 21:14 Mitteleuropäische Zeit
"BLAS-xblat1s" time elapsed: 00:00:00
----------------------------------------------------------

If I understand the error messages correctly, it is trying to load import libraries (with file extension .dll.a) which fails (unsurprisingly). Instead, it should be trying to load the dynamic load libraries (with file extension .dll which are installed in the bin folder on Windows).
I haven't looked yet into why that is happening. Any feedback would be very welcome.

Instead of adding a dependency on a dlopen wrapper library, I thought it might be better to use native Windows functions to load symbols from the libraries on runtime. (Might have a performance advantage. But since it doesn't run yet, I can't tell whether that is the case.)

There are also still a couple of FIXME comments where the implementation isn't complete yet. I figured that it might still make sense to share what I have so far.

@grisuthedragon

Copy link
Copy Markdown
Member

Since there are many constructions like

#ifdef __WIN32__
        ptr  = GetProcAddress(backend->library_handle, fn_name);
#else
        ptr  = dlsym(backend->library_handle, fn_name);
#endif

to get rid of the dlfcn-win32 functionality, we should consider to write a file containing wrappers for dlsym and so on, such that we only have to adjust stuff at one place and keep the remaining code (and its logic) better readable.

@mmuetzel
mmuetzel force-pushed the mingw branch 2 times, most recently from 82bf674 to 5ff8031 Compare March 18, 2025 18:59
@mmuetzel

Copy link
Copy Markdown
Contributor Author

Thanks for the feedback.
I tried to introduce a couple of helper functions that can be called independent on the host OS and encapsulate the target-specific code. There should be a lot less places now with pre-processor conditions like #ifdef __WIN32__.

I also rebased on the branch that triggers the CI on pull requests. (And already found a regression that should be fixed now.)

I'm still at a loss as to where the flexiblas Unable to load library: D:/repo/flexiblas/build/lib\libflexiblas_hook_dummy.dll.a message is coming from.
That looks very suspicious. But is that the actual error? Or is it failing for some other reason?

@grisuthedragon

grisuthedragon commented Mar 18, 2025 via email

Copy link
Copy Markdown
Member

Loading symbols from shared libraries requires different mechanisms on
Windows (compared to Linux or macOS). Add helper functions that
encapsulate these differences for some tasks that are done repeatedly.
That concentrated of platform-specific code in less places and makes
maintenance easier.
Avoid duplicate definition of xerbla_ in Fortran and C if CBLAS=ON.
Define "RowMajorStrg" in one of the objects linked into that library.
@mmuetzel

mmuetzel commented Aug 7, 2025

Copy link
Copy Markdown
Contributor Author

Rebased on your current release candidate.

It still doesn't work. But at least it is building again.

@grisuthedragon

Copy link
Copy Markdown
Member

This should be done with FlexiBLAS 3.5.0

@mmuetzel

mmuetzel commented Nov 10, 2025

Copy link
Copy Markdown
Contributor Author

Thank you for adding support for MinGW.

I finally came around to testing this in the MINGW64 environment of MSYS2.
Configuring (cmake .. in an empty build directory) and building (cmake --build .) went without obvious issues. But a couple of tests are failing for me.
Output for ctest . --rerun-failed --output-on-failure:
test-errors.log

Please, let me know if you have an idea what I might be doing wrong or if you need further information.

If you'd like, I could also look into adding a workflow for testing FlexiBLAS with MSYS2 packages in the GitHub CI. Would you be interested in that?

@grisuthedragon

Copy link
Copy Markdown
Member

These tests will also fail if you compile the reference LAPACK with -DBUILD_SHARED_LIBS=ON. This failure lies in the nature, how the XERBLA routine is exchanged and linked into LAPACK. This problem needs to be first handled by the reference implementation and then by FlexiBLAS. I already have an idea in mind to do this in an API compatible way.

An MSYS2 on github CI would be great. :-)

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