未验证 提交 5ed2320c 编写于 作者: Z Zhang Na 提交者: GitHub

Add LoongArch support (#51109)

上级 2dfc3fa8
...@@ -298,6 +298,7 @@ option(WITH_CRYPTO "Compile PaddlePaddle with crypto support" ON) ...@@ -298,6 +298,7 @@ option(WITH_CRYPTO "Compile PaddlePaddle with crypto support" ON)
option(WITH_ARM "Compile PaddlePaddle with arm support" OFF) option(WITH_ARM "Compile PaddlePaddle with arm support" OFF)
option(WITH_SW "Compile PaddlePaddle with sw support" OFF) option(WITH_SW "Compile PaddlePaddle with sw support" OFF)
option(WITH_MIPS "Compile PaddlePaddle with mips support" OFF) option(WITH_MIPS "Compile PaddlePaddle with mips support" OFF)
option(WITH_LOONGARCH "Compile PaddlePaddle with loongarch support" OFF)
option(WITH_MUSL "Compile with musl libc instead of gblic" OFF) option(WITH_MUSL "Compile with musl libc instead of gblic" OFF)
option(WITH_UNITY_BUILD "Compile with UnityBuild mode" OFF) option(WITH_UNITY_BUILD "Compile with UnityBuild mode" OFF)
option(WITH_STRIP "Strip so files of Whl packages" OFF) option(WITH_STRIP "Strip so files of Whl packages" OFF)
...@@ -659,6 +660,16 @@ if(WITH_MIPS) ...@@ -659,6 +660,16 @@ if(WITH_MIPS)
add_definitions(-DPADDLE_WITH_MIPS) add_definitions(-DPADDLE_WITH_MIPS)
endif() endif()
if(WITH_LOONGARCH)
set(WITH_XBYAK
OFF
CACHE STRING "Disable XBYAK when compiling WITH_LOONGARCH=ON" FORCE)
set(WITH_MKL
OFF
CACHE STRING "Disable MKL when compiling WITH_LOONGARCH=ON." FORCE)
add_definitions(-DPADDLE_WITH_LOONGARCH)
endif()
if(WITH_ONEMKL) if(WITH_ONEMKL)
add_definitions(-DPADDLE_WITH_ONEMKL) add_definitions(-DPADDLE_WITH_ONEMKL)
endif() endif()
......
...@@ -26,6 +26,10 @@ if(WITH_MIPS) ...@@ -26,6 +26,10 @@ if(WITH_MIPS)
set(CBLAS_TAG v0.3.13) set(CBLAS_TAG v0.3.13)
endif() endif()
if(WITH_LOONGARCH)
set(CBLAS_TAG v0.3.18)
endif()
if(NOT WIN32) if(NOT WIN32)
set(CBLAS_LIBRARIES set(CBLAS_LIBRARIES
"${CBLAS_INSTALL_DIR}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}openblas${CMAKE_STATIC_LIBRARY_SUFFIX}" "${CBLAS_INSTALL_DIR}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}openblas${CMAKE_STATIC_LIBRARY_SUFFIX}"
......
...@@ -196,7 +196,8 @@ if(NOT WIN32) ...@@ -196,7 +196,8 @@ if(NOT WIN32)
if(NOT WITH_NV_JETSON if(NOT WITH_NV_JETSON
AND NOT WITH_ARM AND NOT WITH_ARM
AND NOT WITH_SW AND NOT WITH_SW
AND NOT WITH_MIPS) AND NOT WITH_MIPS
AND NOT WITH_LOONGARCH)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m64") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m64")
endif() endif()
endif() endif()
......
...@@ -15,7 +15,7 @@ limitations under the License. */ ...@@ -15,7 +15,7 @@ limitations under the License. */
#pragma once #pragma once
#if !defined(PADDLE_WITH_ARM) && !defined(PADDLE_WITH_SW) && \ #if !defined(PADDLE_WITH_ARM) && !defined(PADDLE_WITH_SW) && \
!defined(PADDLE_WITH_MIPS) !defined(PADDLE_WITH_MIPS) && !defined(PADDLE_WITH_LOONGARCH)
#include <immintrin.h> #include <immintrin.h>
#endif #endif
#include <cfloat> #include <cfloat>
...@@ -103,7 +103,7 @@ void call_gemm_batched(const framework::ExecutionContext& ctx, ...@@ -103,7 +103,7 @@ void call_gemm_batched(const framework::ExecutionContext& ctx,
} }
#if !defined(PADDLE_WITH_ARM) && !defined(PADDLE_WITH_SW) && \ #if !defined(PADDLE_WITH_ARM) && !defined(PADDLE_WITH_SW) && \
!defined(PADDLE_WITH_MIPS) !defined(PADDLE_WITH_MIPS) && !defined(PADDLE_WITH_LOONGARCH)
#define __m256x __m256 #define __m256x __m256
...@@ -144,7 +144,7 @@ inline void axpy(const T* x, T* y, size_t len, const T alpha) { ...@@ -144,7 +144,7 @@ inline void axpy(const T* x, T* y, size_t len, const T alpha) {
_mm256_mul_px(mm_alpha, _mm256_load_px(x + jjj)))); _mm256_mul_px(mm_alpha, _mm256_load_px(x + jjj))));
} }
#elif defined(PADDLE_WITH_ARM) || defined(PADDLE_WITH_SW) || \ #elif defined(PADDLE_WITH_ARM) || defined(PADDLE_WITH_SW) || \
defined(PADDLE_WITH_MIPS) defined(PADDLE_WITH_MIPS) || defined(PADDLE_WITH_LOONGARCH)
PADDLE_THROW(platform::errors::Unimplemented("axpy is not supported")); PADDLE_THROW(platform::errors::Unimplemented("axpy is not supported"));
#else #else
lll = len & ~SSE_CUT_LEN_MASK; lll = len & ~SSE_CUT_LEN_MASK;
...@@ -174,7 +174,7 @@ inline void axpy_noadd(const T* x, T* y, size_t len, const T alpha) { ...@@ -174,7 +174,7 @@ inline void axpy_noadd(const T* x, T* y, size_t len, const T alpha) {
_mm256_store_px(y + jjj, _mm256_mul_px(mm_alpha, _mm256_load_px(x + jjj))); _mm256_store_px(y + jjj, _mm256_mul_px(mm_alpha, _mm256_load_px(x + jjj)));
} }
#elif defined(PADDLE_WITH_ARM) || defined(PADDLE_WITH_SW) || \ #elif defined(PADDLE_WITH_ARM) || defined(PADDLE_WITH_SW) || \
defined(PADDLE_WITH_MIPS) defined(PADDLE_WITH_MIPS) || defined(PADDLE_WITH_LOONGARCH)
PADDLE_THROW(platform::errors::Unimplemented("axpy_noadd is not supported")); PADDLE_THROW(platform::errors::Unimplemented("axpy_noadd is not supported"));
#else #else
lll = len & ~SSE_CUT_LEN_MASK; lll = len & ~SSE_CUT_LEN_MASK;
......
...@@ -29,7 +29,8 @@ ...@@ -29,7 +29,8 @@
#endif #endif
#if !defined(GCC_WITHOUT_INTRINSICS) && !defined(PADDLE_WITH_ARM) && \ #if !defined(GCC_WITHOUT_INTRINSICS) && !defined(PADDLE_WITH_ARM) && \
!defined(PADDLE_WITH_SW) && !defined(PADDLE_WITH_MIPS) && !defined(_WIN32) !defined(PADDLE_WITH_SW) && !defined(PADDLE_WITH_MIPS) && \
!defined(_WIN32) && !defined(PADDLE_WITH_LOONGARCH)
#define DENORM_USE_INTRINSICS #define DENORM_USE_INTRINSICS
#endif #endif
......
...@@ -165,8 +165,9 @@ bool MayIUse(const cpu_isa_t cpu_isa) { ...@@ -165,8 +165,9 @@ bool MayIUse(const cpu_isa_t cpu_isa) {
if (cpu_isa == isa_any) { if (cpu_isa == isa_any) {
return true; return true;
} else { } else {
#if !defined(WITH_NV_JETSON) && !defined(PADDLE_WITH_ARM) && \ #if !defined(WITH_NV_JETSON) && !defined(PADDLE_WITH_ARM) && \
!defined(PADDLE_WITH_SW) && !defined(PADDLE_WITH_MIPS) !defined(PADDLE_WITH_SW) && !defined(PADDLE_WITH_MIPS) && \
!defined(PADDLE_WITH_LOONGARCH)
int reg[4]; int reg[4];
cpuid(reg, 0); cpuid(reg, 0);
int nIds = reg[0]; int nIds = reg[0];
......
...@@ -40,8 +40,9 @@ ...@@ -40,8 +40,9 @@
#ifdef _WIN32 #ifdef _WIN32
#define cpuid(reg, x) __cpuidex(reg, x, 0) #define cpuid(reg, x) __cpuidex(reg, x, 0)
#else #else
#if !defined(WITH_NV_JETSON) && !defined(PADDLE_WITH_ARM) && \ #if !defined(WITH_NV_JETSON) && !defined(PADDLE_WITH_ARM) && \
!defined(PADDLE_WITH_SW) && !defined(PADDLE_WITH_MIPS) !defined(PADDLE_WITH_SW) && !defined(PADDLE_WITH_MIPS) && \
!defined(PADDLE_WITH_LOONGARCH)
#include <cpuid.h> #include <cpuid.h>
inline void cpuid(int reg[4], int x) { inline void cpuid(int reg[4], int x) {
__cpuid_count(x, 0, reg[0], reg[1], reg[2], reg[3]); __cpuid_count(x, 0, reg[0], reg[1], reg[2], reg[3]);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册