From 49bbf330ca592f439a07f24f137e61af1cc9c616 Mon Sep 17 00:00:00 2001 From: Martin Kroeker Date: Sun, 18 Jul 2021 22:19:19 +0200 Subject: [PATCH 1/3] Empirical workaround for numpy SVD NaN problem from issue 3318 --- kernel/Makefile.L2 | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/kernel/Makefile.L2 b/kernel/Makefile.L2 index 888a9b9594..ac53c29c34 100644 --- a/kernel/Makefile.L2 +++ b/kernel/Makefile.L2 @@ -1,3 +1,10 @@ +FMAFLAG= +ifndef OLDGCC +ifdef HAVE_FMA3 +FMAFLAG = -mfma +endif +endif + ### GEMV ### ifndef SGEMVNKERNEL @@ -263,7 +270,7 @@ $(KDIR)dgemv_n$(TSUFFIX).$(SUFFIX) $(KDIR)dgemv_n$(TSUFFIX).$(PSUFFIX) : $(KER $(CC) -c $(CFLAGS) -DDOUBLE -UCOMPLEX -UTRANS $< -o $@ $(KDIR)dgemv_t$(TSUFFIX).$(SUFFIX) $(KDIR)dgemv_t$(TSUFFIX).$(PSUFFIX) : $(KERNELDIR)/$(DGEMVTKERNEL) $(TOPDIR)/common.h $(GEMVDEP) - $(CC) -c $(CFLAGS) -DDOUBLE -UCOMPLEX -DTRANS $< -o $@ + $(CC) -c $(CFLAGS) $(FMAFLAG) -DDOUBLE -UCOMPLEX -DTRANS $< -o $@ endif $(KDIR)qgemv_n$(TSUFFIX).$(SUFFIX) $(KDIR)qgemv_n$(TSUFFIX).$(PSUFFIX) : $(KERNELDIR)/$(QGEMVNKERNEL) From 30f23be0f94c7041b7e3bb53a4a0236355cdabad Mon Sep 17 00:00:00 2001 From: Martin Kroeker Date: Thu, 22 Jul 2021 12:00:03 +0200 Subject: [PATCH 2/3] Rework setting of -mfma to only apply it where necessary --- cmake/cc.cmake | 6 +++--- cmake/system.cmake | 10 +++++----- cmake/utils.cmake | 10 +++++++++- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/cmake/cc.cmake b/cmake/cc.cmake index 76952152b6..ac5e455d55 100644 --- a/cmake/cc.cmake +++ b/cmake/cc.cmake @@ -124,9 +124,9 @@ if (NOT DYNAMIC_ARCH) if (HAVE_AVX) set (CCOMMON_OPT "${CCOMMON_OPT} -mavx") endif () - if (HAVE_FMA3) - set (CCOMMON_OPT "${CCOMMON_OPT} -mfma") - endif () + # if (HAVE_FMA3) + #set (CCOMMON_OPT "${CCOMMON_OPT} -mfma") + #endif () if (HAVE_SSE) set (CCOMMON_OPT "${CCOMMON_OPT} -msse") endif () diff --git a/cmake/system.cmake b/cmake/system.cmake index 34874827c5..f8bd6678ec 100644 --- a/cmake/system.cmake +++ b/cmake/system.cmake @@ -186,11 +186,11 @@ if (DEFINED TARGET) set (KERNEL_DEFINITIONS "${KERNEL_DEFINITIONS} -mavx2") endif() endif() - if (DEFINED HAVE_FMA3) - if (NOT NO_AVX2) - set (KERNEL_DEFINITIONS "${KERNEL_DEFINITIONS} -mfma") - endif() - endif() + # if (DEFINED HAVE_FMA3) + # if (NOT NO_AVX2) + # set (KERNEL_DEFINITIONS "${KERNEL_DEFINITIONS} -mfma") + # endif() + # endif() if (DEFINED HAVE_SSE) set (KERNEL_DEFINITIONS "${KERNEL_DEFINITIONS} -msse") endif() diff --git a/cmake/utils.cmake b/cmake/utils.cmake index 794d73d06d..2c1a1c763a 100644 --- a/cmake/utils.cmake +++ b/cmake/utils.cmake @@ -311,7 +311,15 @@ function(GenerateNamedObjects sources_in) configure_file(${new_source_file}.tmp ${new_source_file} COPYONLY) file(REMOVE ${new_source_file}.tmp) list(APPEND SRC_LIST_OUT ${new_source_file}) - + message (STATUS ${new_source_file}) + if (DEFINED HAVE_FMA3) + if ( ${new_source_file} MATCHES "(s|d?)rot_k.c") + set_source_files_properties(${new_source_file} PROPERTIES COMPILE_OPTIONS "-mfma") + endif () + if ( ${new_source_file} MATCHES "dgemv_t_k.c") + set_source_files_properties(${new_source_file} PROPERTIES COMPILE_OPTIONS "-mfma") + endif () + endif () endforeach () endforeach () From 47ba85f314808476c8254779389607f9af60231f Mon Sep 17 00:00:00 2001 From: Martin Kroeker Date: Thu, 22 Jul 2021 17:24:15 +0200 Subject: [PATCH 3/3] Fix regex to match kernels suffixed with cpuname too --- cmake/utils.cmake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmake/utils.cmake b/cmake/utils.cmake index 2c1a1c763a..6b54092eac 100644 --- a/cmake/utils.cmake +++ b/cmake/utils.cmake @@ -313,10 +313,10 @@ function(GenerateNamedObjects sources_in) list(APPEND SRC_LIST_OUT ${new_source_file}) message (STATUS ${new_source_file}) if (DEFINED HAVE_FMA3) - if ( ${new_source_file} MATCHES "(s|d?)rot_k.c") + if ( ${new_source_file} MATCHES "(s|d?)rot_k.*c") set_source_files_properties(${new_source_file} PROPERTIES COMPILE_OPTIONS "-mfma") endif () - if ( ${new_source_file} MATCHES "dgemv_t_k.c") + if ( ${new_source_file} MATCHES "dgemv_t_k.*c") set_source_files_properties(${new_source_file} PROPERTIES COMPILE_OPTIONS "-mfma") endif () endif ()