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

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