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

Use f2c translations of LAPACK when no Fortran compiler is available #3539

Merged
merged 95 commits into from
Apr 9, 2022
Merged

Use f2c translations of LAPACK when no Fortran compiler is available #3539

merged 95 commits into from
Apr 9, 2022

Conversation

martin-frbg
Copy link
Collaborator

@martin-frbg martin-frbg commented Feb 23, 2022

translations done with a modified version of the f2clapack script from PRIMME (which in turn based on the one from f2clapack)
and additional hand-editing to work around use of F90 idiom in current LAPACK.

  • the current translation drops OpenMP parallelism from the few .F files that used it (f2c limitation, could be put back by hand)
  • currently omits cgbrfsx,cgerfsx,cherfsx,cporfsx,csyrfsx, zgbrfsx,zgerfsx,zherfsx,zporfsx,zsyrfsx due to TRANSFER intrinsic
    LAPACK-TEST currently shows failures in ?gelsd only observed with gcc7.5.0
    need to update most files to support INTERFACE64 - right now only the absolute minimum needed to run DGESVD (as used to prepare the DGEMM "kernel_regress" test in openblas_utest) is updated as a proof of concept
  • currently does not work with MSVC (which uses structs to represent complex numbers)
    fixes clang64 flang compile failure #3509 and fixes When I compile OpenBLAS with NOFORTRAN=1 some LAPACK (e.g. dpotrf) routines are not available #1284

@mmuetzel
Copy link
Contributor

mmuetzel commented Apr 4, 2022

This would already be very useful for the CLANG* build environments in MSYS2 in its current state.
Do you think it could make sense to disable C_LAPACK for MSVC for now (and maybe fix that in a follow up)?

Copy link
Contributor

@mmuetzel mmuetzel left a comment

Choose a reason for hiding this comment

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

Just some comments on the existing changes. I hope this is helpful.

CMakeLists.txt Outdated
if (NOT NOFORTRAN AND NOT NO_LAPACK)
include("${PROJECT_SOURCE_DIR}/cmake/lapack.cmake")
if (NOT NO_LAPACK)
include("${PROJECT_SOURCE_DIR}/cmake/lapack.cmake")
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Should the whitespace change in line 181 be reverted?

Makefile Outdated
@@ -246,10 +249,10 @@ netlib :

else
netlib : lapack_prebuild
ifeq ($(NOFORTRAN), $(filter 0,$(NOFORTRAN)))
#ifeq ($(NOFORTRAN), $(filter 0,$(NOFORTRAN)))
Copy link
Contributor

Choose a reason for hiding this comment

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

Would this condition be better here?

-ifeq ($(NOFORTRAN), $(filter 0,$(NOFORTRAN)))
+ifneq ($(NO_LAPACK), 1)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Drop the outer ifneq down there you mean ? Agree this should simplify things a bit.

@@ -26,10 +26,15 @@ if(CMAKE_Fortran_COMPILER)
enable_language(Fortran)
else()
if (NOT NO_LAPACK)
message(STATUS "No Fortran compiler found, can build only BLAS but not LAPACK")
message(STATUS "No Fortran compiler found, can build only BLAS and f2c-converted LAPACK")
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Whitespace?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

now fixed with the temporary exclusion of MSVC

if (INTERFACE64)
set (CCOMMON_OPT "${CCOMMON_OPT} -DLAPACK_ILP64")
endif ()
set(TIMER "NONE")
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Intent block by two spaces?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

also fixed with the MSVC changes

@mmuetzel
Copy link
Contributor

mmuetzel commented Apr 9, 2022

Thanks for the recent changes regarding MSVC and C_LAPACK (or rather their mutual exclusivity for the time being).

I noticed the last couple of changes were related to an issue with clang-cl (MSVC) & flang on Windows. IIUC, that is probably because some tests are run now (after #3595 has landed) that have been skipped previously.
Are those failing tests a blocker for this PR?

@martin-frbg
Copy link
Collaborator Author

not a blocker, i just noticed them in the context and wanted to make sure they are unrelated. different pr for that now, will clean up here later when i have time

@martin-frbg martin-frbg changed the title [WIP] Use f2c translations of LAPACK when no Fortran compiler is available Use f2c translations of LAPACK when no Fortran compiler is available Apr 9, 2022
@martin-frbg martin-frbg merged commit b787360 into OpenMathLib:develop Apr 9, 2022
@martin-frbg martin-frbg added this to the 0.3.21 milestone Apr 9, 2022
ioraff pushed a commit to ioraff/OpenBLAS that referenced this pull request May 12, 2022
…penMathLib#3539)

* Add C equivalents of the Fortran routines from Reference-LAPACK as fallbacks, and C_LAPACK variable to trigger their use
@lesteve
Copy link

lesteve commented Apr 3, 2023

translations done with a modified version of the f2clapack script from PRIMME (which in turn based on the one from f2clapack)
and additional hand-editing to work around use of F90 idiom in current LAPACK.

@martin-frbg in case you still your modified f2clapack script easy accessible, I would be interested to take a look at it. I am guessing the PRIMME script you started from is https://github.com/primme/primme/blame/master/R/f2clapack.sh?

In a Pyodide context I have been trying to use OpenBLAS (see pyodide/pyodide#3331 for more details). Being able to look at the f2c conversion script (or even run it if possible) you used for OpenBLAS, may help in some cases to reduce the discrepancy we are seeing between some f2c'ed scipy files and OpenBLAS.

@martin-frbg
Copy link
Collaborator Author

yes that is what I started from, need to clean up a few hacks that I hand-corrected in the converted files afterwards... mostly fixing some of the fortran function macros from the header part of the primme script that had bad variable types and adding implementations for some complex functions

@lesteve
Copy link

lesteve commented Apr 3, 2023

OK so you changed mostly the header part of the primme script and then modified the result by hand?

I was wondering whether you changed the lex part too, in order to fix some signatures (full disclosure I don't understand what the lex part of the script does).

@martin-frbg
Copy link
Collaborator Author

This should be it - sorry for the delay. Obviously some of the changes are OpenBLAS-specific (like the "blasint" typedef) and some of the (complex function) declarations will lead to "unused function" warnings during compilation, so there is certainly still room for improvement
f2clapack.sh.txt

@lesteve
Copy link

lesteve commented Apr 17, 2023

Thanks a lot for the update!

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