test.yaml 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. name: test
  2. concurrency:
  3. # For PRs, later CI runs preempt previous ones. e.g. a force push on a PR
  4. # cancels running CI jobs and starts all new ones.
  5. #
  6. # For non-PR pushes, concurrency.group needs to be unique for every distinct
  7. # CI run we want to have happen. Use run_id, which in practice means all
  8. # non-PR CI runs will be allowed to run without preempting each other.
  9. group: ${{ github.workflow }}-$${{ github.pull_request.number || github.run_id }}
  10. cancel-in-progress: true
  11. on:
  12. pull_request:
  13. paths:
  14. - '**/*'
  15. - '!docs/**'
  16. - '!README.md'
  17. jobs:
  18. changes:
  19. runs-on: ubuntu-latest
  20. outputs:
  21. changed: ${{ steps.changes.outputs.changed }}
  22. steps:
  23. - uses: actions/checkout@v4
  24. with:
  25. fetch-depth: 0
  26. - id: changes
  27. run: |
  28. changed() {
  29. local BASE=${{ github.event.pull_request.base.sha }}
  30. local HEAD=${{ github.event.pull_request.head.sha }}
  31. local MERGE_BASE=$(git merge-base $BASE $HEAD)
  32. git diff-tree -r --no-commit-id --name-only "$MERGE_BASE" "$HEAD" \
  33. | xargs python3 -c "import sys; from pathlib import Path; print(any(Path(x).match(glob) for x in sys.argv[1:] for glob in '$*'.split(' ')))"
  34. }
  35. echo changed=$(changed 'llama/llama.cpp/**' 'ml/backend/ggml/ggml/**') | tee -a $GITHUB_OUTPUT
  36. linux:
  37. needs: [changes]
  38. if: needs.changes.outputs.changed == 'True'
  39. strategy:
  40. matrix:
  41. include:
  42. - preset: CPU
  43. - preset: CUDA
  44. container: nvidia/cuda:11.8.0-devel-ubuntu22.04
  45. flags: '-DCMAKE_CUDA_ARCHITECTURES=87'
  46. - preset: ROCm
  47. container: rocm/dev-ubuntu-22.04:6.1.2
  48. extra-packages: rocm-libs
  49. flags: '-DAMDGPU_TARGETS=gfx1010 -DCMAKE_PREFIX_PATH=/opt/rocm'
  50. runs-on: linux
  51. container: ${{ matrix.container }}
  52. steps:
  53. - uses: actions/checkout@v4
  54. - run: |
  55. [ -n "${{ matrix.container }}" ] || sudo=sudo
  56. $sudo apt-get update
  57. $sudo apt-get install -y cmake ccache ${{ matrix.extra-packages }}
  58. env:
  59. DEBIAN_FRONTEND: noninteractive
  60. - uses: actions/cache@v4
  61. with:
  62. path: /github/home/.cache/ccache
  63. key: ccache-${{ runner.os }}-${{ runner.arch }}-${{ matrix.preset }}
  64. - run: |
  65. cmake --preset ${{ matrix.preset }} ${{ matrix.flags }}
  66. cmake --build --preset ${{ matrix.preset }} --parallel
  67. windows:
  68. needs: [changes]
  69. if: needs.changes.outputs.changed == 'True'
  70. strategy:
  71. matrix:
  72. include:
  73. - preset: CPU
  74. - preset: CUDA
  75. install: https://developer.download.nvidia.com/compute/cuda/11.3.1/local_installers/cuda_11.3.1_465.89_win10.exe
  76. flags: '-DCMAKE_CUDA_ARCHITECTURES=80'
  77. - preset: ROCm
  78. install: https://download.amd.com/developer/eula/rocm-hub/AMD-Software-PRO-Edition-24.Q4-WinSvr2022-For-HIP.exe
  79. flags: '-DAMDGPU_TARGETS=gfx1010'
  80. runs-on: windows
  81. steps:
  82. - run: |
  83. choco install -y --no-progress ccache ninja
  84. ccache -o cache_dir=${{ github.workspace }}\.ccache
  85. - if: matrix.preset == 'CUDA' || matrix.preset == 'ROCm'
  86. id: cache-install
  87. uses: actions/cache/restore@v4
  88. with:
  89. path: |
  90. C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA
  91. C:\Program Files\AMD\ROCm
  92. key: ${{ matrix.install }}
  93. - if: matrix.preset == 'CUDA'
  94. name: Install CUDA ${{ matrix.cuda-version }}
  95. run: |
  96. $ErrorActionPreference = "Stop"
  97. if ("${{ steps.cache-install.outputs.cache-hit }}" -ne 'true') {
  98. Invoke-WebRequest -Uri "${{ matrix.install }}" -OutFile "install.exe"
  99. Start-Process -FilePath .\install.exe -ArgumentList (@("-s", "cudart_11.3", "nvcc_11.3", "cublas_11.3", "cublas_dev_11.3")) -NoNewWindow -Wait
  100. }
  101. $cudaPath = (Resolve-Path "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\*").path
  102. echo "$cudaPath\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
  103. - if: matrix.preset == 'ROCm'
  104. name: Install ROCm ${{ matrix.rocm-version }}
  105. run: |
  106. $ErrorActionPreference = "Stop"
  107. if ("${{ steps.cache-install.outputs.cache-hit }}" -ne 'true') {
  108. Invoke-WebRequest -Uri "${{ matrix.install }}" -OutFile "install.exe"
  109. Start-Process -FilePath .\install.exe -ArgumentList '-install' -NoNewWindow -Wait
  110. }
  111. $hipPath = (Resolve-Path "C:\Program Files\AMD\ROCm\*").path
  112. echo "$hipPath\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
  113. echo "CC=$hipPath\bin\clang.exe" | Out-File -FilePath $env:GITHUB_ENV -Append
  114. echo "CXX=$hipPath\bin\clang++.exe" | Out-File -FilePath $env:GITHUB_ENV -Append
  115. - if: ${{ !cancelled() && steps.cache-install.outputs.cache-hit != 'true' }}
  116. uses: actions/cache/save@v4
  117. with:
  118. path: |
  119. C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA
  120. C:\Program Files\AMD\ROCm
  121. key: ${{ matrix.install }}
  122. - uses: actions/checkout@v4
  123. - uses: actions/cache@v4
  124. with:
  125. path: ${{ github.workspace }}\.ccache
  126. key: ccache-${{ runner.os }}-${{ runner.arch }}-${{ matrix.preset }}
  127. - run: |
  128. Import-Module 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\Tools\Microsoft.VisualStudio.DevShell.dll'
  129. Enter-VsDevShell -VsInstallPath 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise' -SkipAutomaticLocation -DevCmdArguments '-arch=x64 -no_logo'
  130. cmake --preset "${{ matrix.preset }}" ${{ matrix.flags }}
  131. cmake --build --parallel --preset "${{ matrix.preset }}"
  132. env:
  133. CMAKE_GENERATOR: Ninja
  134. go_mod_tidy:
  135. runs-on: ubuntu-latest
  136. steps:
  137. - uses: actions/checkout@v4
  138. - name: check that 'go mod tidy' is clean
  139. run: go mod tidy --diff || (echo "Please run 'go mod tidy'." && exit 1)
  140. test:
  141. strategy:
  142. matrix:
  143. os: [ubuntu-latest, macos-latest, windows-latest]
  144. runs-on: ${{ matrix.os }}
  145. env:
  146. CGO_ENABLED: '1'
  147. GOEXPERIMENT: 'synctest'
  148. steps:
  149. - name: checkout
  150. uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # 4.2.2
  151. - name: cache restore
  152. uses: actions/cache/restore@1bd1e32a3bdc45362d1e726936510720a7c30a57 # v4.2.0
  153. with:
  154. # Note: unlike the other setups, this is only grabbing the mod download
  155. # cache, rather than the whole mod directory, as the download cache
  156. # contains zips that can be unpacked in parallel faster than they can be
  157. # fetched and extracted by tar
  158. path: |
  159. ~/.cache/go-build
  160. ~/go/pkg/mod/cache
  161. ~\AppData\Local\go-build
  162. # NOTE: The -3- here should be incremented when the scheme of data to be
  163. # cached changes (e.g. path above changes).
  164. key: ${{ github.job }}-${{ runner.os }}-${{ matrix.goarch }}-${{ matrix.buildflags }}-go-3-${{ hashFiles('**/go.sum') }}-${{ github.run_id }}
  165. restore-keys: |
  166. ${{ github.job }}-${{ runner.os }}-${{ matrix.goarch }}-${{ matrix.buildflags }}-go-3-${{ hashFiles('**/go.sum') }}
  167. ${{ github.job }}-${{ runner.os }}-${{ matrix.goarch }}-${{ matrix.buildflags }}-go-3-
  168. - name: Setup Go
  169. uses: actions/setup-go@v5
  170. with:
  171. # The caching strategy of setup-go is less than ideal, and wastes
  172. # time by not saving artifacts due to small failures like the linter
  173. # complaining, etc. This means subsequent have to rebuild their world
  174. # again until all checks pass. For instance, if you mispell a word,
  175. # you're punished until you fix it. This is more hostile than
  176. # helpful.
  177. cache: false
  178. go-version-file: go.mod
  179. # It is tempting to run this in a platform independent way, but the past
  180. # shows this codebase will see introductions of platform specific code
  181. # generation, and so we need to check this per platform to ensure we
  182. # don't abuse go generate on specific platforms.
  183. - name: check that 'go generate' is clean
  184. if: always()
  185. run: |
  186. go generate ./...
  187. git diff --name-only --exit-code || (echo "Please run 'go generate ./...'." && exit 1)
  188. - name: go test
  189. if: always()
  190. run: go test -count=1 -benchtime=1x ./...
  191. # TODO(bmizerany): replace this heavy tool with just the
  192. # tools/checks/binaries we want and then make them all run in parallel
  193. # across jobs, not on a single tiny vm on Github Actions.
  194. - uses: golangci/golangci-lint-action@v6
  195. with:
  196. args: --timeout 10m0s -v
  197. - name: cache save
  198. # Always save the cache, even if the job fails. The artifacts produced
  199. # during the building of test binaries are not all for naught. They can
  200. # be used to speed up subsequent runs.
  201. if: always()
  202. uses: actions/cache/save@1bd1e32a3bdc45362d1e726936510720a7c30a57 # v4.2.0
  203. with:
  204. # Note: unlike the other setups, this is only grabbing the mod download
  205. # cache, rather than the whole mod directory, as the download cache
  206. # contains zips that can be unpacked in parallel faster than they can be
  207. # fetched and extracted by tar
  208. path: |
  209. ~/.cache/go-build
  210. ~/go/pkg/mod/cache
  211. ~\AppData\Local\go-build
  212. # NOTE: The -3- here should be incremented when the scheme of data to be
  213. # cached changes (e.g. path above changes).
  214. key: ${{ github.job }}-${{ runner.os }}-${{ matrix.goarch }}-${{ matrix.buildflags }}-go-3-${{ hashFiles('**/go.sum') }}-${{ github.run_id }}
  215. patches:
  216. runs-on: ubuntu-latest
  217. steps:
  218. - uses: actions/checkout@v4
  219. - name: Verify patches apply cleanly and do not change files
  220. run: |
  221. make -f Makefile.sync clean sync
  222. git diff --compact-summary --exit-code