Skip to content

Commit a270894

Browse files
authored
Merge pull request #2829 from mhillenibm/clang_s390x
Fix DYNAMIC_ARCH=1 with clang s390x
2 parents 15da2f9 + 047b8d7 commit a270894

File tree

4 files changed

+61
-47
lines changed

4 files changed

+61
-47
lines changed

.travis.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,18 @@ matrix:
4343
- TARGET_BOX=IBMZ_LINUX
4444
- BTYPE="BINARY=64 USE_OPENMP=1"
4545

46+
- <<: *test-ubuntu
47+
os: linux
48+
dist: focal
49+
arch: s390x
50+
compiler: clang
51+
before_script:
52+
- COMMON_FLAGS="DYNAMIC_ARCH=1 TARGET=Z13 NUM_THREADS=32"
53+
env:
54+
# for matrix annotation only
55+
- TARGET_BOX=IBMZ_LINUX
56+
- BTYPE="BINARY=64 USE_OPENMP=0 CC=clang"
57+
4658
- <<: *test-ubuntu
4759
env:
4860
- TARGET_BOX=LINUX64

CONTRIBUTORS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ In chronological order:
187187
* Marius Hillenbrand <https://github.com/mhillenibm>
188188
* [2020-05-12] Revise dynamic architecture detection for IBM z
189189
* [2020-05-12] Add new sgemm and strmm kernel for IBM z14
190+
* [2020-09-07] Fix builds with clang on IBM z, including dynamic architecture support
190191

191192
* Danfeng Zhang <https://github.com/craft-zhang>
192193
* [2020-05-20] Improve performance of SGEMM and STRMM on Arm Cortex-A53

Makefile.system

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,6 @@ endif
295295
ifeq ($(C_COMPILER), GCC)
296296
GCCVERSIONGTEQ4 := $(shell expr `$(CC) -dumpversion | cut -f1 -d.` \>= 4)
297297
GCCVERSIONGT4 := $(shell expr `$(CC) -dumpversion | cut -f1 -d.` \> 4)
298-
GCCVERSIONEQ5 := $(shell expr `$(CC) -dumpversion | cut -f1 -d.` = 5)
299298
GCCVERSIONGT5 := $(shell expr `$(CC) -dumpversion | cut -f1 -d.` \> 5)
300299
GCCVERSIONGTEQ7 := $(shell expr `$(CC) -dumpversion | cut -f1 -d.` \>= 7)
301300
GCCVERSIONGTEQ9 := $(shell expr `$(CC) -dumpversion | cut -f1 -d.` \>= 9)
@@ -594,34 +593,36 @@ endif
594593
ifeq ($(ARCH), zarch)
595594
DYNAMIC_CORE = ZARCH_GENERIC
596595

597-
# Z13 is supported since gcc-5.2, gcc-6, and in RHEL 7.3 and newer
598-
ifeq ($(GCCVERSIONGT5), 1)
599-
ZARCH_SUPPORT_Z13 := 1
600-
else ifeq ($(GCCVERSIONEQ5), 1)
601-
ifeq ($(GCCMINORVERSIONGTEQ2), 1)
602-
ZARCH_SUPPORT_Z13 := 1
603-
endif
604-
endif
605-
606-
ifeq ($(wildcard /etc/redhat-release), /etc/redhat-release)
607-
ifeq ($(shell source /etc/os-release ; expr $$VERSION_ID \>= "7.3"), 1)
608-
ZARCH_SUPPORT_Z13 := 1
609-
endif
610-
endif
611-
612-
ifeq ($(ZARCH_SUPPORT_Z13), 1)
596+
# if the compiler accepts -march=arch11 or -march=z13 and can compile a file
597+
# with z13-specific inline assembly, then we can include support for Z13.
598+
# note: -march=z13 is equivalent to -march=arch11 yet some compiler releases
599+
# only support one or the other.
600+
# note: LLVM version 6.x supported -march=z13 yet could not handle vector
601+
# registers in inline assembly, so the check for supporting the -march flag is
602+
# not enough.
603+
ZARCH_TEST_COMPILE=-c $(TOPDIR)/kernel/zarch/damin_z13.c -I$(TOPDIR) -o /dev/null > /dev/null 2> /dev/null
604+
ZARCH_CC_SUPPORTS_ARCH11=$(shell $(CC) -march=arch11 $(ZARCH_TEST_COMPILE) && echo 1)
605+
ZARCH_CC_SUPPORTS_Z13=$(shell $(CC) -march=z13 $(ZARCH_TEST_COMPILE) && echo 1)
606+
607+
ifeq ($(or $(ZARCH_CC_SUPPORTS_ARCH11), $(ZARCH_CC_SUPPORTS_Z13)), 1)
613608
DYNAMIC_CORE += Z13
609+
CCOMMON_OPT += -DDYN_Z13
614610
else
615-
$(info OpenBLAS: Not building Z13 kernels because gcc is older than 5.2 or 6.x)
611+
$(info OpenBLAS: Not building Z13 kernels because the compiler $(CC) does not support it)
616612
endif
617613

618-
ifeq ($(GCCVERSIONGTEQ7), 1)
614+
# as above for z13, check for -march=arch12 and z14 support in the compiler.
615+
ZARCH_CC_SUPPORTS_ARCH12=$(shell $(CC) -march=arch12 $(ZARCH_TEST_COMPILE) && echo 1)
616+
ZARCH_CC_SUPPORTS_Z14=$(shell $(CC) -march=z14 $(ZARCH_TEST_COMPILE) && echo 1)
617+
ifeq ($(or $(ZARCH_CC_SUPPORTS_ARCH12), $(ZARCH_CC_SUPPORTS_Z14)), 1)
619618
DYNAMIC_CORE += Z14
619+
CCOMMON_OPT += -DDYN_Z14
620620
else
621-
$(info OpenBLAS: Not building Z14 kernels because gcc is older than 7.x)
622-
endif
621+
$(info OpenBLAS: Not building Z14 kernels because the compiler $(CC) does not support it)
623622
endif
624623

624+
endif # ARCH zarch
625+
625626
ifeq ($(ARCH), power)
626627
DYNAMIC_CORE = POWER6
627628
DYNAMIC_CORE += POWER8

driver/others/dynamic_zarch.c

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,6 @@
11
#include "common.h"
22
#include <stdbool.h>
33

4-
// Gate kernels for z13 and z14 on gcc version
5-
#if (__GNUC__ == 5 && __GNUC_MINOR__ >= 2) || __GNUC__ >= 6 || \
6-
/* RHEL 7 since 7.3: */ \
7-
(__GNUC__ == 4 && __GNUC_MINOR__ == 8 && __GNUC_PATCHLEVEL__ == 5 && \
8-
__GNUC_RH_RELEASE__ >= 11)
9-
#define HAVE_Z13_SUPPORT
10-
#endif
11-
12-
#if __GNUC__ >= 7
13-
#define HAVE_Z14_SUPPORT
14-
#endif
15-
164
// Guard the use of getauxval() on glibc version >= 2.16
175
#ifdef __GLIBC__
186
#include <features.h>
@@ -47,10 +35,10 @@ static unsigned long get_hwcap(void) {
4735
#endif // __GLIBC
4836

4937
extern gotoblas_t gotoblas_ZARCH_GENERIC;
50-
#ifdef HAVE_Z13_SUPPORT
38+
#ifdef DYN_Z13
5139
extern gotoblas_t gotoblas_Z13;
5240
#endif
53-
#ifdef HAVE_Z14_SUPPORT
41+
#ifdef DYN_Z14
5442
extern gotoblas_t gotoblas_Z14;
5543
#endif
5644

@@ -66,17 +54,21 @@ static char* corename[] = {
6654
};
6755

6856
char* gotoblas_corename(void) {
69-
#ifdef HAVE_Z13_SUPPORT
57+
#ifdef DYN_Z13
7058
if (gotoblas == &gotoblas_Z13) return corename[1];
7159
#endif
72-
#ifdef HAVE_Z14_SUPPORT
60+
#ifdef DYN_Z14
7361
if (gotoblas == &gotoblas_Z14) return corename[2];
7462
#endif
7563
if (gotoblas == &gotoblas_ZARCH_GENERIC) return corename[3];
7664

7765
return corename[0];
7866
}
7967

68+
#ifndef HWCAP_S390_VXE
69+
#define HWCAP_S390_VXE 8192
70+
#endif
71+
8072
/**
8173
* Detect the fitting set of kernels by retrieving the CPU features supported by
8274
* OS from the auxiliary value AT_HWCAP and choosing the set of kernels
@@ -89,15 +81,15 @@ static gotoblas_t* get_coretype(void) {
8981

9082
unsigned long hwcap __attribute__((unused)) = get_hwcap();
9183

84+
#ifdef DYN_Z14
9285
// z14 and z15 systems: exploit Vector Facility (SIMD) and
9386
// Vector-Enhancements Facility 1 (float SIMD instructions), if present.
94-
#ifdef HAVE_Z14_SUPPORT
9587
if ((hwcap & HWCAP_S390_VX) && (hwcap & HWCAP_S390_VXE))
9688
return &gotoblas_Z14;
9789
#endif
9890

91+
#ifdef DYN_Z13
9992
// z13: Vector Facility (SIMD for double)
100-
#ifdef HAVE_Z13_SUPPORT
10193
if (hwcap & HWCAP_S390_VX)
10294
return &gotoblas_Z13;
10395
#endif
@@ -123,19 +115,27 @@ static gotoblas_t* force_coretype(char* coretype) {
123115
}
124116
}
125117

126-
switch (found)
127-
{
128-
#ifdef HAVE_Z13_SUPPORT
129-
case 1: return (&gotoblas_Z13);
118+
if (found == 1) {
119+
#ifdef DYN_Z13
120+
return &gotoblas_Z13;
121+
#else
122+
openblas_warning(1, "Z13 support not compiled in");
123+
return NULL;
130124
#endif
131-
#ifdef HAVE_Z14_SUPPORT
132-
case 2: return (&gotoblas_Z14);
125+
} else if (found == 2) {
126+
#ifdef DYN_Z14
127+
return &gotoblas_Z14;
128+
#else
129+
openblas_warning(1, "Z14 support not compiled in");
130+
return NULL;
133131
#endif
134-
case 3: return (&gotoblas_ZARCH_GENERIC);
135-
default: return NULL;
132+
} else if (found == 3) {
133+
return &gotoblas_ZARCH_GENERIC;
136134
}
135+
137136
snprintf(message, 128, "Core not found: %s\n", coretype);
138137
openblas_warning(1, message);
138+
return NULL;
139139
}
140140

141141
void gotoblas_dynamic_init(void) {

0 commit comments

Comments
 (0)