Skip to content

Commit cbc4616

Browse files
authored
Merge pull request #1526 from jerryz123/upstream_riscv
Add support for RISC-V
2 parents 0c4718c + 0ee395d commit cbc4616

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+4180
-0
lines changed

Makefile.riscv64

Whitespace-only changes.

Makefile.system

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,9 @@ endif
593593
ifndef BINARY_DEFINED
594594
ifneq ($(OSNAME), AIX)
595595
ifdef BINARY64
596+
ifneq ($(ARCH), riscv64)
596597
CCOMMON_OPT += -m64
598+
endif
597599
else
598600
CCOMMON_OPT += -m32
599601
endif
@@ -687,8 +689,10 @@ endif
687689
else
688690
ifdef BINARY64
689691
ifneq ($(OSNAME), AIX)
692+
ifneq ($(ARCH), riscv64)
690693
FCOMMON_OPT += -m64
691694
endif
695+
endif
692696
ifdef INTERFACE64
693697
ifneq ($(INTERFACE64), 0)
694698
FCOMMON_OPT += -fdefault-integer-8

c_check

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ $architecture = ia64 if ($data =~ /ARCH_IA64/);
7676
$architecture = arm if ($data =~ /ARCH_ARM/);
7777
$architecture = arm64 if ($data =~ /ARCH_ARM64/);
7878
$architecture = zarch if ($data =~ /ARCH_ZARCH/);
79+
$architecture = riscv64 if ($data =~ /ARCH_RISCV64/);
7980

8081
$defined = 0;
8182

common.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,11 @@ please https://github.com/xianyi/OpenBLAS/issues/246
408408
#include "common_mips.h"
409409
#endif
410410

411+
412+
#ifdef ARCH_RISCV64
413+
#include "common_riscv64.h"
414+
#endif
415+
411416
#ifdef ARCH_MIPS64
412417
#include "common_mips64.h"
413418
#endif

common_riscv64.h

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*****************************************************************************
2+
Copyright (c) 2011-2014, 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+
/*********************************************************************/
34+
/* Copyright 2009, 2010 The University of Texas at Austin. */
35+
/* All rights reserved. */
36+
/* */
37+
/* Redistribution and use in source and binary forms, with or */
38+
/* without modification, are permitted provided that the following */
39+
/* conditions are met: */
40+
/* */
41+
/* 1. Redistributions of source code must retain the above */
42+
/* copyright notice, this list of conditions and the following */
43+
/* disclaimer. */
44+
/* */
45+
/* 2. Redistributions in binary form must reproduce the above */
46+
/* copyright notice, this list of conditions and the following */
47+
/* disclaimer in the documentation and/or other materials */
48+
/* provided with the distribution. */
49+
/* */
50+
/* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY OF TEXAS AT */
51+
/* AUSTIN ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, */
52+
/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
53+
/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
54+
/* DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OF TEXAS AT */
55+
/* AUSTIN OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, */
56+
/* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES */
57+
/* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE */
58+
/* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR */
59+
/* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF */
60+
/* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */
61+
/* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT */
62+
/* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE */
63+
/* POSSIBILITY OF SUCH DAMAGE. */
64+
/* */
65+
/* The views and conclusions contained in the software and */
66+
/* documentation are those of the authors and should not be */
67+
/* interpreted as representing official policies, either expressed */
68+
/* or implied, of The University of Texas at Austin. */
69+
/*********************************************************************/
70+
71+
#ifndef COMMON_RISCV64
72+
#define COMMON_RISCV64
73+
74+
#define MB __sync_synchronize()
75+
#define WMB __sync_synchronize()
76+
77+
#define INLINE inline
78+
79+
#ifndef ASSEMBLER
80+
81+
82+
static inline int blas_quickdivide(blasint x, blasint y){
83+
return x / y;
84+
}
85+
86+
#endif
87+
88+
89+
90+
#define BUFFER_SIZE ( 32 << 20)
91+
#define SEEK_ADDRESS
92+
93+
#endif

cpuid_riscv64.c

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
/*****************************************************************************
2+
Copyright (c) 2011-2014, 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+
34+
35+
/*********************************************************************/
36+
/* Copyright 2009, 2010 The University of Texas at Austin. */
37+
/* All rights reserved. */
38+
/* */
39+
/* Redistribution and use in source and binary forms, with or */
40+
/* without modification, are permitted provided that the following */
41+
/* conditions are met: */
42+
/* */
43+
/* 1. Redistributions of source code must retain the above */
44+
/* copyright notice, this list of conditions and the following */
45+
/* disclaimer. */
46+
/* */
47+
/* 2. Redistributions in binary form must reproduce the above */
48+
/* copyright notice, this list of conditions and the following */
49+
/* disclaimer in the documentation and/or other materials */
50+
/* provided with the distribution. */
51+
/* */
52+
/* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY OF TEXAS AT */
53+
/* AUSTIN ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, */
54+
/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
55+
/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
56+
/* DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OF TEXAS AT */
57+
/* AUSTIN OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, */
58+
/* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES */
59+
/* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE */
60+
/* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR */
61+
/* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF */
62+
/* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */
63+
/* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT */
64+
/* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE */
65+
/* POSSIBILITY OF SUCH DAMAGE. */
66+
/* */
67+
/* The views and conclusions contained in the software and */
68+
/* documentation are those of the authors and should not be */
69+
/* interpreted as representing official policies, either expressed */
70+
/* or implied, of The University of Texas at Austin. */
71+
/*********************************************************************/
72+
73+
#define CPU_UNKNOWN 0
74+
75+
static char *cpuname[] = {
76+
"UNKOWN",
77+
};
78+
79+
int detect(void){
80+
return CPU_UNKNOWN;
81+
}
82+
83+
char *get_corename(void){
84+
return cpuname[detect()];
85+
}
86+
87+
void get_architecture(void){
88+
printf("RISCV64");
89+
}
90+
91+
void get_subarchitecture(void){
92+
}
93+
94+
void get_subdirname(void){
95+
printf("riscv64");
96+
}
97+
98+
void get_cpuconfig(void){
99+
printf("#define UNKNOWN\n");
100+
printf("#define L1_DATA_SIZE 65536\n");
101+
printf("#define L1_DATA_LINESIZE 32\n");
102+
printf("#define L2_SIZE 512488\n");
103+
printf("#define L2_LINESIZE 32\n");
104+
printf("#define DTB_DEFAULT_ENTRIES 64\n");
105+
printf("#define DTB_SIZE 4096\n");
106+
printf("#define L2_ASSOCIATIVE 4\n");
107+
}
108+
109+
void get_libname(void){
110+
printf("riscv64\n");
111+
}

ctest.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,3 +149,7 @@ ARCH_ARM
149149
ARCH_ARM64
150150
#endif
151151

152+
#if defined(__riscv)
153+
ARCH_RISCV64
154+
#endif
155+

getarch.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,7 @@ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
604604
#endif
605605

606606

607+
607608
#ifdef FORCE_PPCG4
608609
#define FORCE
609610
#define ARCHITECTURE "POWER"
@@ -859,6 +860,20 @@ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
859860
#else
860861
#endif
861862

863+
#ifdef FORCE_RISCV64
864+
#define FORCE
865+
#define ARCHITECTURE "RISCV64"
866+
#define SUBARCHITECTURE "RISCV64"
867+
#define SUBDIRNAME "riscv64"
868+
#define ARCHCONFIG "-DRISCV64 " \
869+
"-DL1_DATA_SIZE=32768 -DL1_DATA_LINESIZE=32 " \
870+
"-DL2_SIZE=1048576 -DL2_LINESIZE=32 " \
871+
"-DDTB_DEFAULT_ENTRIES=128 -DDTB_SIZE=4096 -DL2_ASSOCIATIVE=4 "
872+
#define LIBNAME "riscv64"
873+
#define CORENAME "RISCV64"
874+
#else
875+
#endif
876+
862877
#ifdef FORCE_CORTEXA15
863878
#define FORCE
864879
#define ARCHITECTURE "ARM"
@@ -1051,6 +1066,10 @@ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
10511066
#define OPENBLAS_SUPPORTED
10521067
#endif
10531068

1069+
#ifdef __riscv
1070+
#include "cpuid_riscv64.c"
1071+
#endif
1072+
10541073
#ifdef __arm__
10551074
#include "cpuid_arm.c"
10561075
#define OPENBLAS_SUPPORTED

kernel/Makefile.L3

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ ifeq ($(ARCH), arm64)
2020
USE_TRMM = 1
2121
endif
2222

23+
ifeq ($(ARCH), riscv64)
24+
USE_TRMM = 1
25+
endif
26+
2327
ifeq ($(TARGET), LOONGSON3B)
2428
USE_TRMM = 1
2529
endif

0 commit comments

Comments
 (0)