build.yml 12 KB

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