build.yml 12 KB

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