build.yml 12 KB

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