Skip to content

Commit

Permalink
Adding a compile option to Paddle for Risc-V
Browse files Browse the repository at this point in the history
  • Loading branch information
MiracleWater committed Sep 7, 2023
1 parent 95983a6 commit d3db383
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 7 deletions.
15 changes: 15 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,21 @@ if(WITH_ARM)
add_definitions(-DPADDLE_WITH_ARM)
endif()

if(WITH_RISCV)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
set(WITH_XBYAK
OFF
CACHE STRING "Disable XBYAK when compiling WITH_RISCV=ON." FORCE)
set(WITH_MKL
OFF
CACHE STRING "Disable MKL when compiling WITH_RISCV=ON." FORCE)
set(WITH_AVX
OFF
CACHE STRING "Disable AVX when compiling WITH_AVX=OFF." FORCE)
add_definitions(-DPADDLE_WITH_RISCV)
endif()

if(WITH_SW)
# mieee flag solves floating-point exceptions under sw and ALPHA architectures
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC -mieee")
Expand Down
1 change: 1 addition & 0 deletions cmake/flags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ if(NOT WIN32)
AND NOT WITH_ARM
AND NOT WITH_SW
AND NOT WITH_MIPS
AND NOT WITH_RISCV
AND NOT WITH_LOONGARCH)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m64")
endif()
Expand Down
3 changes: 3 additions & 0 deletions cmake/third_party.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,9 @@ if(WITH_POCKETFFT)
include(external/pocketfft)
list(APPEND third_party_deps extern_pocketfft)
add_definitions(-DPADDLE_WITH_POCKETFFT)
if(WITH_RISCV)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-maybe-uninitialized") # Warnings in pocketfft_hdronly.h
endif()
endif()

if(WIN32)
Expand Down
12 changes: 8 additions & 4 deletions paddle/fluid/operators/search_compute.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ limitations under the License. */
#pragma once

#if !defined(PADDLE_WITH_ARM) && !defined(PADDLE_WITH_SW) && \
!defined(PADDLE_WITH_MIPS) && !defined(PADDLE_WITH_LOONGARCH)
!defined(PADDLE_WITH_MIPS) && !defined(PADDLE_WITH_LOONGARCH) && \
!defined(PADDLE_WITH_RISCV)
#include <immintrin.h>
#endif
#include <cfloat>
Expand Down Expand Up @@ -103,7 +104,8 @@ void call_gemm_batched(const framework::ExecutionContext& ctx,
}

#if !defined(PADDLE_WITH_ARM) && !defined(PADDLE_WITH_SW) && \
!defined(PADDLE_WITH_MIPS) && !defined(PADDLE_WITH_LOONGARCH)
!defined(PADDLE_WITH_MIPS) && !defined(PADDLE_WITH_LOONGARCH) && \
!defined(PADDLE_WITH_RISCV)

#define __m256x __m256

Expand Down Expand Up @@ -144,7 +146,8 @@ 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_LOONGARCH)
defined(PADDLE_WITH_MIPS) || defined(PADDLE_WITH_LOONGARCH) || \
defined(PADDLE_WITH_RISCV)
PADDLE_THROW(platform::errors::Unimplemented("axpy is not supported"));
#else
lll = len & ~SSE_CUT_LEN_MASK;
Expand Down Expand Up @@ -174,7 +177,8 @@ 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_LOONGARCH)
defined(PADDLE_WITH_MIPS) || defined(PADDLE_WITH_LOONGARCH) || \
defined(PADDLE_WITH_RISCV)
PADDLE_THROW(platform::errors::Unimplemented("axpy_noadd is not supported"));
#else
lll = len & ~SSE_CUT_LEN_MASK;
Expand Down
3 changes: 2 additions & 1 deletion paddle/fluid/platform/denormal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@

#if !defined(GCC_WITHOUT_INTRINSICS) && !defined(PADDLE_WITH_ARM) && \
!defined(PADDLE_WITH_SW) && !defined(PADDLE_WITH_MIPS) && \
!defined(_WIN32) && !defined(PADDLE_WITH_LOONGARCH)
!defined(_WIN32) && !defined(PADDLE_WITH_LOONGARCH) && \
!defined(PADDLE_WITH_RISCV)
#define DENORM_USE_INTRINSICS
#endif

Expand Down
2 changes: 1 addition & 1 deletion paddle/phi/backends/cpu/cpu_info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ bool MayIUse(const cpu_isa_t cpu_isa) {
} else {
#if !defined(WITH_NV_JETSON) && !defined(PADDLE_WITH_ARM) && \
!defined(PADDLE_WITH_SW) && !defined(PADDLE_WITH_MIPS) && \
!defined(PADDLE_WITH_LOONGARCH)
!defined(PADDLE_WITH_LOONGARCH) && !defined(PADDLE_WITH_RISCV)
std::array<int, 4> reg;
cpuid(reg.data(), 0);
int nIds = reg[0];
Expand Down
2 changes: 1 addition & 1 deletion paddle/phi/backends/cpu/cpu_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
#else
#if !defined(WITH_NV_JETSON) && !defined(PADDLE_WITH_ARM) && \
!defined(PADDLE_WITH_SW) && !defined(PADDLE_WITH_MIPS) && \
!defined(PADDLE_WITH_LOONGARCH)
!defined(PADDLE_WITH_LOONGARCH) && !defined(PADDLE_WITH_RISCV)
#include <cpuid.h>
inline void cpuid(int reg[4], int x) {
__cpuid_count(x, 0, reg[0], reg[1], reg[2], reg[3]);
Expand Down

0 comments on commit d3db383

Please sign in to comment.