[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#1057643: onednn: add support for loongarch64



Source: onednn
Version: 2.7.4-2
Severity: wishlist
Tags: patch
User: debian-loongarch@lists.debian.org
Usertags: loong64

Dear maintainers,

The onednn source package lacks LoongArch architecture support.
We need to add loongarch64 support in d/control and source code.

Please consider the patch I have attached.
The onednn source package was compiled successfully on my local loong64 rootfs environment.
And the test cases passed, for examples,
```
......
101/101 Test #101: noexcept-cpp .....................................   Passed    0.00 sec
100% tests passed, 0 tests failed out of 101
Total Test time (real) = 177.87 sec
```
If you have any questions, you can contact me at any time.

thanks,
Dandan Zhang

diff -Nru onednn-2.7.4/debian/control onednn-2.7.4/debian/control
--- onednn-2.7.4/debian/control	2023-08-17 18:24:42.000000000 +0000
+++ onednn-2.7.4/debian/control	2023-08-17 18:37:11.000000000 +0000
@@ -17,7 +17,7 @@
 
 Package: libdnnl-dev
 Section: libdevel
-Architecture: amd64 arm64 ppc64el s390x
+Architecture: amd64 arm64 ppc64el s390x loong64
 Multi-Arch: same
 Depends: libdnnl2 (= ${binary:Version}), ${misc:Depends}, ${shlibs:Depends}
 Recommends: ocl-icd-opencl-dev
@@ -36,7 +36,7 @@
 
 Package: libdnnl2
 Section: libs
-Architecture: amd64 arm64 ppc64el s390x
+Architecture: amd64 arm64 ppc64el s390x loong64
 Multi-Arch: same
 Depends: ${misc:Depends}, ${shlibs:Depends}
 Breaks: libmkldnn1
diff -Nru onednn-2.7.4/debian/patches/add-support-for-loongarch64.patch onednn-2.7.4/debian/patches/add-support-for-loongarch64.patch
--- onednn-2.7.4/debian/patches/add-support-for-loongarch64.patch	1970-01-01 00:00:00.000000000 +0000
+++ onednn-2.7.4/debian/patches/add-support-for-loongarch64.patch	2023-08-17 18:37:11.000000000 +0000
@@ -0,0 +1,80 @@
+Description: Add support for loongarch64 
+Author: Dandan Zhang <zhangdandan@loongson.cn> 
+Last-Update: 2023-11-30
+
+--- onednn-2.7.4.orig/CMakeLists.txt
++++ onednn-2.7.4/CMakeLists.txt
+@@ -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.*|loong64.*|LOONG64.*)")
++	set(DNNL_TARGET_ARCH "LOONGARCH64")
+     else()
+         set(DNNL_TARGET_ARCH "X64")
+     endif()
+--- onednn-2.7.4.orig/cmake/platform.cmake
++++ onednn-2.7.4/cmake/platform.cmake
+@@ -318,6 +318,15 @@ elseif(UNIX OR MINGW)
+             append(DEF_ARCH_OPT_FLAGS "-march=rv64gc")
+         elseif(DNNL_TARGET_ARCH STREQUAL "X64")
+             platform_gnu_x64_arch_ccxx_flags(DEF_ARCH_OPT_FLAGS)
++        elseif(DNNL_TARGET_ARCH STREQUAL "LOONGARCH64")
++            if (NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
++                set(DEF_ARCH_OPT_FLAGS "-O3")
++            endif()
++            # In GCC, -ftree-vectorize is turned on under -O3 since 2007.
++            # For native compilation tune for the host processor
++            if (CMAKE_SYSTEM_PROCESSOR STREQUAL CMAKE_HOST_SYSTEM_PROCESSOR)
++                append(DEF_ARCH_OPT_FLAGS "-march=native")
++            endif()
+         endif()
+         platform_gnu_nowarn_ccxx_flags(CMAKE_CCXX_NOWARN_FLAGS ${CMAKE_CXX_COMPILER_VERSION})
+     elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
+--- onednn-2.7.4.orig/src/cpu/README.md
++++ onednn-2.7.4/src/cpu/README.md
+@@ -46,6 +46,7 @@ enable or disable parts of code. There t
+ - `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 LoongArch 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.
+ 
+--- onednn-2.7.4.orig/src/cpu/platform.hpp
++++ onednn-2.7.4/src/cpu/platform.hpp
+@@ -30,6 +30,7 @@
+ // - 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.
+ 
+@@ -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
+@@ -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
diff -Nru onednn-2.7.4/debian/patches/series onednn-2.7.4/debian/patches/series
--- onednn-2.7.4/debian/patches/series	2023-08-17 18:37:11.000000000 +0000
+++ onednn-2.7.4/debian/patches/series	2023-08-17 18:37:11.000000000 +0000
@@ -1 +1,2 @@
 fix-gcc13-ftbfs.patch
+add-support-for-loongarch64.patch

Reply to: