Fix cooperlake and sapphire rapids march flags on clang

The march=cooperlake and march=sapphirerapids flags were never getting
added when building with Clang targetting those architectures. Instead
it was falling back to the skylake AVX512 implementation.

Clang added support for these two architectures in Clang 9 and Clang 12,
so introduce new checks for those versions to enable the appropriate
march flag, and fallback to skylake otherwise.
This commit is contained in:
Ian McInerney 2023-08-14 15:41:28 +01:00
parent 562ef5fdca
commit 8a8a8479be
3 changed files with 57 additions and 26 deletions

View File

@ -384,6 +384,11 @@ GCCMINORVERSIONGTEQ4 := $(shell expr `$(CC) $(GCCDUMPVERSION_PARAM) | cut -f2 -d
GCCMINORVERSIONGTEQ7 := $(shell expr `$(CC) $(GCCDUMPVERSION_PARAM) | cut -f2 -d.` \>= 7) GCCMINORVERSIONGTEQ7 := $(shell expr `$(CC) $(GCCDUMPVERSION_PARAM) | cut -f2 -d.` \>= 7)
endif endif
ifeq ($(C_COMPILER), CLANG)
CLANGVERSIONGTEQ9 := $(shell expr `$(CC) -dumpversion | cut -f1 -d.` \>= 9)
CLANGVERSIONGTEQ12 := $(shell expr `$(CC) -dumpversion | cut -f1 -d.` \>= 12)
endif
# #
# OS dependent settings # OS dependent settings
# #

View File

@ -75,18 +75,31 @@ endif
ifeq ($(CORE), COOPERLAKE) ifeq ($(CORE), COOPERLAKE)
ifndef NO_AVX512 ifndef NO_AVX512
ifeq ($(C_COMPILER), GCC) ifeq ($(C_COMPILER), GCC)
# cooperlake support was added in 10.1 # cooperlake support was added in 10.1
ifeq ($(GCCVERSIONGTEQ10)$(GCCMINORVERSIONGTEQ1), 11) ifeq ($(GCCVERSIONGTEQ10)$(GCCMINORVERSIONGTEQ1), 11)
CCOMMON_OPT += -march=cooperlake CCOMMON_OPT += -march=cooperlake
ifneq ($(F_COMPILER), NAG) ifneq ($(F_COMPILER), NAG)
FCOMMON_OPT += -march=cooperlake FCOMMON_OPT += -march=cooperlake
endif endif
else # gcc not support, fallback to avx512 else # gcc not support, fallback to avx512
CCOMMON_OPT += -march=skylake-avx512 CCOMMON_OPT += -march=skylake-avx512
ifneq ($(F_COMPILER), NAG) ifneq ($(F_COMPILER), NAG)
FCOMMON_OPT += -march=skylake-avx512 FCOMMON_OPT += -march=skylake-avx512
endif endif
endif endif
else ifeq ($(C_COMPILER), CLANG)
# cooperlake support was added in clang 9
ifeq ($(CLANGVERSIONGTEQ9), 1)
CCOMMON_OPT += -march=cooperlake
ifneq ($(F_COMPILER), NAG)
FCOMMON_OPT += -march=cooperlake
endif
else # not supported in clang, fallback to avx512
CCOMMON_OPT += -march=skylake-avx512
ifneq ($(F_COMPILER), NAG)
FCOMMON_OPT += -march=skylake-avx512
endif
endif
endif endif
ifeq ($(OSNAME), CYGWIN_NT) ifeq ($(OSNAME), CYGWIN_NT)
CCOMMON_OPT += -fno-asynchronous-unwind-tables CCOMMON_OPT += -fno-asynchronous-unwind-tables
@ -104,18 +117,31 @@ endif
ifeq ($(CORE), SAPPHIRERAPIDS) ifeq ($(CORE), SAPPHIRERAPIDS)
ifndef NO_AVX512 ifndef NO_AVX512
ifeq ($(C_COMPILER), GCC) ifeq ($(C_COMPILER), GCC)
# sapphire rapids support was added in 11 # sapphire rapids support was added in 11
ifeq ($(GCCVERSIONGTEQ11), 1) ifeq ($(GCCVERSIONGTEQ11), 1)
CCOMMON_OPT += -march=sapphirerapids CCOMMON_OPT += -march=sapphirerapids
ifneq ($(F_COMPILER), NAG) ifneq ($(F_COMPILER), NAG)
FCOMMON_OPT += -march=sapphirerapids FCOMMON_OPT += -march=sapphirerapids
endif endif
else # gcc not support, fallback to avx512 else # gcc not support, fallback to avx512
CCOMMON_OPT += -march=skylake-avx512 CCOMMON_OPT += -march=skylake-avx512
ifneq ($(F_COMPILER), NAG) ifneq ($(F_COMPILER), NAG)
FCOMMON_OPT += -march=skylake-avx512 FCOMMON_OPT += -march=skylake-avx512
endif endif
endif endif
else ifeq ($(C_COMPILER), CLANG)
# cooperlake support was added in clang 12
ifeq ($(CLANGVERSIONGTEQ12), 1)
CCOMMON_OPT += -march=cooperlake
ifneq ($(F_COMPILER), NAG)
FCOMMON_OPT += -march=cooperlake
endif
else # not supported in clang, fallback to avx512
CCOMMON_OPT += -march=skylake-avx512
ifneq ($(F_COMPILER), NAG)
FCOMMON_OPT += -march=skylake-avx512
endif
endif
endif endif
ifeq ($(OSNAME), CYGWIN_NT) ifeq ($(OSNAME), CYGWIN_NT)
CCOMMON_OPT += -fno-asynchronous-unwind-tables CCOMMON_OPT += -fno-asynchronous-unwind-tables

View File

@ -33,7 +33,7 @@ endif
ifdef TARGET_CORE ifdef TARGET_CORE
ifeq ($(TARGET_CORE), SAPPHIRERAPIDS) ifeq ($(TARGET_CORE), SAPPHIRERAPIDS)
override CFLAGS += -DBUILD_KERNEL -DTABLE_NAME=gotoblas_$(TARGET_CORE) override CFLAGS += -DBUILD_KERNEL -DTABLE_NAME=gotoblas_$(TARGET_CORE)
ifeq ($(GCCVERSIONGTEQ11), 1) ifeq (1, $(filter 1,$(GCCVERSIONGTEQ11) $(CLANGVERSIONGTEQ12)))
override CFLAGS += -march=sapphirerapids override CFLAGS += -march=sapphirerapids
else else
override CFLAGS += -march=skylake-avx512 -mavx512f override CFLAGS += -march=skylake-avx512 -mavx512f
@ -48,7 +48,7 @@ ifeq ($(TARGET_CORE), SAPPHIRERAPIDS)
endif endif
else ifeq ($(TARGET_CORE), COOPERLAKE) else ifeq ($(TARGET_CORE), COOPERLAKE)
override CFLAGS += -DBUILD_KERNEL -DTABLE_NAME=gotoblas_$(TARGET_CORE) override CFLAGS += -DBUILD_KERNEL -DTABLE_NAME=gotoblas_$(TARGET_CORE)
ifeq ($(GCCVERSIONGTEQ10), 1) ifeq (1, $(filter 1,$(GCCVERSIONGTEQ10) $(CLANGVERSIONGTEQ9)))
override CFLAGS += -march=cooperlake override CFLAGS += -march=cooperlake
else else
override CFLAGS += -march=skylake-avx512 -mavx512f override CFLAGS += -march=skylake-avx512 -mavx512f