Skip to content

Commit 76a66ea

Browse files
authored
Merge pull request #1829 from ashwinyes/develop_aarch64_dynamic_arch_support
Add DYNAMIC_ARCH support for ARM64
2 parents e3c262e + d5aeff6 commit 76a66ea

14 files changed

+466
-258
lines changed

Makefile.system

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,13 @@ CCOMMON_OPT += $(XCCOMMON_OPT)
510510
#CCOMMON_OPT += -DDYNAMIC_LIST='$(DYNAMIC_LIST)'
511511
endif
512512

513+
ifeq ($(ARCH), arm64)
514+
DYNAMIC_CORE = ARMV8
515+
DYNAMIC_CORE += CORTEXA57
516+
DYNAMIC_CORE += THUNDERX
517+
DYNAMIC_CORE += THUNDERX2T99
518+
endif
519+
513520
# If DYNAMIC_CORE is not set, DYNAMIC_ARCH cannot do anything, so force it to empty
514521
ifndef DYNAMIC_CORE
515522
override DYNAMIC_ARCH=

cpuid_arm64.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,6 @@ void get_cpuconfig(void)
237237
break;
238238

239239
case CPU_THUNDERX:
240-
printf("#define ARMV8\n");
241240
printf("#define THUNDERX\n");
242241
printf("#define L1_DATA_SIZE 32768\n");
243242
printf("#define L1_DATA_LINESIZE 128\n");

driver/others/Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ endif
1515
# COMMONOBJS += info.$(SUFFIX)
1616

1717
ifeq ($(DYNAMIC_ARCH), 1)
18+
ifeq ($(ARCH),arm64)
19+
COMMONOBJS += dynamic_arm64.$(SUFFIX)
20+
else
1821
COMMONOBJS += dynamic.$(SUFFIX)
22+
endif
1923
else
2024
COMMONOBJS += parameter.$(SUFFIX)
2125
endif
@@ -71,7 +75,11 @@ BLAS_SERVER = blas_server.c
7175
endif
7276

7377
ifeq ($(DYNAMIC_ARCH), 1)
78+
ifeq ($(ARCH),arm64)
79+
HPLOBJS = memory.$(SUFFIX) xerbla.$(SUFFIX) dynamic_arm64.$(SUFFIX)
80+
else
7481
HPLOBJS = memory.$(SUFFIX) xerbla.$(SUFFIX) dynamic.$(SUFFIX)
82+
endif
7583
else
7684
HPLOBJS = memory.$(SUFFIX) xerbla.$(SUFFIX) parameter.$(SUFFIX)
7785
endif

driver/others/dynamic_arm64.c

Lines changed: 198 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,198 @@
1+
/*********************************************************************/
2+
/* Copyright 2009, 2010 The University of Texas at Austin. */
3+
/* All rights reserved. */
4+
/* */
5+
/* Redistribution and use in source and binary forms, with or */
6+
/* without modification, are permitted provided that the following */
7+
/* conditions are met: */
8+
/* */
9+
/* 1. Redistributions of source code must retain the above */
10+
/* copyright notice, this list of conditions and the following */
11+
/* disclaimer. */
12+
/* */
13+
/* 2. Redistributions in binary form must reproduce the above */
14+
/* copyright notice, this list of conditions and the following */
15+
/* disclaimer in the documentation and/or other materials */
16+
/* provided with the distribution. */
17+
/* */
18+
/* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY OF TEXAS AT */
19+
/* AUSTIN ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, */
20+
/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
21+
/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
22+
/* DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OF TEXAS AT */
23+
/* AUSTIN OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, */
24+
/* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES */
25+
/* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE */
26+
/* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR */
27+
/* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF */
28+
/* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */
29+
/* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT */
30+
/* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE */
31+
/* POSSIBILITY OF SUCH DAMAGE. */
32+
/* */
33+
/* The views and conclusions contained in the software and */
34+
/* documentation are those of the authors and should not be */
35+
/* interpreted as representing official policies, either expressed */
36+
/* or implied, of The University of Texas at Austin. */
37+
/*********************************************************************/
38+
39+
#include "common.h"
40+
#include <asm/hwcap.h>
41+
#include <sys/auxv.h>
42+
43+
extern gotoblas_t gotoblas_ARMV8;
44+
extern gotoblas_t gotoblas_CORTEXA57;
45+
extern gotoblas_t gotoblas_THUNDERX;
46+
extern gotoblas_t gotoblas_THUNDERX2T99;
47+
48+
extern void openblas_warning(int verbose, const char * msg);
49+
50+
#define NUM_CORETYPES 4
51+
52+
/*
53+
* In case asm/hwcap.h is outdated on the build system, make sure
54+
* that HWCAP_CPUID is defined
55+
*/
56+
#ifndef HWCAP_CPUID
57+
#define HWCAP_CPUID (1 << 11)
58+
#endif
59+
60+
#define get_cpu_ftr(id, var) ({ \
61+
asm("mrs %0, "#id : "=r" (var)); \
62+
})
63+
64+
static char *corename[] = {
65+
"armv8",
66+
"cortexa57",
67+
"thunderx",
68+
"thunderx2t99",
69+
"unknown"
70+
};
71+
72+
char *gotoblas_corename(void) {
73+
if (gotoblas == &gotoblas_ARMV8) return corename[ 0];
74+
if (gotoblas == &gotoblas_CORTEXA57) return corename[ 1];
75+
if (gotoblas == &gotoblas_THUNDERX) return corename[ 2];
76+
if (gotoblas == &gotoblas_THUNDERX2T99) return corename[ 3];
77+
return corename[NUM_CORETYPES];
78+
}
79+
80+
static gotoblas_t *force_coretype(char *coretype) {
81+
int i ;
82+
int found = -1;
83+
char message[128];
84+
85+
for ( i=0 ; i < NUM_CORETYPES; i++)
86+
{
87+
if (!strncasecmp(coretype, corename[i], 20))
88+
{
89+
found = i;
90+
break;
91+
}
92+
}
93+
94+
switch (found)
95+
{
96+
case 0: return (&gotoblas_ARMV8);
97+
case 1: return (&gotoblas_CORTEXA57);
98+
case 2: return (&gotoblas_THUNDERX);
99+
case 3: return (&gotoblas_THUNDERX2T99);
100+
}
101+
snprintf(message, 128, "Core not found: %s\n", coretype);
102+
openblas_warning(1, message);
103+
return NULL;
104+
}
105+
106+
static gotoblas_t *get_coretype(void) {
107+
int implementer, variant, part, arch, revision, midr_el1;
108+
109+
if (!(getauxval(AT_HWCAP) & HWCAP_CPUID)) {
110+
char coremsg[128];
111+
snprintf(coremsg, 128, "Kernel lacks cpuid feature support. Auto detection of core type failed !!!\n");
112+
openblas_warning(1, coremsg);
113+
return NULL;
114+
}
115+
116+
get_cpu_ftr(MIDR_EL1, midr_el1);
117+
/*
118+
* MIDR_EL1
119+
*
120+
* 31 24 23 20 19 16 15 4 3 0
121+
* -----------------------------------------------------------------
122+
* | Implementer | Variant | Architecture | Part Number | Revision |
123+
* -----------------------------------------------------------------
124+
*/
125+
implementer = (midr_el1 >> 24) & 0xFF;
126+
part = (midr_el1 >> 4) & 0xFFF;
127+
128+
switch(implementer)
129+
{
130+
case 0x41: // ARM
131+
switch (part)
132+
{
133+
case 0xd07: // Cortex A57
134+
case 0xd08: // Cortex A72
135+
case 0xd03: // Cortex A53
136+
return &gotoblas_CORTEXA57;
137+
}
138+
break;
139+
case 0x42: // Broadcom
140+
switch (part)
141+
{
142+
case 0x516: // Vulcan
143+
return &gotoblas_THUNDERX2T99;
144+
}
145+
break;
146+
case 0x43: // Cavium
147+
switch (part)
148+
{
149+
case 0x0a1: // ThunderX
150+
return &gotoblas_THUNDERX;
151+
case 0x0af: // ThunderX2
152+
return &gotoblas_THUNDERX2T99;
153+
}
154+
break;
155+
}
156+
return NULL;
157+
}
158+
159+
void gotoblas_dynamic_init(void) {
160+
161+
char coremsg[128];
162+
char coren[22];
163+
char *p;
164+
165+
if (gotoblas) return;
166+
167+
p = getenv("OPENBLAS_CORETYPE");
168+
if ( p )
169+
{
170+
gotoblas = force_coretype(p);
171+
}
172+
else
173+
{
174+
gotoblas = get_coretype();
175+
}
176+
177+
if (gotoblas == NULL)
178+
{
179+
snprintf(coremsg, 128, "Falling back to generic ARMV8 core\n");
180+
openblas_warning(1, coremsg);
181+
gotoblas = &gotoblas_ARMV8;
182+
}
183+
184+
if (gotoblas && gotoblas->init) {
185+
strncpy(coren, gotoblas_corename(), 20);
186+
sprintf(coremsg, "Core: %s\n", coren);
187+
openblas_warning(2, coremsg);
188+
gotoblas -> init();
189+
} else {
190+
openblas_warning(0, "OpenBLAS : Architecture Initialization failed. No initialization function found.\n");
191+
exit(1);
192+
}
193+
194+
}
195+
196+
void gotoblas_dynamic_quit(void) {
197+
gotoblas = NULL;
198+
}

driver/others/parameter.c

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -730,35 +730,8 @@ void blas_set_parameter(void){
730730

731731
#if defined(ARCH_ARM64)
732732

733-
#if defined(VULCAN) || defined(THUNDERX2T99) || defined(ARMV8)
734-
unsigned long dgemm_prefetch_size_a;
735-
unsigned long dgemm_prefetch_size_b;
736-
unsigned long dgemm_prefetch_size_c;
737-
#endif
738-
739733
void blas_set_parameter(void)
740734
{
741-
#if defined(VULCAN) || defined(THUNDERX2T99) || defined(ARMV8)
742-
dgemm_p = 160;
743-
dgemm_q = 128;
744-
dgemm_r = 4096;
745-
746-
sgemm_p = 128;
747-
sgemm_q = 352;
748-
sgemm_r = 4096;
749-
750-
cgemm_p = 128;
751-
cgemm_q = 224;
752-
cgemm_r = 4096;
753-
754-
zgemm_p = 128;
755-
zgemm_q = 112;
756-
zgemm_r = 4096;
757-
758-
dgemm_prefetch_size_a = 3584;
759-
dgemm_prefetch_size_b = 512;
760-
dgemm_prefetch_size_c = 128;
761-
#endif
762735
}
763736

764737
#endif

kernel/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,11 @@ lsame.$(SUFFIX): $(KERNELDIR)/$(LSAME_KERNEL)
8888
$(CC) -c $(CFLAGS) -DF_INTERFACE $< -o $(@F)
8989

9090
setparam$(TSUFFIX).$(SUFFIX): setparam$(TSUFFIX).c kernel$(TSUFFIX).h
91+
ifeq ($(USE_GEMM3M), 1)
92+
$(CC) -c $(CFLAGS) -DUSE_GEMM3M $< -o $@
93+
else
9194
$(CC) -c $(CFLAGS) $< -o $@
95+
endif
9296

9397
setparam$(TSUFFIX).c : setparam-ref.c
9498
sed 's/TS/$(TSUFFIX)/g' $< > $(@F)

0 commit comments

Comments
 (0)