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

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