diff --git a/CMakeLists.txt b/CMakeLists.txt index e720e09072daea13502320654131a7ca31a5f3cf..fe10d96261acefbd46a46be7d91b92306569e757 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -298,6 +298,7 @@ option(WITH_CRYPTO "Compile PaddlePaddle with crypto support" ON) option(WITH_ARM "Compile PaddlePaddle with arm support" OFF) option(WITH_SW "Compile PaddlePaddle with sw 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_UNITY_BUILD "Compile with UnityBuild mode" OFF) option(WITH_STRIP "Strip so files of Whl packages" OFF) @@ -659,6 +660,16 @@ if(WITH_MIPS) add_definitions(-DPADDLE_WITH_MIPS) 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) add_definitions(-DPADDLE_WITH_ONEMKL) endif() diff --git a/cmake/external/openblas.cmake b/cmake/external/openblas.cmake index ceb7e17993a8507dfc7d3d6044a7ffffec24f150..01b9371da1509499dd7f0b6cb99fb0846a28cdf9 100644 --- a/cmake/external/openblas.cmake +++ b/cmake/external/openblas.cmake @@ -26,6 +26,10 @@ if(WITH_MIPS) set(CBLAS_TAG v0.3.13) endif() +if(WITH_LOONGARCH) + set(CBLAS_TAG v0.3.18) +endif() + if(NOT WIN32) set(CBLAS_LIBRARIES "${CBLAS_INSTALL_DIR}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}openblas${CMAKE_STATIC_LIBRARY_SUFFIX}" diff --git a/cmake/flags.cmake b/cmake/flags.cmake index 7dbad9621f9cbc0957c3e7f34eca05a50ad80a61..b880c8028a4f64d3942aad9da2ee0583471c3287 100644 --- a/cmake/flags.cmake +++ b/cmake/flags.cmake @@ -196,7 +196,8 @@ if(NOT WIN32) if(NOT WITH_NV_JETSON AND NOT WITH_ARM AND NOT WITH_SW - AND NOT WITH_MIPS) + AND NOT WITH_MIPS + AND NOT WITH_LOONGARCH) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m64") endif() endif() diff --git a/paddle/fluid/operators/search_compute.h b/paddle/fluid/operators/search_compute.h index e2156483320107742a3bb30eda221a24346a053c..abf8365182483867f3ef8942630801fa5090ccb6 100644 --- a/paddle/fluid/operators/search_compute.h +++ b/paddle/fluid/operators/search_compute.h @@ -15,7 +15,7 @@ limitations under the License. */ #pragma once #if !defined(PADDLE_WITH_ARM) && !defined(PADDLE_WITH_SW) && \ - !defined(PADDLE_WITH_MIPS) + !defined(PADDLE_WITH_MIPS) && !defined(PADDLE_WITH_LOONGARCH) #include #endif #include @@ -103,7 +103,7 @@ void call_gemm_batched(const framework::ExecutionContext& ctx, } #if !defined(PADDLE_WITH_ARM) && !defined(PADDLE_WITH_SW) && \ - !defined(PADDLE_WITH_MIPS) + !defined(PADDLE_WITH_MIPS) && !defined(PADDLE_WITH_LOONGARCH) #define __m256x __m256 @@ -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)))); } #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")); #else 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) { _mm256_store_px(y + jjj, _mm256_mul_px(mm_alpha, _mm256_load_px(x + jjj))); } #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")); #else lll = len & ~SSE_CUT_LEN_MASK; diff --git a/paddle/fluid/platform/denormal.cc b/paddle/fluid/platform/denormal.cc index 4cfb082544322d47749a748fed19af44743e1826..eca106af3dd673d27f36a25da9ec89cb5e515617 100644 --- a/paddle/fluid/platform/denormal.cc +++ b/paddle/fluid/platform/denormal.cc @@ -29,7 +29,8 @@ #endif #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 #endif diff --git a/paddle/phi/backends/cpu/cpu_info.cc b/paddle/phi/backends/cpu/cpu_info.cc index 74a8df11920d6480d04ebdeabf18edac0135d2c1..9d6b4e46df07d9b3834154cb7b65dc08e390cd70 100644 --- a/paddle/phi/backends/cpu/cpu_info.cc +++ b/paddle/phi/backends/cpu/cpu_info.cc @@ -165,8 +165,9 @@ bool MayIUse(const cpu_isa_t cpu_isa) { if (cpu_isa == isa_any) { return true; } else { -#if !defined(WITH_NV_JETSON) && !defined(PADDLE_WITH_ARM) && \ - !defined(PADDLE_WITH_SW) && !defined(PADDLE_WITH_MIPS) +#if !defined(WITH_NV_JETSON) && !defined(PADDLE_WITH_ARM) && \ + !defined(PADDLE_WITH_SW) && !defined(PADDLE_WITH_MIPS) && \ + !defined(PADDLE_WITH_LOONGARCH) int reg[4]; cpuid(reg, 0); int nIds = reg[0]; diff --git a/paddle/phi/backends/cpu/cpu_info.h b/paddle/phi/backends/cpu/cpu_info.h index 92a159c9b0aac2c6bd77e130ba7de60ce52b9565..3bc8551cd95d2932eef4883b410a7ee216f95ca6 100644 --- a/paddle/phi/backends/cpu/cpu_info.h +++ b/paddle/phi/backends/cpu/cpu_info.h @@ -40,8 +40,9 @@ #ifdef _WIN32 #define cpuid(reg, x) __cpuidex(reg, x, 0) #else -#if !defined(WITH_NV_JETSON) && !defined(PADDLE_WITH_ARM) && \ - !defined(PADDLE_WITH_SW) && !defined(PADDLE_WITH_MIPS) +#if !defined(WITH_NV_JETSON) && !defined(PADDLE_WITH_ARM) && \ + !defined(PADDLE_WITH_SW) && !defined(PADDLE_WITH_MIPS) && \ + !defined(PADDLE_WITH_LOONGARCH) #include inline void cpuid(int reg[4], int x) { __cpuid_count(x, 0, reg[0], reg[1], reg[2], reg[3]);