Skip to content

Commit

Permalink
Add initial support for loongarch architecture
Browse files Browse the repository at this point in the history
  • Loading branch information
loong-hy committed May 20, 2024
1 parent 684034d commit 620d8fa
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ if(NOT DNNL_TARGET_ARCH)
set(DNNL_TARGET_ARCH "S390X")
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(rv.*|RV.*|riscv.*|RISCV.*)")
set(DNNL_TARGET_ARCH "RV64")
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(loongarch64.*|LOONGARCH64.*)")
set(DNNL_TARGET_ARCH "LOONGARCH64")
else()
set(DNNL_TARGET_ARCH "X64")
endif()
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ oneDNN supports platforms based on the following architectures:
- [OpenPOWER](https://openpowerfoundation.org/) / [IBM Power ISA](https://en.wikipedia.org/wiki/Power_ISA).
- [IBMz z/Architecture (s390x)](https://en.wikipedia.org/wiki/Z/Architecture).
- [RISC-V 64-bit (RV64)](https://en.wikipedia.org/wiki/RISC-V).

- [LOONGARCH 64 bit](https://docs.kernel.org/arch/loongarch/introduction.html).
> **WARNING**
>
> Power ISA (PPC64), IBMz (s390x), and RISC-V (RV64) support is
> Power ISA (PPC64), IBMz (s390x), RISC-V (RV64) and Loongson (LOONGARCH64) support is
> **experimental** with limited testing validation.
The library is optimized for the following CPUs:
Expand Down
2 changes: 2 additions & 0 deletions cmake/platform.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,8 @@ elseif(UNIX OR MINGW)
elseif(DNNL_TARGET_ARCH STREQUAL "RV64")
# G = General-purpose extensions, C = Compression extension (very common).
append(DEF_ARCH_OPT_FLAGS "-march=rv64gc")
elseif(DNNL_TARGET_ARCH STREQUAL "LOONGARCH64")
append(DEF_ARCH_OPT_FLAGS "-march=loongarch64")
elseif(DNNL_TARGET_ARCH STREQUAL "X64")
platform_gnu_x64_arch_ccxx_flags(DEF_ARCH_OPT_FLAGS)
endif()
Expand Down
1 change: 1 addition & 0 deletions src/cpu/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ enable or disable parts of code. There the following macros defined:
- `DNNL_PPC64` is 1 on OpenPOWER / IBM Power architecture;
- `DNNL_S390X` is 1 on IBMz / s390x architecture;
- `DNNL_RV64` is 1 on RISC-V architecture;
- `DNNL_LOONGARCH64` is 1 on Loongson LOONGARCH64 architecture;
- `DNNL_ARCH_GENERIC` is 1 on other platforms.
Only one of the macros above is defined to 1. All others are defined to 0.

Expand Down
10 changes: 8 additions & 2 deletions src/cpu/platform.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@
// - DNNL_PPC64
// - DNNL_S390X
// - DNNL_RV64
// - DNNL_LOONGARCH64
// - DNNL_ARCH_GENERIC
// Target architecture macro is set to 1, others to 0. All macros are defined.

#if defined(DNNL_X64) + defined(DNNL_AARCH64) + defined(DNNL_PPC64) \
+ defined(DNNL_S390X) + defined(DNNL_RV64) \
+ defined(DNNL_S390X) + defined(DNNL_RV64) + defined(DNNL_LOONGARCH64) \
+ defined(DNNL_ARCH_GENERIC) \
== 0
#if defined(__x86_64__) || defined(_M_X64)
Expand All @@ -47,13 +48,15 @@
#define DNNL_S390X 1
#elif defined(__riscv)
#define DNNL_RV64 1
#elif defined(__loongarch64)
#define DNNL_LOONGARCH64 1
#else
#define DNNL_ARCH_GENERIC 1
#endif
#endif // defined(DNNL_X64) + ... == 0

#if defined(DNNL_X64) + defined(DNNL_AARCH64) + defined(DNNL_PPC64) \
+ defined(DNNL_S390X) + defined(DNNL_RV64) \
+ defined(DNNL_S390X) + defined(DNNL_RV64) + defined(DNNL_LOONGARCH64) \
+ defined(DNNL_ARCH_GENERIC) \
!= 1
#error One and only one architecture should be defined at a time
Expand All @@ -74,6 +77,9 @@
#if !defined(DNNL_RV64)
#define DNNL_RV64 0
#endif
#if !defined(DNNL_LOONGARCH64)
#define DNNL_LOONGARCH64 0
#endif
#if !defined(DNNL_ARCH_GENERIC)
#define DNNL_ARCH_GENERIC 0
#endif
Expand Down

0 comments on commit 620d8fa

Please sign in to comment.