Skip to content

Commit dd43661

Browse files
committed
Init IBM z system (s390x) porting.
1 parent 9253dad commit dd43661

File tree

12 files changed

+467
-4
lines changed

12 files changed

+467
-4
lines changed

Makefile.zarch

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
ifeq ($(CORE), Z13)
3+
CCOMMON_OPT += -march=z13
4+
FCOMMON_OPT += -march=z13
5+
endif
6+

c_check

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ $hostarch = "x86_64" if ($hostarch eq "amd64");
77
$hostarch = "arm" if ($hostarch =~ /^arm.*/);
88
$hostarch = "arm64" if ($hostarch eq "aarch64");
99
$hostarch = "power" if ($hostarch =~ /^(powerpc|ppc).*/);
10+
$hostarch = "zarch" if ($hostarch eq "s390x");
1011

1112
$binary = $ENV{"BINARY"};
1213

@@ -70,6 +71,7 @@ $architecture = sparc if ($data =~ /ARCH_SPARC/);
7071
$architecture = ia64 if ($data =~ /ARCH_IA64/);
7172
$architecture = arm if ($data =~ /ARCH_ARM/);
7273
$architecture = arm64 if ($data =~ /ARCH_ARM64/);
74+
$architecture = zarch if ($data =~ /ARCH_ZARCH/);
7375

7476
$defined = 0;
7577

@@ -89,6 +91,11 @@ if (($architecture eq "arm") || ($architecture eq "arm64")) {
8991
$defined = 1;
9092
}
9193

94+
if ($architecture eq "zarch") {
95+
$defined = 1;
96+
$binary = 64;
97+
}
98+
9299
if ($architecture eq "alpha") {
93100
$defined = 1;
94101
$binary = 64;
@@ -162,6 +169,7 @@ $architecture = sparc if ($data =~ /ARCH_SPARC/);
162169
$architecture = ia64 if ($data =~ /ARCH_IA64/);
163170
$architecture = arm if ($data =~ /ARCH_ARM/);
164171
$architecture = arm64 if ($data =~ /ARCH_ARM64/);
172+
$architecture = zarch if ($data =~ /ARCH_ZARCH/);
165173

166174
$binformat = bin32;
167175
$binformat = bin64 if ($data =~ /BINARY_64/);

common.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,10 @@ please https://github.com/xianyi/OpenBLAS/issues/246
409409
#include "common_arm64.h"
410410
#endif
411411

412+
#ifdef ARCH_ZARCH
413+
#include "common_zarch.h"
414+
#endif
415+
412416
#ifndef ASSEMBLER
413417
#ifdef OS_WINDOWS
414418
typedef char env_var_t[MAX_PATH];

common_linux.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ extern long int syscall (long int __sysno, ...);
7070
static inline int my_mbind(void *addr, unsigned long len, int mode,
7171
unsigned long *nodemask, unsigned long maxnode,
7272
unsigned flags) {
73-
#if defined (__LSB_VERSION__)
73+
#if defined (__LSB_VERSION__) || defined(ARCH_ZARCH)
7474
// So far, LSB (Linux Standard Base) don't support syscall().
7575
// https://lsbbugs.linuxfoundation.org/show_bug.cgi?id=3482
7676
return 0;
@@ -90,7 +90,7 @@ static inline int my_mbind(void *addr, unsigned long len, int mode,
9090
}
9191

9292
static inline int my_set_mempolicy(int mode, const unsigned long *addr, unsigned long flag) {
93-
#if defined (__LSB_VERSION__)
93+
#if defined (__LSB_VERSION__) || defined(ARCH_ZARCH)
9494
// So far, LSB (Linux Standard Base) don't support syscall().
9595
// https://lsbbugs.linuxfoundation.org/show_bug.cgi?id=3482
9696
return 0;

common_zarch.h

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
/*****************************************************************************
2+
Copyright (c) 2011-2016, The OpenBLAS Project
3+
All rights reserved.
4+
5+
Redistribution and use in source and binary forms, with or without
6+
modification, are permitted provided that the following conditions are
7+
met:
8+
9+
1. Redistributions of source code must retain the above copyright
10+
notice, this list of conditions and the following disclaimer.
11+
12+
2. Redistributions in binary form must reproduce the above copyright
13+
notice, this list of conditions and the following disclaimer in
14+
the documentation and/or other materials provided with the
15+
distribution.
16+
3. Neither the name of the OpenBLAS project nor the names of
17+
its contributors may be used to endorse or promote products
18+
derived from this software without specific prior written
19+
permission.
20+
21+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24+
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
25+
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
30+
USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31+
**********************************************************************************/
32+
33+
#ifndef COMMON_ZARCH
34+
#define COMMON_ZARCH
35+
36+
#define MB
37+
//__asm__ __volatile__ ("dmb ish" : : : "memory")
38+
#define WMB
39+
//__asm__ __volatile__ ("dmb ishst" : : : "memory")
40+
41+
42+
#define INLINE inline
43+
44+
#define RETURN_BY_COMPLEX
45+
46+
#ifndef ASSEMBLER
47+
48+
/*
49+
static void __inline blas_lock(volatile BLASULONG *address){
50+
51+
BLASULONG ret;
52+
53+
do {
54+
while (*address) {YIELDING;};
55+
56+
__asm__ __volatile__(
57+
"mov x4, #1 \n\t"
58+
"1: \n\t"
59+
"ldaxr x2, [%1] \n\t"
60+
"cbnz x2, 1b \n\t"
61+
"2: \n\t"
62+
"stxr w3, x4, [%1] \n\t"
63+
"cbnz w3, 1b \n\t"
64+
"mov %0, #0 \n\t"
65+
: "=r"(ret), "=r"(address)
66+
: "1"(address)
67+
: "memory", "x2" , "x3", "x4"
68+
69+
70+
);
71+
72+
73+
} while (ret);
74+
75+
}
76+
*/
77+
//#define BLAS_LOCK_DEFINED
78+
79+
80+
81+
static inline int blas_quickdivide(blasint x, blasint y){
82+
return x / y;
83+
}
84+
85+
#if defined(DOUBLE)
86+
#define GET_IMAGE(res) __asm__ __volatile__("str d1, %0" : "=m"(res) : : "memory")
87+
#else
88+
#define GET_IMAGE(res) __asm__ __volatile__("str s1, %0" : "=m"(res) : : "memory")
89+
#endif
90+
91+
#define GET_IMAGE_CANCEL
92+
93+
#endif
94+
95+
96+
#ifndef F_INTERFACE
97+
#define REALNAME ASMNAME
98+
#else
99+
#define REALNAME ASMFNAME
100+
#endif
101+
102+
#if defined(ASSEMBLER) && !defined(NEEDPARAM)
103+
104+
#define PROLOGUE \
105+
.text ;\
106+
.align 4 ;\
107+
.global REALNAME ;\
108+
.type REALNAME, %function ;\
109+
REALNAME:
110+
111+
#define EPILOGUE
112+
113+
#define PROFCODE
114+
115+
#endif
116+
117+
118+
#define SEEK_ADDRESS
119+
120+
#ifndef PAGESIZE
121+
#define PAGESIZE ( 4 << 10)
122+
#endif
123+
#define HUGE_PAGESIZE ( 4 << 20)
124+
125+
#if defined(CORTEXA57)
126+
#define BUFFER_SIZE (20 << 20)
127+
#else
128+
#define BUFFER_SIZE (16 << 20)
129+
#endif
130+
131+
132+
#define BASE_ADDRESS (START_ADDRESS - BUFFER_SIZE * MAX_CPU_NUMBER)
133+
134+
#ifndef MAP_ANONYMOUS
135+
#define MAP_ANONYMOUS MAP_ANON
136+
#endif
137+
138+
#endif
139+

cpuid_zarch.c

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/**************************************************************************
2+
Copyright (c) 2016, The OpenBLAS Project
3+
All rights reserved.
4+
Redistribution and use in source and binary forms, with or without
5+
modification, are permitted provided that the following conditions are
6+
met:
7+
1. Redistributions of source code must retain the above copyright
8+
notice, this list of conditions and the following disclaimer.
9+
2. Redistributions in binary form must reproduce the above copyright
10+
notice, this list of conditions and the following disclaimer in
11+
the documentation and/or other materials provided with the
12+
distribution.
13+
3. Neither the name of the OpenBLAS project nor the names of
14+
its contributors may be used to endorse or promote products
15+
derived from this software without specific prior written permission.
16+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19+
ARE DISCLAIMED. IN NO EVENT SHALL THE OPENBLAS PROJECT OR CONTRIBUTORS BE
20+
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
25+
USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+
*****************************************************************************/
27+
28+
#include <string.h>
29+
30+
#define CPU_GENERIC 0
31+
#define CPU_Z13 1
32+
33+
static char *cpuname[] = {
34+
"ZARCH_GENERIC",
35+
"Z13"
36+
};
37+
38+
static char *cpuname_lower[] = {
39+
"zarch_generic",
40+
"z13"
41+
};
42+
43+
int detect(void)
44+
{
45+
return CPU_GENERIC;
46+
}
47+
48+
void get_libname(void)
49+
{
50+
51+
int d = detect();
52+
printf("%s", cpuname_lower[d]);
53+
}
54+
55+
char *get_corename(void)
56+
{
57+
return cpuname[detect()];
58+
}
59+
60+
void get_architecture(void)
61+
{
62+
printf("ZARCH");
63+
}
64+
65+
void get_subarchitecture(void)
66+
{
67+
int d = detect();
68+
printf("%s", cpuname[d]);
69+
}
70+
71+
void get_subdirname(void)
72+
{
73+
printf("zarch");
74+
}
75+
76+
77+
void get_cpuconfig(void)
78+
{
79+
80+
int d = detect();
81+
switch (d){
82+
case CPU_GENERIC:
83+
printf("#define ZARCH_GENERIC\n");
84+
printf("#define DTB_DEFAULT_ENTRIES 64\n");
85+
break;
86+
case CPU_Z13:
87+
printf("#define Z13\n");
88+
printf("#define DTB_DEFAULT_ENTRIES 64\n");
89+
break;
90+
}
91+
}

ctest.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ ARCH_X86_64
105105
ARCH_POWER
106106
#endif
107107

108+
#if defined(__s390x__) || defined(__zarch__)
109+
ARCH_ZARCH
110+
#endif
111+
108112
#ifdef __mips64
109113
ARCH_MIPS64
110114
#endif

getarch.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -862,6 +862,12 @@ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
862862
#define OPENBLAS_SUPPORTED
863863
#endif
864864

865+
#if defined(__zarch__) || defined(__s390x__)
866+
#define ZARCH
867+
#include "cpuid_zarch.c"
868+
#define OPENBLAS_SUPPORTED
869+
#endif
870+
865871
#ifdef INTEL_AMD
866872
#include "cpuid_x86.c"
867873
#define OPENBLAS_SUPPORTED
@@ -957,7 +963,7 @@ int main(int argc, char *argv[]){
957963
#ifdef FORCE
958964
printf("CORE=%s\n", CORENAME);
959965
#else
960-
#if defined(INTEL_AMD) || defined(POWER) || defined(__mips__) || defined(__arm__) || defined(__aarch64__)
966+
#if defined(INTEL_AMD) || defined(POWER) || defined(__mips__) || defined(__arm__) || defined(__aarch64__) || defined(ZARCH)
961967
printf("CORE=%s\n", get_corename());
962968
#endif
963969
#endif
@@ -1064,7 +1070,7 @@ int main(int argc, char *argv[]){
10641070
#ifdef FORCE
10651071
printf("#define CHAR_CORENAME \"%s\"\n", CORENAME);
10661072
#else
1067-
#if defined(INTEL_AMD) || defined(POWER) || defined(__mips__) || defined(__arm__) || defined(__aarch64__)
1073+
#if defined(INTEL_AMD) || defined(POWER) || defined(__mips__) || defined(__arm__) || defined(__aarch64__) || defined(ZARCH)
10681074
printf("#define CHAR_CORENAME \"%s\"\n", get_corename());
10691075
#endif
10701076
#endif

kernel/zarch/KERNEL

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
ifndef SCABS_KERNEL
2+
SCABS_KERNEL = ../generic/cabs.c
3+
endif
4+
5+
ifndef DCABS_KERNEL
6+
DCABS_KERNEL = ../generic/cabs.c
7+
endif
8+
9+
ifndef QCABS_KERNEL
10+
QCABS_KERNEL = ../generic/cabs.c
11+
endif
12+
13+
ifndef LSAME_KERNEL
14+
LSAME_KERNEL = ../generic/lsame.c
15+
endif
16+
17+
ifndef SGEMM_BETA
18+
SGEMM_BETA = ../generic/gemm_beta.c
19+
endif
20+
ifndef DGEMM_BETA
21+
DGEMM_BETA = ../generic/gemm_beta.c
22+
endif
23+
ifndef CGEMM_BETA
24+
CGEMM_BETA = ../generic/zgemm_beta.c
25+
endif
26+
ifndef ZGEMM_BETA
27+
ZGEMM_BETA = ../generic/zgemm_beta.c
28+
endif
29+
30+

0 commit comments

Comments
 (0)