build.yml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455
  1. name: CI
  2. on:
  3. workflow_dispatch: # allows manual triggering
  4. inputs:
  5. create_release:
  6. description: 'Create new release'
  7. required: true
  8. type: boolean
  9. push:
  10. branches:
  11. - master
  12. paths: ['.github/workflows/**', '**/CMakeLists.txt', '**/Makefile', '**/*.h', '**/*.c', '**/*.cpp']
  13. pull_request:
  14. types: [opened, synchronize, reopened]
  15. paths: ['**/CMakeLists.txt', '**/Makefile', '**/*.h', '**/*.c', '**/*.cpp']
  16. env:
  17. BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
  18. jobs:
  19. ubuntu-focal-make:
  20. runs-on: ubuntu-20.04
  21. steps:
  22. - name: Clone
  23. id: checkout
  24. uses: actions/checkout@v1
  25. - name: Dependencies
  26. id: depends
  27. run: |
  28. sudo apt-get update
  29. sudo apt-get install build-essential gcc-8
  30. - name: Build
  31. id: make_build
  32. run: |
  33. CC=gcc-8 make
  34. ubuntu-latest-cmake:
  35. runs-on: ubuntu-latest
  36. steps:
  37. - name: Clone
  38. id: checkout
  39. uses: actions/checkout@v1
  40. - name: Dependencies
  41. id: depends
  42. run: |
  43. sudo apt-get update
  44. sudo apt-get install build-essential
  45. - name: Build
  46. id: cmake_build
  47. run: |
  48. mkdir build
  49. cd build
  50. cmake ..
  51. cmake --build . --config Release
  52. - name: Test
  53. id: cmake_test
  54. run: |
  55. cd build
  56. ctest --verbose
  57. ubuntu-latest-cmake-sanitizer:
  58. runs-on: ubuntu-latest
  59. continue-on-error: true
  60. strategy:
  61. matrix:
  62. sanitizer: [ADDRESS, THREAD, UNDEFINED]
  63. build_type: [Debug, Release]
  64. steps:
  65. - name: Clone
  66. id: checkout
  67. uses: actions/checkout@v1
  68. - name: Dependencies
  69. id: depends
  70. run: |
  71. sudo apt-get update
  72. sudo apt-get install build-essential
  73. - name: Build
  74. id: cmake_build
  75. run: |
  76. mkdir build
  77. cd build
  78. cmake .. -DLLAMA_SANITIZE_${{ matrix.sanitizer }}=ON -DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
  79. cmake --build . --config ${{ matrix.build_type }}
  80. - name: Test
  81. id: cmake_test
  82. run: |
  83. cd build
  84. ctest --verbose
  85. macOS-latest-make:
  86. runs-on: macos-latest
  87. steps:
  88. - name: Clone
  89. id: checkout
  90. uses: actions/checkout@v1
  91. - name: Dependencies
  92. id: depends
  93. run: |
  94. brew update
  95. - name: Build
  96. id: make_build
  97. run: |
  98. make
  99. macOS-latest-cmake:
  100. runs-on: macOS-latest
  101. steps:
  102. - name: Clone
  103. id: checkout
  104. uses: actions/checkout@v1
  105. - name: Dependencies
  106. id: depends
  107. run: |
  108. brew update
  109. - name: Build
  110. id: cmake_build
  111. run: |
  112. mkdir build
  113. cd build
  114. cmake -DLLAMA_AVX2=OFF ..
  115. cmake --build . --config Release
  116. - name: Test
  117. id: cmake_test
  118. run: |
  119. cd build
  120. ctest --verbose
  121. windows-latest-cmake:
  122. runs-on: windows-latest
  123. strategy:
  124. matrix:
  125. include:
  126. - build: 'avx2'
  127. defines: ''
  128. - build: 'avx'
  129. defines: '-DLLAMA_AVX2=OFF'
  130. - build: 'avx512'
  131. defines: '-DLLAMA_AVX512=ON -DBUILD_SHARED_LIBS=ON'
  132. steps:
  133. - name: Clone
  134. id: checkout
  135. uses: actions/checkout@v1
  136. - name: Build
  137. id: cmake_build
  138. run: |
  139. mkdir build
  140. cd build
  141. cmake .. ${{ matrix.defines }}
  142. cmake --build . --config Release
  143. - name: Check AVX512F support
  144. id: check_avx512f
  145. if: ${{ matrix.build == 'avx512' }}
  146. continue-on-error: true
  147. run: |
  148. cd build
  149. $vcdir = $(vswhere -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath)
  150. $msvc = $(join-path $vcdir $('VC\Tools\MSVC\'+$(gc -raw $(join-path $vcdir 'VC\Auxiliary\Build\Microsoft.VCToolsVersion.default.txt')).Trim()))
  151. $cl = $(join-path $msvc 'bin\Hostx64\x64\cl.exe')
  152. echo 'int main(void){unsigned int a[4];__cpuid(a,7);return !(a[1]&65536);}' >> avx512f.c
  153. & $cl /O2 /GS- /kernel avx512f.c /link /nodefaultlib /entry:main
  154. .\avx512f.exe && echo "AVX512F: YES" && ( echo HAS_AVX512F=1 >> $env:GITHUB_ENV ) || echo "AVX512F: NO"
  155. - name: Test
  156. id: cmake_test
  157. if: ${{ matrix.build != 'avx512' || env.HAS_AVX512F == '1' }} # Test AVX-512 only when possible
  158. run: |
  159. cd build
  160. ctest -C Release --verbose
  161. - name: Get commit hash
  162. id: commit
  163. if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }}
  164. uses: pr-mpt/actions-commit-hash@v2
  165. - name: Pack artifacts
  166. id: pack_artifacts
  167. if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }}
  168. run: |
  169. 7z a llama-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-win-${{ matrix.build }}-x64.zip .\build\bin\Release\*
  170. - name: Upload artifacts
  171. if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }}
  172. uses: actions/upload-artifact@v3
  173. with:
  174. path: |
  175. llama-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-win-${{ matrix.build }}-x64.zip
  176. release:
  177. if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }}
  178. runs-on: ubuntu-latest
  179. needs:
  180. - ubuntu-focal-make
  181. - ubuntu-latest-cmake
  182. - macOS-latest-make
  183. - macOS-latest-cmake
  184. - windows-latest-cmake
  185. steps:
  186. - name: Download artifacts
  187. id: download-artifact
  188. uses: actions/download-artifact@v3
  189. - name: Get commit hash
  190. id: commit
  191. uses: pr-mpt/actions-commit-hash@v2
  192. - name: Create release
  193. id: create_release
  194. uses: anzz1/action-create-release@v1
  195. env:
  196. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  197. with:
  198. tag_name: ${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}
  199. - name: Upload release
  200. id: upload_release
  201. uses: actions/github-script@v3
  202. with:
  203. github-token: ${{secrets.GITHUB_TOKEN}}
  204. script: |
  205. const path = require('path');
  206. const fs = require('fs');
  207. const release_id = '${{ steps.create_release.outputs.id }}';
  208. for (let file of await fs.readdirSync('./artifact')) {
  209. if (path.extname(file) === '.zip') {
  210. console.log('uploadReleaseAsset', file);
  211. await github.repos.uploadReleaseAsset({
  212. owner: context.repo.owner,
  213. repo: context.repo.repo,
  214. release_id: release_id,
  215. name: file,
  216. data: await fs.readFileSync(`./artifact/${file}`)
  217. });
  218. }
  219. }
  220. # ubuntu-latest-gcc:
  221. # runs-on: ubuntu-latest
  222. #
  223. # strategy:
  224. # matrix:
  225. # build: [Debug, Release]
  226. #
  227. # steps:
  228. # - name: Clone
  229. # uses: actions/checkout@v1
  230. #
  231. # - name: Dependencies
  232. # run: |
  233. # sudo apt-get update
  234. # sudo apt-get install build-essential
  235. # sudo apt-get install cmake
  236. #
  237. # - name: Configure
  238. # run: cmake . -DCMAKE_BUILD_TYPE=${{ matrix.build }}
  239. #
  240. # - name: Build
  241. # run: |
  242. # make
  243. #
  244. # ubuntu-latest-clang:
  245. # runs-on: ubuntu-latest
  246. #
  247. # strategy:
  248. # matrix:
  249. # build: [Debug, Release]
  250. #
  251. # steps:
  252. # - name: Clone
  253. # uses: actions/checkout@v1
  254. #
  255. # - name: Dependencies
  256. # run: |
  257. # sudo apt-get update
  258. # sudo apt-get install build-essential
  259. # sudo apt-get install cmake
  260. #
  261. # - name: Configure
  262. # run: cmake . -DCMAKE_BUILD_TYPE=${{ matrix.build }} -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_COMPILER=clang
  263. #
  264. # - name: Build
  265. # run: |
  266. # make
  267. #
  268. # ubuntu-latest-gcc-sanitized:
  269. # runs-on: ubuntu-latest
  270. #
  271. # strategy:
  272. # matrix:
  273. # sanitizer: [ADDRESS, THREAD, UNDEFINED]
  274. #
  275. # steps:
  276. # - name: Clone
  277. # uses: actions/checkout@v1
  278. #
  279. # - name: Dependencies
  280. # run: |
  281. # sudo apt-get update
  282. # sudo apt-get install build-essential
  283. # sudo apt-get install cmake
  284. #
  285. # - name: Configure
  286. # run: cmake . -DCMAKE_BUILD_TYPE=Debug -DLLAMA_SANITIZE_${{ matrix.sanitizer }}=ON
  287. #
  288. # - name: Build
  289. # run: |
  290. # make
  291. #
  292. # windows:
  293. # runs-on: windows-latest
  294. #
  295. # strategy:
  296. # matrix:
  297. # build: [Release]
  298. # arch: [Win32, x64]
  299. # include:
  300. # - arch: Win32
  301. # s2arc: x86
  302. # - arch: x64
  303. # s2arc: x64
  304. #
  305. # steps:
  306. # - name: Clone
  307. # uses: actions/checkout@v1
  308. #
  309. # - name: Add msbuild to PATH
  310. # uses: microsoft/setup-msbuild@v1
  311. #
  312. # - name: Configure
  313. # run: >
  314. # cmake -S . -B ./build -A ${{ matrix.arch }}
  315. # -DCMAKE_BUILD_TYPE=${{ matrix.build }}
  316. #
  317. # - name: Build
  318. # run: |
  319. # cd ./build
  320. # msbuild ALL_BUILD.vcxproj -t:build -p:configuration=${{ matrix.build }} -p:platform=${{ matrix.arch }}
  321. #
  322. # - name: Upload binaries
  323. # uses: actions/upload-artifact@v1
  324. # with:
  325. # name: llama-bin-${{ matrix.arch }}
  326. # path: build/bin/${{ matrix.build }}
  327. #
  328. # windows-blas:
  329. # runs-on: windows-latest
  330. #
  331. # strategy:
  332. # matrix:
  333. # build: [Release]
  334. # arch: [Win32, x64]
  335. # blas: [ON]
  336. # include:
  337. # - arch: Win32
  338. # obzip: https://github.com/xianyi/OpenBLAS/releases/download/v0.3.21/OpenBLAS-0.3.21-x86.zip
  339. # s2arc: x86
  340. # - arch: x64
  341. # obzip: https://github.com/xianyi/OpenBLAS/releases/download/v0.3.21/OpenBLAS-0.3.21-x64.zip
  342. # s2arc: x64
  343. #
  344. # steps:
  345. # - name: Clone
  346. # uses: actions/checkout@v1
  347. #
  348. # - name: Add msbuild to PATH
  349. # uses: microsoft/setup-msbuild@v1
  350. #
  351. # - name: Fetch OpenBLAS
  352. # if: matrix.blas == 'ON'
  353. # run: |
  354. # C:/msys64/usr/bin/wget.exe -qO blas.zip ${{ matrix.obzip }}
  355. # 7z x blas.zip -oblas -y
  356. # copy blas/include/cblas.h .
  357. # copy blas/include/openblas_config.h .
  358. # echo "blasdir=$env:GITHUB_WORKSPACE/blas" >> $env:GITHUB_ENV
  359. #
  360. # - name: Configure
  361. # run: >
  362. # cmake -S . -B ./build -A ${{ matrix.arch }}
  363. # -DCMAKE_BUILD_TYPE=${{ matrix.build }}
  364. # -DLLAMA_SUPPORT_OPENBLAS=${{ matrix.blas }}
  365. # -DCMAKE_LIBRARY_PATH="$env:blasdir/lib"
  366. #
  367. # - name: Build
  368. # run: |
  369. # cd ./build
  370. # msbuild ALL_BUILD.vcxproj -t:build -p:configuration=${{ matrix.build }} -p:platform=${{ matrix.arch }}
  371. #
  372. # - name: Copy libopenblas.dll
  373. # if: matrix.blas == 'ON'
  374. # run: copy "$env:blasdir/bin/libopenblas.dll" build/bin/${{ matrix.build }}
  375. #
  376. # - name: Upload binaries
  377. # if: matrix.blas == 'ON'
  378. # uses: actions/upload-artifact@v1
  379. # with:
  380. # name: llama-blas-bin-${{ matrix.arch }}
  381. # path: build/bin/${{ matrix.build }}
  382. #
  383. # emscripten:
  384. # runs-on: ubuntu-latest
  385. #
  386. # strategy:
  387. # matrix:
  388. # build: [Release]
  389. #
  390. # steps:
  391. # - name: Clone
  392. # uses: actions/checkout@v1
  393. #
  394. # - name: Dependencies
  395. # run: |
  396. # wget -q https://github.com/emscripten-core/emsdk/archive/master.tar.gz
  397. # tar -xvf master.tar.gz
  398. # emsdk-master/emsdk update
  399. # emsdk-master/emsdk install latest
  400. # emsdk-master/emsdk activate latest
  401. #
  402. # - name: Configure
  403. # run: echo "tmp"
  404. #
  405. # - name: Build
  406. # run: |
  407. # pushd emsdk-master
  408. # source ./emsdk_env.sh
  409. # popd
  410. # emcmake cmake . -DCMAKE_BUILD_TYPE=${{ matrix.build }}
  411. # make