From 30af9278dcea8faf49b40cecd821a5a34bcab9eb Mon Sep 17 00:00:00 2001 From: gxw Date: Thu, 26 Sep 2024 16:55:06 +0800 Subject: [PATCH] LoongArch64: Enable cmake cross-compilation --- cmake/arch.cmake | 4 ++ cmake/prebuild.cmake | 48 +++++++++++++++++++++++ cmake/system.cmake | 4 +- cmake/system_check.cmake | 2 + driver/others/CMakeLists.txt | 2 + kernel/loongarch64/KERNEL.LOONGSONGENERIC | 6 +++ 6 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 kernel/loongarch64/KERNEL.LOONGSONGENERIC diff --git a/cmake/arch.cmake b/cmake/arch.cmake index 5f3703ae0b..0ff4f1df31 100644 --- a/cmake/arch.cmake +++ b/cmake/arch.cmake @@ -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 () diff --git a/cmake/prebuild.cmake b/cmake/prebuild.cmake index 609fbe2417..785c275c78 100644 --- a/cmake/prebuild.cmake +++ b/cmake/prebuild.cmake @@ -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) diff --git a/cmake/system.cmake b/cmake/system.cmake index a0b73ddae0..d697d69405 100644 --- a/cmake/system.cmake +++ b/cmake/system.cmake @@ -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) @@ -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") diff --git a/cmake/system_check.cmake b/cmake/system_check.cmake index e94497a048..59a1358789 100644 --- a/cmake/system_check.cmake +++ b/cmake/system_check.cmake @@ -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 () diff --git a/driver/others/CMakeLists.txt b/driver/others/CMakeLists.txt index 659449fbc2..139f329ecf 100644 --- a/driver/others/CMakeLists.txt +++ b/driver/others/CMakeLists.txt @@ -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 () diff --git a/kernel/loongarch64/KERNEL.LOONGSONGENERIC b/kernel/loongarch64/KERNEL.LOONGSONGENERIC new file mode 100644 index 0000000000..fc4c12008d --- /dev/null +++ b/kernel/loongarch64/KERNEL.LOONGSONGENERIC @@ -0,0 +1,6 @@ +include $(KERNELDIR)/KERNEL + +STRMMKERNEL = gemm_kernel.S +DTRMMKERNEL = gemm_kernel.S +CTRMMKERNEL = zgemm_kernel.S +ZTRMMKERNEL = zgemm_kernel.S