From b25c0e8ba36313751271143eb385b35e685d15d6 Mon Sep 17 00:00:00 2001 From: Jingyun Hua Date: Thu, 18 May 2023 06:20:09 +0000 Subject: [PATCH] Add loongarch64 support Signed-off-by: Jingyun Hua --- ...-loongarch64-support-for-third_party.patch | 90 +++++++++++++++++++ pytorch.spec | 6 +- 2 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 0003-Add-loongarch64-support-for-third_party.patch diff --git a/0003-Add-loongarch64-support-for-third_party.patch b/0003-Add-loongarch64-support-for-third_party.patch new file mode 100644 index 0000000..1340af0 --- /dev/null +++ b/0003-Add-loongarch64-support-for-third_party.patch @@ -0,0 +1,90 @@ +From 108c7d4a2777cc94067dfb7f580e7c8aef03832c Mon Sep 17 00:00:00 2001 +From: Jingyun Hua +Date: Thu, 18 May 2023 02:39:20 +0000 +Subject: [PATCH] Add loongarch64 support for third_party + +Signed-off-by: Jingyun Hua +--- + third_party/benchmark/src/cycleclock.h | 4 ++++ + .../third_party/onnx/third_party/benchmark/src/cycleclock.h | 4 ++++ + third_party/onnx/third_party/benchmark/src/cycleclock.h | 4 ++++ + third_party/protobuf/third_party/benchmark/src/cycleclock.h | 4 ++++ + third_party/sleef/src/arch/helperpurec_scalar.h | 2 +- + 5 files changed, 17 insertions(+), 1 deletion(-) + +diff --git a/third_party/benchmark/src/cycleclock.h b/third_party/benchmark/src/cycleclock.h +index 00d57641..92860f3b 100644 +--- a/third_party/benchmark/src/cycleclock.h ++++ b/third_party/benchmark/src/cycleclock.h +@@ -164,6 +164,10 @@ inline BENCHMARK_ALWAYS_INLINE int64_t Now() { + uint64_t tsc; + asm("stck %0" : "=Q"(tsc) : : "cc"); + return tsc; ++#elif defined(__loongarch64) ++ struct timeval tv; ++ gettimeofday(&tv, nullptr); ++ return static_cast(tv.tv_sec) * 1000000 + tv.tv_usec; + #else + // The soft failover to a generic implementation is automatic only for ARM. + // For other platforms the developer is expected to make an attempt to create +diff --git a/third_party/onnx-tensorrt/third_party/onnx/third_party/benchmark/src/cycleclock.h b/third_party/onnx-tensorrt/third_party/onnx/third_party/benchmark/src/cycleclock.h +index 3b376ac5..49795da7 100644 +--- a/third_party/onnx-tensorrt/third_party/onnx/third_party/benchmark/src/cycleclock.h ++++ b/third_party/onnx-tensorrt/third_party/onnx/third_party/benchmark/src/cycleclock.h +@@ -164,6 +164,10 @@ inline BENCHMARK_ALWAYS_INLINE int64_t Now() { + uint64_t tsc; + asm("stck %0" : "=Q" (tsc) : : "cc"); + return tsc; ++#elif defined(__loongarch64) ++ struct timeval tv; ++ gettimeofday(&tv, nullptr); ++ return static_cast(tv.tv_sec) * 1000000 + tv.tv_usec; + #else + // The soft failover to a generic implementation is automatic only for ARM. + // For other platforms the developer is expected to make an attempt to create +diff --git a/third_party/onnx/third_party/benchmark/src/cycleclock.h b/third_party/onnx/third_party/benchmark/src/cycleclock.h +index 3b376ac5..0c66c375 100644 +--- a/third_party/onnx/third_party/benchmark/src/cycleclock.h ++++ b/third_party/onnx/third_party/benchmark/src/cycleclock.h +@@ -164,6 +164,10 @@ inline BENCHMARK_ALWAYS_INLINE int64_t Now() { + uint64_t tsc; + asm("stck %0" : "=Q" (tsc) : : "cc"); + return tsc; ++ #elif defined(__loongarch64) ++ struct timeval tv; ++ gettimeofday(&tv, nullptr); ++ return static_cast(tv.tv_sec) * 1000000 + tv.tv_usec; + #else + // The soft failover to a generic implementation is automatic only for ARM. + // For other platforms the developer is expected to make an attempt to create +diff --git a/third_party/protobuf/third_party/benchmark/src/cycleclock.h b/third_party/protobuf/third_party/benchmark/src/cycleclock.h +index 4251fe4c..9b29eb8e 100644 +--- a/third_party/protobuf/third_party/benchmark/src/cycleclock.h ++++ b/third_party/protobuf/third_party/benchmark/src/cycleclock.h +@@ -159,6 +159,10 @@ inline BENCHMARK_ALWAYS_INLINE int64_t Now() { + struct timeval tv; + gettimeofday(&tv, nullptr); + return static_cast(tv.tv_sec) * 1000000 + tv.tv_usec; ++#elif defined(__loongarch64) ++ struct timeval tv; ++ gettimeofday(&tv, nullptr); ++ return static_cast(tv.tv_sec) * 1000000 + tv.tv_usec; + #else + // The soft failover to a generic implementation is automatic only for ARM. + // For other platforms the developer is expected to make an attempt to create +diff --git a/third_party/sleef/src/arch/helperpurec_scalar.h b/third_party/sleef/src/arch/helperpurec_scalar.h +index 9c11ace4..82274d24 100644 +--- a/third_party/sleef/src/arch/helperpurec_scalar.h ++++ b/third_party/sleef/src/arch/helperpurec_scalar.h +@@ -43,7 +43,7 @@ + #define ENABLE_FMA_DP + #define ENABLE_FMA_SP + +-#if defined(__AVX2__) || defined(__aarch64__) || defined(__arm__) || defined(__powerpc64__) ++#if defined(__AVX2__) || defined(__aarch64__) || defined(__arm__) || defined(__powerpc64__) || defined(__loongarch64) + #ifndef FP_FAST_FMA + #define FP_FAST_FMA + #endif +-- +2.33.0 + diff --git a/pytorch.spec b/pytorch.spec index b603bf8..1e9763e 100644 --- a/pytorch.spec +++ b/pytorch.spec @@ -1,7 +1,7 @@ %global _empty_manifest_terminate_build 0 Name: pytorch Version: 1.6.0 -Release: 3 +Release: 4 Summary: Tensors and Dynamic neural networks in Python with strong GPU acceleration License: BSD-3 URL: https://pytorch.org/ @@ -10,6 +10,7 @@ Source0: pytorch-%{version}-include-submodules.tar.bz2 Patch0001: 0001-Fix-illegal-opcode-bug-in-caffe2-40584.patch Patch0002: 0002-disable-SVE-for-v1.6.0-due-to-sleef-build-error.patch +Patch0003: 0003-Add-loongarch64-support-for-third_party.patch BuildRequires: g++ Requires: python3-future @@ -86,6 +87,9 @@ mv %{buildroot}/doclist.lst . %{_docdir}/* %changelog +* Thu May 18 2023 huajingyun - 1.6.0-4 +- add loongarch64 support + * Mon Jun 28 2021 wulei - 1.6.0-3 - fixes: error: the CXX compiler identification is unknown -- Gitee