Skip to content

Commit

Permalink
Merge pull request #4904 from XiWeiGu/la64_cross_cmake
Browse files Browse the repository at this point in the history
LoongArch64: Enable cmake cross-compilation
  • Loading branch information
martin-frbg authored Oct 3, 2024
2 parents edaf593 + 30af927 commit de421b7
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 2 deletions.
4 changes: 4 additions & 0 deletions cmake/arch.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ if (DYNAMIC_ARCH)
endif ()
endif ()

if (LOONGARCH64)
set(DYNAMIC_CORE LOONGSONGENERIC LOONGSON2K1000 LOONGSON3R5)
endif ()

if (EXISTS ${PROJECT_SOURCE_DIR}/config_kernel.h)
message (FATAL_ERROR "Your build directory contains a file config_kernel.h, probably from a previous compilation with make. This will conflict with the cmake compilation and cause strange compiler errors - please remove the file before trying again")
endif ()
Expand Down
48 changes: 48 additions & 0 deletions cmake/prebuild.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -1349,6 +1349,54 @@ endif ()
"#define DTB_DEFAULT_ENTRIES 128\n"
"#define DTB_SIZE 4096\n"
"#define L2_ASSOCIATIVE 4\n")
elseif ("${TCORE}" STREQUAL "LOONGSONGENERIC")
file(APPEND ${TARGET_CONF_TEMP}
"#define DTB_DEFAULT_ENTRIES 64\n")
set(SGEMM_UNROLL_M 2)
set(SGEMM_UNROLL_N 8)
set(DGEMM_UNROLL_M 2)
set(DGEMM_UNROLL_N 8)
set(CGEMM_UNROLL_M 1)
set(CGEMM_UNROLL_N 4)
set(ZGEMM_UNROLL_M 1)
set(ZGEMM_UNROLL_N 4)
set(CGEMM3M_UNROLL_M 2)
set(CGEMM3M_UNROLL_N 8)
set(ZGEMM3M_UNROLL_M 2)
set(ZGEMM3M_UNROLL_N 8)
elseif ("${TCORE}" STREQUAL "LOONGSON2K1000")
file(APPEND ${TARGET_CONF_TEMP}
"#define DTB_DEFAULT_ENTRIES 64\n")
set(HAVE_LSX 1)
set(SGEMM_UNROLL_M 2)
set(SGEMM_UNROLL_N 8)
set(DGEMM_UNROLL_M 8)
set(DGEMM_UNROLL_N 4)
set(CGEMM_UNROLL_M 8)
set(CGEMM_UNROLL_N 4)
set(ZGEMM_UNROLL_M 4)
set(ZGEMM_UNROLL_N 4)
set(CGEMM3M_UNROLL_M 2)
set(CGEMM3M_UNROLL_N 8)
set(ZGEMM3M_UNROLL_M 8)
set(ZGEMM3M_UNROLL_N 4)
elseif ("${TCORE}" STREQUAL "LOONGSON3R5")
file(APPEND ${TARGET_CONF_TEMP}
"#define DTB_DEFAULT_ENTRIES 64\n")
set(HAVE_LASX 1)
set(HAVE_LSX 1)
set(SGEMM_UNROLL_M 16)
set(SGEMM_UNROLL_N 8)
set(DGEMM_UNROLL_M 16)
set(DGEMM_UNROLL_N 6)
set(CGEMM_UNROLL_M 16)
set(CGEMM_UNROLL_N 4)
set(ZGEMM_UNROLL_M 8)
set(ZGEMM_UNROLL_N 4)
set(CGEMM3M_UNROLL_M 16)
set(CGEMM3M_UNROLL_N 8)
set(ZGEMM3M_UNROLL_M 16)
set(ZGEMM3M_UNROLL_N 6)
endif()
set(SBGEMM_UNROLL_M 8)
set(SBGEMM_UNROLL_N 4)
Expand Down
4 changes: 2 additions & 2 deletions cmake/system.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ if (NEED_PIC)
endif()
endif ()

if (X86_64 OR ${CORE} STREQUAL POWER10)
if (X86_64 OR ${CORE} STREQUAL POWER10 OR LOONGARCH64)
set(SMALL_MATRIX_OPT TRUE)
endif ()
if (ARM64)
Expand All @@ -403,7 +403,7 @@ if (SMALL_MATRIX_OPT)
endif ()

if (DYNAMIC_ARCH)
if (X86 OR X86_64 OR ARM64 OR POWER OR RISCV64)
if (X86 OR X86_64 OR ARM64 OR POWER OR RISCV64 OR LOONGARCH64)
set(CCOMMON_OPT "${CCOMMON_OPT} -DDYNAMIC_ARCH")
if (DYNAMIC_OLDER)
set(CCOMMON_OPT "${CCOMMON_OPT} -DDYNAMIC_OLDER")
Expand Down
2 changes: 2 additions & 0 deletions cmake/system_check.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ elseif(ARM)
set(ARCH "arm")
elseif(ARM64)
set(ARCH "arm64")
elseif(LOONGARCH64)
set(ARCH "loongarch64")
else()
set(ARCH ${CMAKE_SYSTEM_PROCESSOR} CACHE STRING "Target Architecture")
endif ()
Expand Down
2 changes: 2 additions & 0 deletions driver/others/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ if (DYNAMIC_ARCH)
list(APPEND COMMON_SOURCES dynamic_power.c)
elseif (RISCV64)
list(APPEND COMMON_SOURCES dynamic_riscv64.c detect_riscv64.c)
elseif (LOONGARCH64)
list(APPEND COMMON_SOURCES dynamic_loongarch64.c)
else ()
list(APPEND COMMON_SOURCES dynamic.c)
endif ()
Expand Down
6 changes: 6 additions & 0 deletions kernel/loongarch64/KERNEL.LOONGSONGENERIC
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
include $(KERNELDIR)/KERNEL

STRMMKERNEL = gemm_kernel.S
DTRMMKERNEL = gemm_kernel.S
CTRMMKERNEL = zgemm_kernel.S
ZTRMMKERNEL = zgemm_kernel.S

0 comments on commit de421b7

Please sign in to comment.