From ff1ae7a7c3ab0795d12ff10392ebfefc16e26b30 Mon Sep 17 00:00:00 2001 From: "T.Aoyama" Date: Wed, 21 Aug 2024 04:06:59 +0900 Subject: [PATCH 1/4] fix call to ilaenv --- src/ltl2inv/ilaenv_lauum.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ltl2inv/ilaenv_lauum.cc b/src/ltl2inv/ilaenv_lauum.cc index f150384f..bc95b6e6 100644 --- a/src/ltl2inv/ilaenv_lauum.cc +++ b/src/ltl2inv/ilaenv_lauum.cc @@ -13,7 +13,8 @@ template <> int ilaenv_lauum(uplo_t uplo, int n) \ char uplo_ = uplo2char(uplo); \ int ispec = 1; \ int dummy = 0; \ - return ilaenv_(&ispec, #name, &uplo_, &n, &dummy, &dummy, &dummy); \ + int n_ = n; \ + return ilaenv_(&ispec, #name, &uplo_, &n_, &dummy, &dummy, &dummy); \ } EXPANDMAC( float, SLAUUM ) EXPANDMAC( double, DLAUUM ) From 749c9c101914af6179574ebb92f5e42a45595759 Mon Sep 17 00:00:00 2001 From: "T.Aoyama" Date: Wed, 21 Aug 2024 04:08:06 +0900 Subject: [PATCH 2/4] modify build conditions --- .github/workflows/main.yml | 2 +- config/gcc.cmake | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b49b05fe..82dba41d 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -55,7 +55,7 @@ jobs: ln -s `which gfortran-11` gfortran env PATH=`pwd`:$PATH cmake -DCONFIG=apple -DCMAKE_VERBOSE_MAKEFILE=ON $GITHUB_WORKSPACE else - cmake -DCMAKE_VERBOSE_MAKEFILE=ON $GITHUB_WORKSPACE + cmake -DCONFIG=gcc -DCMAKE_VERBOSE_MAKEFILE=ON $GITHUB_WORKSPACE fi env: HOMEBREW_PREFIX: /opt/homebrew diff --git a/config/gcc.cmake b/config/gcc.cmake index 751912d7..8a15d2dc 100644 --- a/config/gcc.cmake +++ b/config/gcc.cmake @@ -3,4 +3,5 @@ set(CMAKE_C_COMPILER "gcc" CACHE STRING "" FORCE) set(CMAKE_CXX_COMPILER "g++" CACHE STRING "" FORCE) set(CMAKE_C_FLAGS_DEBUG "-g -O0 -Wall -Wformat -Werror=format-security") set(CMAKE_C_FLAGS_RELEASE "-O3 -Wno-unknown-pragmas ") +set(CMAKE_CXX_FLAGS_RELEASE "-O3 -Wno-unknown-pragmas ") set(CMAKE_Fortran_COMPILER "gfortran" CACHE STRING "" FORCE) From ae384ec6b273c607c82aae66fbd67ac2d05ad65a Mon Sep 17 00:00:00 2001 From: "T.Aoyama" Date: Wed, 21 Aug 2024 04:23:03 +0900 Subject: [PATCH 3/4] modify build parameter --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 82dba41d..b49b05fe 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -55,7 +55,7 @@ jobs: ln -s `which gfortran-11` gfortran env PATH=`pwd`:$PATH cmake -DCONFIG=apple -DCMAKE_VERBOSE_MAKEFILE=ON $GITHUB_WORKSPACE else - cmake -DCONFIG=gcc -DCMAKE_VERBOSE_MAKEFILE=ON $GITHUB_WORKSPACE + cmake -DCMAKE_VERBOSE_MAKEFILE=ON $GITHUB_WORKSPACE fi env: HOMEBREW_PREFIX: /opt/homebrew From ef9d66b27b0befed0b38c4284593665bf5188d1c Mon Sep 17 00:00:00 2001 From: "T.Aoyama" Date: Thu, 22 Aug 2024 16:17:19 +0900 Subject: [PATCH 4/4] modify ilaenv_lauum to use wrapped version of ilaenv --- src/ltl2inv/CMakeLists.txt | 2 +- src/ltl2inv/ilaenv.h | 3 +++ src/ltl2inv/ilaenv_lauum.cc | 32 ++++++++++++++++++++++++++++++-- src/ltl2inv/ilaenv_wrap.f90 | 37 +++++++++++++++++++++++++++++++++++++ 4 files changed, 71 insertions(+), 3 deletions(-) create mode 100644 src/ltl2inv/ilaenv_wrap.f90 diff --git a/src/ltl2inv/CMakeLists.txt b/src/ltl2inv/CMakeLists.txt index 8aa7141c..88a55025 100644 --- a/src/ltl2inv/CMakeLists.txt +++ b/src/ltl2inv/CMakeLists.txt @@ -11,6 +11,6 @@ endif() include_directories(../common) # TODO: Move blalink_gemmt.c to other subprojects? -add_library(ltl2inv STATIC ltl2inv.cc blalink_gemmt.c ilaenv_lauum.cc) +add_library(ltl2inv STATIC ltl2inv.cc blalink_gemmt.c ilaenv_lauum.cc ilaenv_wrap.f90) target_compile_definitions(ltl2inv PRIVATE -D_CC_IMPL) diff --git a/src/ltl2inv/ilaenv.h b/src/ltl2inv/ilaenv.h index add0a1ed..f4762491 100644 --- a/src/ltl2inv/ilaenv.h +++ b/src/ltl2inv/ilaenv.h @@ -8,7 +8,10 @@ extern "C" { #endif +/* int ilaenv_(const int *ispec, const char *name, const char *opts, const int *n1, const int *n2, const int *n3, const int *n4); +*/ +int ilaenv_wrap(int ispec, const char *name, const char *opts, int n1, int n2, int n3, int n4); #ifdef __cplusplus } diff --git a/src/ltl2inv/ilaenv_lauum.cc b/src/ltl2inv/ilaenv_lauum.cc index bc95b6e6..fa6beaff 100644 --- a/src/ltl2inv/ilaenv_lauum.cc +++ b/src/ltl2inv/ilaenv_lauum.cc @@ -7,15 +7,43 @@ #include "ilaenv.h" #include "ilaenv_lauum.hh" +/* + * sloppy version exploits that + * ILAENV(ispec=1, xLAUUM, "", dummy, dummy, dummy, dummy) + * returns 64 for x=S,D,C,Z . + */ + +#undef SLOPPY_ILAENV +// #define SLOPPY_ILAENV + +/* #define EXPANDMAC(cctype, name) \ template <> int ilaenv_lauum(uplo_t uplo, int n) \ { \ char uplo_ = uplo2char(uplo); \ int ispec = 1; \ int dummy = 0; \ - int n_ = n; \ - return ilaenv_(&ispec, #name, &uplo_, &n_, &dummy, &dummy, &dummy); \ + return ilaenv_(&ispec, #name, &uplo_, &n, &dummy, &dummy, &dummy); \ } +*/ + +#ifndef SLOPPY_ILAENV +#define EXPANDMAC(cctype, name) \ +template <> int ilaenv_lauum(uplo_t uplo, int n) \ +{ \ + char uplo_ = uplo2char(uplo); \ + int ispec = 1; \ + int dummy = -1; \ + return ilaenv_wrap(ispec, #name, &uplo_, n, dummy, dummy, dummy); \ +} +#else +#define EXPANDMAC(cctype, name) \ +template <> int ilaenv_lauum(uplo_t uplo, int n) \ +{ \ + return 64; \ +} +#endif + EXPANDMAC( float, SLAUUM ) EXPANDMAC( double, DLAUUM ) EXPANDMAC( ccscmplx, CLAUUM ) diff --git a/src/ltl2inv/ilaenv_wrap.f90 b/src/ltl2inv/ilaenv_wrap.f90 new file mode 100644 index 00000000..f4e62167 --- /dev/null +++ b/src/ltl2inv/ilaenv_wrap.f90 @@ -0,0 +1,37 @@ +module wrapper + use, intrinsic :: iso_c_binding + implicit none +contains + function c_charptr_to_f_charptr(ccp) result(result) + type(c_ptr),intent(in),value :: ccp + character(:,c_char),pointer :: result + interface + function strlen(p) bind(c) + import c_ptr, c_size_t + type(c_ptr),value :: p + integer(c_size_t) strlen + end function strlen + end interface + result => convert_cptr(ccp,strlen(ccp)) + contains + function convert_cptr(p, len) + type(c_ptr),intent(in) :: p + integer(c_size_t),intent(in) :: len + character(len, c_char),pointer :: convert_cptr + call c_f_pointer(p, convert_cptr) + end function convert_cptr + end function c_charptr_to_f_charptr + + integer function ilaenv_wrap(ispec, name, opts, n1, n2, n3, n4) bind(c, name="ilaenv_wrap") + implicit none + integer,intent(in),value :: ispec, n1, n2, n3, n4 + type(c_ptr),intent(in),value :: name, opts + character(:,c_char),pointer :: namef, optsf + integer ilaenv + + namef => c_charptr_to_f_charptr(name) + optsf => c_charptr_to_f_charptr(opts) + + ilaenv_wrap = ILAENV(ispec, namef, optsf, n1, n2, n3, n4) + end function ilaenv_wrap +end module wrapper