Add support for cross compiling.

Add support for not having host compiler as CMake cannot detect such a compiler.
Add support for not using getarch.
Successfully builds Android ARMV8. Any target can be added by supplying the TARGET_CORE config in prebuild.cmake.
This commit is contained in:
Sacha Refshauge 2017-08-20 20:08:53 +10:00
parent 11911fd941
commit 0a7a527a92
2 changed files with 86 additions and 11 deletions

View File

@ -38,12 +38,19 @@
# CPUIDEMU = ../../cpuid/table.o
# Cannot run getarch on target if we are cross-compiling
if(NOT CMAKE_CROSSCOMPILING)
if (DEFINED CPUIDEMU)
set(EXFLAGS "-DCPUIDEMU -DVENDOR=99")
endif ()
if(CMAKE_CROSSCOMPILING AND NOT DEFINED TARGET_CORE)
# Detect target without running getarch
if(AARCH64)
set(TARGET_CORE "ARMV8")
else()
message(FATAL_ERROR "When cross compiling, a TARGET_CORE is required.")
endif()
endif()
if (DEFINED TARGET_CORE)
# set the C flags for just this file
set(GETARCH2_FLAGS "-DBUILD_KERNEL")
@ -63,6 +70,73 @@ if (NOT NOFORTRAN)
include("${PROJECT_SOURCE_DIR}/cmake/f_check.cmake")
endif ()
# Cannot run getarch on target if we are cross-compiling
if (CMAKE_CROSSCOMPILING)
# Write to config as getarch would
# TODO: Set up defines that getarch sets up based on every other target
# Perhaps this should be inside a different file as it grows larger
file(APPEND ${TARGET_CONF_TEMP}
"#define ${TARGET_CORE}\n"
"#define CHAR_CORENAME \"${TARGET_CORE}\"\n")
if ("${TARGET_CORE}" STREQUAL "ARMV8")
file(APPEND ${TARGET_CONF_TEMP}
"#define L1_DATA_SIZE\t32768\n"
"#define L1_DATA_LINESIZE\t64\n"
"#define L2_SIZE\t262144\n"
"#define L2_LINESIZE\t64\n"
"#define DTB_DEFAULT_ENTRIES\t64\n"
"#define DTB_SIZE\t4096\n"
"#define L2_ASSOCIATIVE\t32\n")
set(SGEMM_UNROLL_M 4)
set(SGEMM_UNROLL_N 4)
elseif ("${TARGET_CORE}" STREQUAL "CORTEXA57")
file(APPEND ${TARGET_CONF_TEMP}
"#define L1_CODE_SIZE\t49152\n"
"#define L1_CODE_LINESIZE\t64\n"
"#define L1_CODE_ASSOCIATIVE\t3\n"
"#define L1_DATA_SIZE\t32768\n"
"#define L1_DATA_LINESIZE\t64\n"
"#define L1_DATA_ASSOCIATIVE\t2\n"
"#define L2_SIZE\t2097152\n"
"#define L2_LINESIZE\t64\n"
"#define L2_ASSOCIATIVE\t16\n"
"#define DTB_DEFAULT_ENTRIES\t64\n"
"#define DTB_SIZE\t4096\n"
"#define HAVE_VFPV4\n"
"#define HAVE_VFPV3\n"
"#define HAVE_VFP\n"
"#define HAVE_NEON\n")
set(SGEMM_DEFAULT_UNROLL_M 16)
set(SGEMM_DEFAULT_UNROLL_N 4)
set(DGEMM_DEFAULT_UNROLL_M 8)
set(DGEMM_DEFAULT_UNROLL_N 4)
set(CGEMM_DEFAULT_UNROLL_M 8)
set(CGEMM_DEFAULT_UNROLL_N 4)
set(ZGEMM_DEFAULT_UNROLL_M 8)
set(ZGEMM_DEFAULT_UNROLL_N 4)
endif()
# Or should this actually be NUM_CORES?
if (${NUM_THREADS} GREATER 0)
file(APPEND ${TARGET_CONF_TEMP} "#define NUM_CORES\t${NUM_THREADS}\n")
endif()
# GetArch_2nd
foreach(float_char S;D;Q;C;Z;X)
if (NOT DEFINED ${float_char}GEMM_UNROLL_M)
set(${float_char}GEMM_UNROLL_M 2)
endif()
if (NOT DEFINED ${float_char}GEMM_UNROLL_N)
set(${float_char}GEMM_UNROLL_N 2)
endif()
endforeach()
file(APPEND ${TARGET_CONF_TEMP}
"#define GEMM_MULTITHREAD_THRESHOLD\t${GEMM_MULTITHREAD_THRESHOLD}\n")
# Move to where gen_config_h would place it
file(RENAME ${TARGET_CONF_TEMP} "${PROJECT_BINARY_DIR}/config.h")
else()
# compile getarch
set(GETARCH_SRC
${PROJECT_SOURCE_DIR}/getarch.c
@ -161,4 +235,4 @@ if (NOT "${CMAKE_SYSTEM_NAME}" STREQUAL "WindowsStore")
endif ()
endif ()
endif(NOT CMAKE_CROSSCOMPILING)
endif(CMAKE_CROSSCOMPILING)

View File

@ -12,6 +12,9 @@ set(NETLIB_LAPACK_DIR "${PROJECT_SOURCE_DIR}/lapack-netlib")
# TARGET_CORE will override TARGET which is used in DYNAMIC_ARCH=1.
if (DEFINED TARGET_CORE)
set(TARGET ${TARGET_CORE})
if(NOT DEFINED CORE)
set(CORE ${TARGET_CORE})
endif()
endif ()
# Force fallbacks for 32bit
@ -72,8 +75,6 @@ else ()
set(ONLY_CBLAS 0)
endif ()
include("${PROJECT_SOURCE_DIR}/cmake/prebuild.cmake")
# N.B. this is NUM_THREAD in Makefile.system which is probably a bug -hpa
if (NOT CMAKE_CROSSCOMPILING)
if (NOT DEFINED NUM_CORES)
@ -86,22 +87,22 @@ if (NOT CMAKE_CROSSCOMPILING)
endif ()
endif()
if (NOT DEFINED NUM_THREADS)
set(NUM_THREADS 0)
endif()
if (${NUM_THREADS} LESS 2)
set(USE_THREAD 0)
elseif(NOT DEFINED USE_THREAD)
set(USE_THREAD 1)
endif ()
# TODO: Fix. Isn't working. Was never working in CMake.
# Undefined reference to get_num_procs, blas_thread_shutdown, ...
if (UNIX)
set(USE_THREAD 0)
endif()
if (USE_THREAD)
message(STATUS "Multi-threading enabled with ${NUM_THREADS} threads.")
endif ()
include("${PROJECT_SOURCE_DIR}/cmake/prebuild.cmake")
if (NOT DEFINED NEED_PIC)
set(NEED_PIC 1)
endif ()