You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

system.cmake 12 kB

7 years ago
7 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506
  1. ##
  2. ## Author: Hank Anderson <hank@statease.com>
  3. ## Description: Ported from OpenBLAS/Makefile.system
  4. ##
  5. set(NETLIB_LAPACK_DIR "${PROJECT_SOURCE_DIR}/lapack-netlib")
  6. # System detection, via CMake.
  7. include("${PROJECT_SOURCE_DIR}/cmake/system_check.cmake")
  8. if(CMAKE_CROSSCOMPILING AND NOT DEFINED TARGET)
  9. # Detect target without running getarch
  10. if (ARM64)
  11. set(TARGET "ARMV8")
  12. elseif(ARM)
  13. set(TARGET "ARMV7") # TODO: Ask compiler which arch this is
  14. else()
  15. message(FATAL_ERROR "When cross compiling, a TARGET is required.")
  16. endif()
  17. endif()
  18. # Other files expect CORE, which is actually TARGET and will become TARGET_CORE for kernel build. Confused yet?
  19. # It seems we are meant to use TARGET as input and CORE internally as kernel.
  20. if(NOT DEFINED CORE AND DEFINED TARGET)
  21. set(CORE ${TARGET})
  22. endif()
  23. # TARGET_CORE will override TARGET which is used in DYNAMIC_ARCH=1.
  24. if (DEFINED TARGET_CORE)
  25. set(TARGET ${TARGET_CORE})
  26. endif ()
  27. # Force fallbacks for 32bit
  28. if (DEFINED BINARY AND DEFINED TARGET AND BINARY EQUAL 32)
  29. message(STATUS "Compiling a ${BINARY}-bit binary.")
  30. set(NO_AVX 1)
  31. if (${TARGET} STREQUAL "HASWELL" OR ${TARGET} STREQUAL "SANDYBRIDGE" OR ${TARGET} STREQUAL "SKYLAKEX")
  32. set(TARGET "NEHALEM")
  33. endif ()
  34. if (${TARGET} STREQUAL "BULLDOZER" OR ${TARGET} STREQUAL "PILEDRIVER" OR ${TARGET} STREQUAL "ZEN")
  35. set(TARGET "BARCELONA")
  36. endif ()
  37. endif ()
  38. if (DEFINED TARGET)
  39. if (${TARGET} STREQUAL "SKYLAKEX" AND NOT NO_AVX512)
  40. set (KERNEL_DEFINITIONS "${KERNEL_DEFINITIONS} -march=skylake-avx512")
  41. endif()
  42. endif()
  43. if (DEFINED TARGET)
  44. message(STATUS "Targeting the ${TARGET} architecture.")
  45. set(GETARCH_FLAGS "-DFORCE_${TARGET}")
  46. endif ()
  47. if (INTERFACE64)
  48. message(STATUS "Using 64-bit integers.")
  49. set(GETARCH_FLAGS "${GETARCH_FLAGS} -DUSE64BITINT")
  50. endif ()
  51. if (NOT DEFINED GEMM_MULTITHREAD_THRESHOLD)
  52. set(GEMM_MULTITHREAD_THRESHOLD 4)
  53. endif ()
  54. message(STATUS "GEMM multithread threshold set to ${GEMM_MULTITHREAD_THRESHOLD}.")
  55. set(GETARCH_FLAGS "${GETARCH_FLAGS} -DGEMM_MULTITHREAD_THRESHOLD=${GEMM_MULTITHREAD_THRESHOLD}")
  56. if (NO_AVX)
  57. message(STATUS "Disabling Advanced Vector Extensions (AVX).")
  58. set(GETARCH_FLAGS "${GETARCH_FLAGS} -DNO_AVX")
  59. endif ()
  60. if (NO_AVX2)
  61. message(STATUS "Disabling Advanced Vector Extensions 2 (AVX2).")
  62. set(GETARCH_FLAGS "${GETARCH_FLAGS} -DNO_AVX2")
  63. endif ()
  64. if (CMAKE_BUILD_TYPE STREQUAL "Debug")
  65. set(GETARCH_FLAGS "${GETARCH_FLAGS} ${CMAKE_C_FLAGS_DEBUG}")
  66. endif ()
  67. if (NOT DEFINED NO_PARALLEL_MAKE)
  68. set(NO_PARALLEL_MAKE 0)
  69. endif ()
  70. set(GETARCH_FLAGS "${GETARCH_FLAGS} -DNO_PARALLEL_MAKE=${NO_PARALLEL_MAKE}")
  71. if (CMAKE_C_COMPILER STREQUAL loongcc)
  72. set(GETARCH_FLAGS "${GETARCH_FLAGS} -static")
  73. endif ()
  74. #if don't use Fortran, it will only compile CBLAS.
  75. if (ONLY_CBLAS)
  76. set(NO_LAPACK 1)
  77. else ()
  78. set(ONLY_CBLAS 0)
  79. endif ()
  80. # N.B. this is NUM_THREAD in Makefile.system which is probably a bug -hpa
  81. if (NOT CMAKE_CROSSCOMPILING)
  82. if (NOT DEFINED NUM_CORES)
  83. include(ProcessorCount)
  84. ProcessorCount(NUM_CORES)
  85. endif()
  86. endif()
  87. if (NOT DEFINED NUM_PARALLEL)
  88. set(NUM_PARALLEL 1)
  89. endif()
  90. if (NOT DEFINED NUM_THREADS)
  91. if (DEFINED NUM_CORES AND NOT NUM_CORES EQUAL 0)
  92. # HT?
  93. set(NUM_THREADS ${NUM_CORES})
  94. else ()
  95. set(NUM_THREADS 0)
  96. endif ()
  97. endif()
  98. if (${NUM_THREADS} LESS 2)
  99. set(USE_THREAD 0)
  100. elseif(NOT DEFINED USE_THREAD)
  101. set(USE_THREAD 1)
  102. endif ()
  103. if (USE_THREAD)
  104. message(STATUS "Multi-threading enabled with ${NUM_THREADS} threads.")
  105. endif ()
  106. include("${PROJECT_SOURCE_DIR}/cmake/prebuild.cmake")
  107. if (NOT DEFINED NEED_PIC)
  108. set(NEED_PIC 1)
  109. endif ()
  110. # OS dependent settings
  111. include("${PROJECT_SOURCE_DIR}/cmake/os.cmake")
  112. # Architecture dependent settings
  113. include("${PROJECT_SOURCE_DIR}/cmake/arch.cmake")
  114. # C Compiler dependent settings
  115. include("${PROJECT_SOURCE_DIR}/cmake/cc.cmake")
  116. if (NOT NOFORTRAN)
  117. # Fortran Compiler dependent settings
  118. include("${PROJECT_SOURCE_DIR}/cmake/fc.cmake")
  119. endif ()
  120. if (BINARY64)
  121. if (INTERFACE64)
  122. # CCOMMON_OPT += -DUSE64BITINT
  123. endif ()
  124. endif ()
  125. if (NEED_PIC)
  126. if (${CMAKE_C_COMPILER} STREQUAL "IBM")
  127. set(CCOMMON_OPT "${CCOMMON_OPT} -qpic=large")
  128. else ()
  129. set(CCOMMON_OPT "${CCOMMON_OPT} -fPIC")
  130. endif ()
  131. if (NOT NOFORTRAN)
  132. if (${F_COMPILER} STREQUAL "SUN")
  133. set(FCOMMON_OPT "${FCOMMON_OPT} -pic")
  134. else ()
  135. set(FCOMMON_OPT "${FCOMMON_OPT} -fPIC")
  136. endif ()
  137. endif()
  138. endif ()
  139. if (DYNAMIC_ARCH)
  140. set(CCOMMON_OPT "${CCOMMON_OPT} -DDYNAMIC_ARCH")
  141. if (DYNAMIC_OLDER)
  142. set(CCOMMON_OPT "${CCOMMON_OPT} -DDYNAMIC_OLDER")
  143. endif ()
  144. endif ()
  145. if (NO_LAPACK)
  146. set(CCOMMON_OPT "${CCOMMON_OPT} -DNO_LAPACK")
  147. #Disable LAPACK C interface
  148. set(NO_LAPACKE 1)
  149. endif ()
  150. if (NO_LAPACKE)
  151. set(CCOMMON_OPT "${CCOMMON_OPT} -DNO_LAPACKE")
  152. endif ()
  153. if (NO_AVX)
  154. set(CCOMMON_OPT "${CCOMMON_OPT} -DNO_AVX")
  155. endif ()
  156. if (X86)
  157. set(CCOMMON_OPT "${CCOMMON_OPT} -DNO_AVX")
  158. endif ()
  159. if (NO_AVX2)
  160. set(CCOMMON_OPT "${CCOMMON_OPT} -DNO_AVX2")
  161. endif ()
  162. if (USE_THREAD)
  163. # USE_SIMPLE_THREADED_LEVEL3 = 1
  164. # NO_AFFINITY = 1
  165. set(CCOMMON_OPT "${CCOMMON_OPT} -DSMP_SERVER")
  166. if (MIPS64)
  167. if (NOT ${CORE} STREQUAL "LOONGSON3B")
  168. set(USE_SIMPLE_THREADED_LEVEL3 1)
  169. endif ()
  170. endif ()
  171. if (BIGNUMA)
  172. set(CCOMMON_OPT "${CCOMMON_OPT} -DBIGNUMA")
  173. endif ()
  174. endif ()
  175. if (NO_WARMUP)
  176. set(CCOMMON_OPT "${CCOMMON_OPT} -DNO_WARMUP")
  177. endif ()
  178. if (CONSISTENT_FPCSR)
  179. set(CCOMMON_OPT "${CCOMMON_OPT} -DCONSISTENT_FPCSR")
  180. endif ()
  181. if (USE_TLS)
  182. set(CCOMMON_OPT "${CCOMMON_OPT} -DUSE_TLS")
  183. endif ()
  184. # Only for development
  185. # set(CCOMMON_OPT "${CCOMMON_OPT} -DPARAMTEST")
  186. # set(CCOMMON_OPT "${CCOMMON_OPT} -DPREFETCHTEST")
  187. # set(CCOMMON_OPT "${CCOMMON_OPT} -DNO_SWITCHING")
  188. # set(USE_PAPI 1)
  189. if (USE_PAPI)
  190. set(CCOMMON_OPT "${CCOMMON_OPT} -DUSE_PAPI")
  191. set(EXTRALIB "${EXTRALIB} -lpapi -lperfctr")
  192. endif ()
  193. if (DYNAMIC_THREADS)
  194. set(CCOMMON_OPT "${CCOMMON_OPT} -DDYNAMIC_THREADS")
  195. endif ()
  196. set(CCOMMON_OPT "${CCOMMON_OPT} -DMAX_CPU_NUMBER=${NUM_THREADS}")
  197. set(CCOMMON_OPT "${CCOMMON_OPT} -DMAX_PARALLEL_NUMBER=${NUM_PARALLEL}")
  198. if (USE_SIMPLE_THREADED_LEVEL3)
  199. set(CCOMMON_OPT "${CCOMMON_OPT} -DUSE_SIMPLE_THREADED_LEVEL3")
  200. endif ()
  201. if (DEFINED LIBNAMESUFFIX)
  202. set(LIBPREFIX "libopenblas_${LIBNAMESUFFIX}")
  203. else ()
  204. set(LIBPREFIX "libopenblas")
  205. endif ()
  206. if (NOT DEFINED SYMBOLPREFIX)
  207. set(SYMBOLPREFIX "")
  208. endif ()
  209. if (NOT DEFINED SYMBOLSUFFIX)
  210. set(SYMBOLSUFFIX "")
  211. endif ()
  212. set(KERNELDIR "${PROJECT_SOURCE_DIR}/kernel/${ARCH}")
  213. # TODO: nead to convert these Makefiles
  214. # include ${PROJECT_SOURCE_DIR}/cmake/${ARCH}.cmake
  215. if (${CORE} STREQUAL "PPC440")
  216. set(CCOMMON_OPT "${CCOMMON_OPT} -DALLOC_QALLOC")
  217. endif ()
  218. if (${CORE} STREQUAL "PPC440FP2")
  219. set(STATIC_ALLOCATION 1)
  220. endif ()
  221. if (NOT ${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
  222. set(NO_AFFINITY 1)
  223. endif ()
  224. if (NOT X86_64 AND NOT X86 AND NOT ${CORE} STREQUAL "LOONGSON3B")
  225. set(NO_AFFINITY 1)
  226. endif ()
  227. if (NO_AFFINITY)
  228. set(CCOMMON_OPT "${CCOMMON_OPT} -DNO_AFFINITY")
  229. endif ()
  230. if (FUNCTION_PROFILE)
  231. set(CCOMMON_OPT "${CCOMMON_OPT} -DFUNCTION_PROFILE")
  232. endif ()
  233. if (HUGETLB_ALLOCATION)
  234. set(CCOMMON_OPT "${CCOMMON_OPT} -DALLOC_HUGETLB")
  235. endif ()
  236. if (DEFINED HUGETLBFILE_ALLOCATION)
  237. set(CCOMMON_OPT "${CCOMMON_OPT} -DALLOC_HUGETLBFILE -DHUGETLB_FILE_NAME=${HUGETLBFILE_ALLOCATION})")
  238. endif ()
  239. if (STATIC_ALLOCATION)
  240. set(CCOMMON_OPT "${CCOMMON_OPT} -DALLOC_STATIC")
  241. endif ()
  242. if (DEVICEDRIVER_ALLOCATION)
  243. set(CCOMMON_OPT "${CCOMMON_OPT} -DALLOC_DEVICEDRIVER -DDEVICEDRIVER_NAME=\"/dev/mapper\"")
  244. endif ()
  245. if (MIXED_MEMORY_ALLOCATION)
  246. set(CCOMMON_OPT "${CCOMMON_OPT} -DMIXED_MEMORY_ALLOCATION")
  247. endif ()
  248. set(REVISION "-r${OpenBLAS_VERSION}")
  249. set(MAJOR_VERSION ${OpenBLAS_MAJOR_VERSION})
  250. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CCOMMON_OPT}")
  251. if(NOT MSVC)
  252. set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} ${CCOMMON_OPT}")
  253. endif()
  254. # TODO: not sure what PFLAGS is -hpa
  255. set(PFLAGS "${PFLAGS} ${CCOMMON_OPT} -I${TOPDIR} -DPROFILE ${COMMON_PROF}")
  256. set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${FCOMMON_OPT}")
  257. # TODO: not sure what FPFLAGS is -hpa
  258. set(FPFLAGS "${FPFLAGS} ${FCOMMON_OPT} ${COMMON_PROF}")
  259. #For LAPACK Fortran codes.
  260. set(LAPACK_FFLAGS "${LAPACK_FFLAGS} ${CMAKE_Fortran_FLAGS}")
  261. set(LAPACK_FPFLAGS "${LAPACK_FPFLAGS} ${FPFLAGS}")
  262. #Disable -fopenmp for LAPACK Fortran codes on Windows.
  263. if (${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
  264. set(FILTER_FLAGS "-fopenmp;-mp;-openmp;-xopenmp=parallel")
  265. foreach (FILTER_FLAG ${FILTER_FLAGS})
  266. string(REPLACE ${FILTER_FLAG} "" LAPACK_FFLAGS ${LAPACK_FFLAGS})
  267. string(REPLACE ${FILTER_FLAG} "" LAPACK_FPFLAGS ${LAPACK_FPFLAGS})
  268. endforeach ()
  269. endif ()
  270. if ("${F_COMPILER}" STREQUAL "GFORTRAN")
  271. # lapack-netlib is rife with uninitialized warnings -hpa
  272. set(LAPACK_FFLAGS "${LAPACK_FFLAGS} -Wno-maybe-uninitialized")
  273. endif ()
  274. set(LAPACK_CFLAGS "${CMAKE_C_CFLAGS} -DHAVE_LAPACK_CONFIG_H")
  275. if (INTERFACE64)
  276. set(LAPACK_CFLAGS "${LAPACK_CFLAGS} -DLAPACK_ILP64")
  277. endif ()
  278. if (${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
  279. set(LAPACK_CFLAGS "${LAPACK_CFLAGS} -DOPENBLAS_OS_WINDOWS")
  280. endif ()
  281. if (${CMAKE_C_COMPILER} STREQUAL "LSB" OR ${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
  282. set(LAPACK_CFLAGS "${LAPACK_CFLAGS} -DLAPACK_COMPLEX_STRUCTURE")
  283. endif ()
  284. if (NOT DEFINED SUFFIX)
  285. set(SUFFIX o)
  286. endif ()
  287. if (NOT DEFINED PSUFFIX)
  288. set(PSUFFIX po)
  289. endif ()
  290. if (NOT DEFINED LIBSUFFIX)
  291. set(LIBSUFFIX a)
  292. endif ()
  293. if (DYNAMIC_ARCH)
  294. if (USE_THREAD)
  295. set(LIBNAME "${LIBPREFIX}p${REVISION}.${LIBSUFFIX}")
  296. set(LIBNAME_P "${LIBPREFIX}p${REVISION}_p.${LIBSUFFIX}")
  297. else ()
  298. set(LIBNAME "${LIBPREFIX}${REVISION}.${LIBSUFFIX}")
  299. set(LIBNAME_P "${LIBPREFIX}${REVISION}_p.${LIBSUFFIX}")
  300. endif ()
  301. else ()
  302. if (USE_THREAD)
  303. set(LIBNAME "${LIBPREFIX}_${LIBCORE}p${REVISION}.${LIBSUFFIX}")
  304. set(LIBNAME_P "${LIBPREFIX}_${LIBCORE}p${REVISION}_p.${LIBSUFFIX}")
  305. else ()
  306. set(LIBNAME "${LIBPREFIX}_${LIBCORE}${REVISION}.${LIBSUFFIX}")
  307. set(LIBNAME_P "${LIBPREFIX}_${LIBCORE}${REVISION}_p.${LIBSUFFIX}")
  308. endif ()
  309. endif ()
  310. set(LIBDLLNAME "${LIBPREFIX}.dll")
  311. set(LIBSONAME "${LIBNAME}.${LIBSUFFIX}.so")
  312. set(LIBDYNNAME "${LIBNAME}.${LIBSUFFIX}.dylib")
  313. set(LIBDEFNAME "${LIBNAME}.${LIBSUFFIX}.def")
  314. set(LIBEXPNAME "${LIBNAME}.${LIBSUFFIX}.exp")
  315. set(LIBZIPNAME "${LIBNAME}.${LIBSUFFIX}.zip")
  316. set(LIBS "${PROJECT_SOURCE_DIR}/${LIBNAME}")
  317. set(LIBS_P "${PROJECT_SOURCE_DIR}/${LIBNAME_P}")
  318. set(LIB_COMPONENTS BLAS)
  319. if (NOT NO_CBLAS)
  320. set(LIB_COMPONENTS "${LIB_COMPONENTS} CBLAS")
  321. endif ()
  322. if (NOT NO_LAPACK)
  323. set(LIB_COMPONENTS "${LIB_COMPONENTS} LAPACK")
  324. if (NOT NO_LAPACKE)
  325. set(LIB_COMPONENTS "${LIB_COMPONENTS} LAPACKE")
  326. endif ()
  327. if (BUILD_RELAPACK)
  328. set(LIB_COMPONENTS "${LIB_COMPONENTS} ReLAPACK")
  329. endif ()
  330. endif ()
  331. if (ONLY_CBLAS)
  332. set(LIB_COMPONENTS CBLAS)
  333. endif ()
  334. # For GEMM3M
  335. set(USE_GEMM3M 0)
  336. if (DEFINED ARCH)
  337. if (X86 OR X86_64 OR ${ARCH} STREQUAL "ia64" OR MIPS64)
  338. set(USE_GEMM3M 1)
  339. endif ()
  340. if (${CORE} STREQUAL "generic")
  341. set(USE_GEMM3M 0)
  342. endif ()
  343. endif ()
  344. #export OSNAME
  345. #export ARCH
  346. #export CORE
  347. #export LIBCORE
  348. #export PGCPATH
  349. #export CONFIG
  350. #export CC
  351. #export FC
  352. #export BU
  353. #export FU
  354. #export NEED2UNDERSCORES
  355. #export USE_THREAD
  356. #export NUM_THREADS
  357. #export NUM_CORES
  358. #export SMP
  359. #export MAKEFILE_RULE
  360. #export NEED_PIC
  361. #export BINARY
  362. #export BINARY32
  363. #export BINARY64
  364. #export F_COMPILER
  365. #export C_COMPILER
  366. #export USE_OPENMP
  367. #export CROSS
  368. #export CROSS_SUFFIX
  369. #export NOFORTRAN
  370. #export NO_FBLAS
  371. #export EXTRALIB
  372. #export CEXTRALIB
  373. #export FEXTRALIB
  374. #export HAVE_SSE
  375. #export HAVE_SSE2
  376. #export HAVE_SSE3
  377. #export HAVE_SSSE3
  378. #export HAVE_SSE4_1
  379. #export HAVE_SSE4_2
  380. #export HAVE_SSE4A
  381. #export HAVE_SSE5
  382. #export HAVE_AVX
  383. #export HAVE_VFP
  384. #export HAVE_VFPV3
  385. #export HAVE_VFPV4
  386. #export HAVE_NEON
  387. #export KERNELDIR
  388. #export FUNCTION_PROFILE
  389. #export TARGET_CORE
  390. #
  391. #export SGEMM_UNROLL_M
  392. #export SGEMM_UNROLL_N
  393. #export DGEMM_UNROLL_M
  394. #export DGEMM_UNROLL_N
  395. #export QGEMM_UNROLL_M
  396. #export QGEMM_UNROLL_N
  397. #export CGEMM_UNROLL_M
  398. #export CGEMM_UNROLL_N
  399. #export ZGEMM_UNROLL_M
  400. #export ZGEMM_UNROLL_N
  401. #export XGEMM_UNROLL_M
  402. #export XGEMM_UNROLL_N
  403. #export CGEMM3M_UNROLL_M
  404. #export CGEMM3M_UNROLL_N
  405. #export ZGEMM3M_UNROLL_M
  406. #export ZGEMM3M_UNROLL_N
  407. #export XGEMM3M_UNROLL_M
  408. #export XGEMM3M_UNROLL_N
  409. #if (USE_CUDA)
  410. # export CUDADIR
  411. # export CUCC
  412. # export CUFLAGS
  413. # export CULIB
  414. #endif