Skip to content

Commit

Permalink
chore: do not set C(XX)FLAGS for rvv (#55)
Browse files Browse the repository at this point in the history
Signed-off-by: xhe <xw897002528@gmail.com>
  • Loading branch information
xhebox authored Jul 20, 2023
1 parent 5794774 commit b8f7cc3
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 20 deletions.
22 changes: 10 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,25 @@ option(ENABLE_DOT "Build with Arm dotprod." OFF)
option(ENABLE_FP16 "Build with Arm FP16." OFF)
option(ENABLE_GPU "Build with GPU." OFF)
option(ENABLE_TEST "Build with TEST." OFF)
set(INFER_ARCH "auto" CACHE STRING "Build with specific ISA (x86/arm).")
set(INFER_ARCH "auto" CACHE STRING "Build with specific ISA (x86/arm/rvvXpX).")

if(${INFER_ARCH} STREQUAL "auto")
if (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64" OR ${CMAKE_SYSTEM_PROCESSOR} STREQUAL "AMD64")
set(INFER_ARCH "x86")
elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "aarch64" OR ${CMAKE_SYSTEM_PROCESSOR} STREQUAL "arm64")
set(INFER_ARCH "arm")
elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "riscv64")
set(INFER_ARCH "rv64v1p0")
elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "riscv64" OR ${CMAKE_SYSTEM_PROCESSOR} STREQUAL "riscv32")
set(INFER_ARCH "rvv1p0")
endif()
endif()

if(${INFER_ARCH} MATCHES "rv64v.p.")
string(SUBSTRING ${INFER_ARCH} 5 -1 RV64_VECVER)
set(CMAKE_C_FLAGS " -march=rv64imafdc_v${RV64_VECVER} ${CMAKE_C_FLAGS}")
set(CMAKE_CXX_FLAGS " -march=rv64imafdc_v${RV64_VECVER} ${CMAKE_CXX_FLAGS}")
string(REPLACE "p" "" RV64_VECVER ${RV64_VECVER})
string(PREPEND RV64_VECVER "1")
message(STATUS "current platform: ${INFER_ARCH} with ${RV64_VECVER}")
set(INFER_ARCH "rv64")
add_definitions(-DINFER_RV64=${RV64_VECVER})
if(${INFER_ARCH} MATCHES "rvv.p.")
string(SUBSTRING ${INFER_ARCH} 3 -1 RVV_VER)
string(REPLACE "p" "" RVV_VER ${RVV_VER})
string(PREPEND RVV_VER "1")
message(STATUS "current platform: ${INFER_ARCH} with ${RVV_VER}")
set(INFER_ARCH "rvv")
add_definitions(-DINFER_RVV=${RVV_VER})
elseif(${INFER_ARCH} STREQUAL "x86")
message(STATUS "current platform: x86")
set(INFER_ARCH "x86")
Expand Down
6 changes: 3 additions & 3 deletions src/kern/kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
#include "kern/optimized/x86/kernel.h"
#elif INFER_ARM
#include "kern/optimized/arm/kernel.h"
#elif INFER_RV64
#include "kern/optimized/rv64/kernel.h"
#elif INFER_RVV
#include "kern/optimized/rvv/kernel.h"
#else
#include "kern/naive/naive.h"
#endif
Expand All @@ -28,7 +28,7 @@ class Kernel {
Kernel(KernelType kernel_type) : m_kernel_type(kernel_type) {}
Kernel(KernelType kernel_type, ThreadPool* thread_pool)
: m_kernel_type(kernel_type), m_thread_pool(thread_pool) {
#ifdef INFER_RV64
#ifdef INFER_RVV
opt::init();
#endif
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#include "kern/optimized/rv64/common.h"
#include <algorithm>
#include <cmath>
#include <cstdlib>

#include "common.h"

namespace inferllm {
namespace opt {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ inline size_t mk_lmul(SEW sew, int sz) {
}

inline size_t mk_vtype(SEW sew, size_t LMUL) {
#if INFER_RV64 > 107
#if INFER_RVV > 107
return (sew << 3) | LMUL;
#else
return (sew << 2) | LMUL;
#endif
}

#if INFER_RV64 > 107
#if INFER_RVV > 107
#define VSET1(e, m) asm volatile("vsetivli x0, 1, " #e ", " #m);
#else
#define VSET1(e, m) asm volatile("vsetvli x0, %[sz], " #e ", " #m ::[sz] "r"(1));
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
#include <cstdlib>
#include "kern/kernel_define.h"
#include "kern/naive/quantize.h"
#include "kern/optimized/rv64/common.h"

#include "common.h"

namespace inferllm {
namespace opt {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
#include "kern/kernel_define.h"
#include "kern/naive/naive.h"
#include "kern/naive/quantize.h"
#include "kern/optimized/rv64/common.h"

#include "common.h"

namespace inferllm {
namespace opt {
Expand Down

0 comments on commit b8f7cc3

Please sign in to comment.