Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cpu: add loongarch64 support #1923

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,11 @@ 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).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please restore the new line to separate the warning.


> **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")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason to not add opt flags for compilers other than gcc ?

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,12 +30,13 @@
// - 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_ARCH_GENERIC) \
+ defined(DNNL_LOONGARCH64) + defined(DNNL_ARCH_GENERIC) \
== 0
#if defined(__x86_64__) || defined(_M_X64)
#define DNNL_X64 1
Expand All @@ -47,14 +48,16 @@
#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_ARCH_GENERIC) \
+ defined(DNNL_LOONGARCH64) + defined(DNNL_ARCH_GENERIC) \
!= 1
#error One and only one architecture should be defined at a time
#endif
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