|
| 1 | +name: CI |
| 2 | + |
| 3 | +on: |
| 4 | + # Allows manual triggering |
| 5 | + workflow_dispatch: |
| 6 | + inputs: |
| 7 | + create_release: |
| 8 | + description: 'Create new release' |
| 9 | + required: true |
| 10 | + type: boolean |
| 11 | + push: {} |
| 12 | + pull_request: |
| 13 | + types: [opened, synchronize, edited, reopened, review_requested, ready_for_review] |
| 14 | + |
| 15 | +env: |
| 16 | + BRANCH_NAME: ${{ github.head_ref || github.ref_name }} |
| 17 | + |
| 18 | +jobs: |
| 19 | + ubuntu-latest-cmake-sanitizer: |
| 20 | + runs-on: ubuntu-latest |
| 21 | + |
| 22 | + continue-on-error: true |
| 23 | + |
| 24 | + strategy: |
| 25 | + matrix: |
| 26 | + sanitizer: [ADDRESS, THREAD, UNDEFINED] |
| 27 | + build_type: [Debug, Release] |
| 28 | + |
| 29 | + steps: |
| 30 | + - name: Clone |
| 31 | + id: checkout |
| 32 | + uses: actions/checkout@v3 |
| 33 | + with: |
| 34 | + submodules: 'recursive' |
| 35 | + |
| 36 | + - name: Dependencies |
| 37 | + id: depends |
| 38 | + run: | |
| 39 | + sudo apt-get update |
| 40 | + sudo apt-get install build-essential |
| 41 | +
|
| 42 | + - name: Build |
| 43 | + id: cmake_build |
| 44 | + run: | |
| 45 | + mkdir build |
| 46 | + cd build |
| 47 | + cmake .. -DRWKV_SANITIZE_${{ matrix.sanitizer }}=ON -DGGML_SANITIZE_${{ matrix.sanitizer }}=ON -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} |
| 48 | + cmake --build . --config ${{ matrix.build_type }} |
| 49 | +
|
| 50 | + - name: Test |
| 51 | + id: cmake_test |
| 52 | + run: | |
| 53 | + cd build |
| 54 | + ctest --verbose |
| 55 | +
|
| 56 | + ubuntu-latest-cmake: |
| 57 | + runs-on: ubuntu-latest |
| 58 | + |
| 59 | + continue-on-error: true |
| 60 | + |
| 61 | + steps: |
| 62 | + - name: Clone |
| 63 | + id: checkout |
| 64 | + uses: actions/checkout@v3 |
| 65 | + with: |
| 66 | + submodules: 'recursive' |
| 67 | + |
| 68 | + - name: Dependencies |
| 69 | + id: depends |
| 70 | + run: | |
| 71 | + sudo apt-get update |
| 72 | + sudo apt-get install build-essential zip |
| 73 | +
|
| 74 | + - name: Build |
| 75 | + id: cmake_build |
| 76 | + run: | |
| 77 | + mkdir build |
| 78 | + cd build |
| 79 | + cmake .. |
| 80 | + cmake --build . --config Release |
| 81 | +
|
| 82 | + - name: Test |
| 83 | + id: cmake_test |
| 84 | + run: | |
| 85 | + cd build |
| 86 | + ctest --verbose |
| 87 | +
|
| 88 | + - name: Get commit hash |
| 89 | + id: commit |
| 90 | + if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }} |
| 91 | + uses: pr-mpt/actions-commit-hash@v2 |
| 92 | + |
| 93 | + - name: Fetch system info |
| 94 | + id: system-info |
| 95 | + run: | |
| 96 | + echo "CPU_ARCH=`uname -m`" >> "$GITHUB_OUTPUT" |
| 97 | + echo "OS_NAME=`lsb_release -s -i`" >> "$GITHUB_OUTPUT" |
| 98 | + echo "OS_VERSION=`lsb_release -s -r`" >> "$GITHUB_OUTPUT" |
| 99 | + echo "OS_TYPE=`uname -s`" >> "$GITHUB_OUTPUT" |
| 100 | +
|
| 101 | + - name: Pack artifacts |
| 102 | + id: pack_artifacts |
| 103 | + if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }} |
| 104 | + run: | |
| 105 | + zip -j rwkv-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-${{ steps.system-info.outputs.OS_TYPE }}-${{ steps.system-info.outputs.OS_NAME }}-${{ steps.system-info.outputs.OS_VERSION }}-${{ steps.system-info.outputs.CPU_ARCH }}.zip ./build/librwkv.so |
| 106 | +
|
| 107 | + - name: Upload artifacts |
| 108 | + if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }} |
| 109 | + uses: actions/upload-artifact@v3 |
| 110 | + with: |
| 111 | + path: | |
| 112 | + rwkv-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-${{ steps.system-info.outputs.OS_TYPE }}-${{ steps.system-info.outputs.OS_NAME }}-${{ steps.system-info.outputs.OS_VERSION }}-${{ steps.system-info.outputs.CPU_ARCH }}.zip |
| 113 | +
|
| 114 | + macOS-latest-cmake: |
| 115 | + runs-on: macOS-latest |
| 116 | + |
| 117 | + continue-on-error: true |
| 118 | + |
| 119 | + steps: |
| 120 | + - name: Clone |
| 121 | + id: checkout |
| 122 | + uses: actions/checkout@v3 |
| 123 | + with: |
| 124 | + submodules: 'recursive' |
| 125 | + |
| 126 | + - name: Dependencies |
| 127 | + id: depends |
| 128 | + run: | |
| 129 | + brew install zip |
| 130 | +
|
| 131 | + - name: Build |
| 132 | + id: cmake_build |
| 133 | + # FMA disabled because it gives "Illegal instruction" in GitHub Actions runner |
| 134 | + run: | |
| 135 | + mkdir build |
| 136 | + cd build |
| 137 | + cmake --build . --config Release |
| 138 | +
|
| 139 | + - name: Test |
| 140 | + id: cmake_test |
| 141 | + run: | |
| 142 | + cd build |
| 143 | + ctest --verbose |
| 144 | +
|
| 145 | + - name: Get commit hash |
| 146 | + id: commit |
| 147 | + if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }} |
| 148 | + uses: pr-mpt/actions-commit-hash@v2 |
| 149 | + |
| 150 | + - name: Fetch system info |
| 151 | + id: system-info |
| 152 | + run: | |
| 153 | + echo "CPU_ARCH=`uname -m`" >> "$GITHUB_OUTPUT" |
| 154 | + echo "OS_NAME=`sw_vers -productName`" >> "$GITHUB_OUTPUT" |
| 155 | + echo "OS_VERSION=`sw_vers -productVersion`" >> "$GITHUB_OUTPUT" |
| 156 | + echo "OS_TYPE=`uname -s`" >> "$GITHUB_OUTPUT" |
| 157 | +
|
| 158 | + - name: Pack artifacts |
| 159 | + id: pack_artifacts |
| 160 | + if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }} |
| 161 | + run: | |
| 162 | + zip -j rwkv-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-${{ steps.system-info.outputs.OS_TYPE }}-${{ steps.system-info.outputs.OS_NAME }}-${{ steps.system-info.outputs.OS_VERSION }}-${{ steps.system-info.outputs.CPU_ARCH }}.zip ./build/librwkv.dylib |
| 163 | +
|
| 164 | + - name: Upload artifacts |
| 165 | + if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }} |
| 166 | + uses: actions/upload-artifact@v3 |
| 167 | + with: |
| 168 | + path: | |
| 169 | + rwkv-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-${{ steps.system-info.outputs.OS_TYPE }}-${{ steps.system-info.outputs.OS_NAME }}-${{ steps.system-info.outputs.OS_VERSION }}-${{ steps.system-info.outputs.CPU_ARCH }}.zip |
| 170 | +
|
| 171 | + windows-latest-cmake: |
| 172 | + runs-on: windows-latest |
| 173 | + |
| 174 | + continue-on-error: true |
| 175 | + |
| 176 | + strategy: |
| 177 | + matrix: |
| 178 | + include: |
| 179 | + - build: 'avx2' |
| 180 | + defines: '' |
| 181 | + - build: 'avx' |
| 182 | + defines: '-DRWKV_AVX2=OFF' |
| 183 | + - build: 'avx512' |
| 184 | + defines: '-DRWKV_AVX512=ON' |
| 185 | + |
| 186 | + steps: |
| 187 | + - name: Clone |
| 188 | + id: checkout |
| 189 | + uses: actions/checkout@v3 |
| 190 | + with: |
| 191 | + submodules: 'recursive' |
| 192 | + |
| 193 | + - name: Build |
| 194 | + id: cmake_build |
| 195 | + run: | |
| 196 | + mkdir build |
| 197 | + cd build |
| 198 | + cmake .. ${{ matrix.defines }} |
| 199 | + cmake --build . --config Release |
| 200 | +
|
| 201 | + - name: Check AVX512F support |
| 202 | + id: check_avx512f |
| 203 | + if: ${{ matrix.build == 'avx512' }} |
| 204 | + continue-on-error: true |
| 205 | + run: | |
| 206 | + cd build |
| 207 | + $vcdir = $(vswhere -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath) |
| 208 | + $msvc = $(join-path $vcdir $('VC\Tools\MSVC\'+$(gc -raw $(join-path $vcdir 'VC\Auxiliary\Build\Microsoft.VCToolsVersion.default.txt')).Trim())) |
| 209 | + $cl = $(join-path $msvc 'bin\Hostx64\x64\cl.exe') |
| 210 | + echo 'int main(void){unsigned int a[4];__cpuid(a,7);return !(a[1]&65536);}' >> avx512f.c |
| 211 | + & $cl /O2 /GS- /kernel avx512f.c /link /nodefaultlib /entry:main |
| 212 | + .\avx512f.exe && echo "AVX512F: YES" && ( echo HAS_AVX512F=1 >> $env:GITHUB_ENV ) || echo "AVX512F: NO" |
| 213 | +
|
| 214 | + - name: Get commit hash |
| 215 | + id: commit |
| 216 | + if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }} |
| 217 | + uses: pr-mpt/actions-commit-hash@v2 |
| 218 | + |
| 219 | + - name: Pack artifacts |
| 220 | + id: pack_artifacts |
| 221 | + if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }} |
| 222 | + run: | |
| 223 | + 7z a rwkv-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-win-${{ matrix.build }}-x64.zip .\build\bin\Release\rwkv.dll |
| 224 | +
|
| 225 | + - name: Upload artifacts |
| 226 | + if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }} |
| 227 | + uses: actions/upload-artifact@v3 |
| 228 | + with: |
| 229 | + path: | |
| 230 | + rwkv-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-win-${{ matrix.build }}-x64.zip |
| 231 | +
|
| 232 | + release: |
| 233 | + if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }} |
| 234 | + |
| 235 | + runs-on: ubuntu-latest |
| 236 | + |
| 237 | + needs: |
| 238 | + - ubuntu-latest-cmake |
| 239 | + - macOS-latest-cmake |
| 240 | + - windows-latest-cmake |
| 241 | + |
| 242 | + steps: |
| 243 | + - name: Download artifacts |
| 244 | + id: download-artifact |
| 245 | + uses: actions/download-artifact@v3 |
| 246 | + |
| 247 | + - name: Get commit hash |
| 248 | + id: commit |
| 249 | + uses: pr-mpt/actions-commit-hash@v2 |
| 250 | + |
| 251 | + - name: Create release |
| 252 | + id: create_release |
| 253 | + uses: anzz1/action-create-release@v1 |
| 254 | + env: |
| 255 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 256 | + with: |
| 257 | + tag_name: ${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }} |
| 258 | + |
| 259 | + - name: Upload release |
| 260 | + id: upload_release |
| 261 | + uses: actions/github-script@v3 |
| 262 | + with: |
| 263 | + github-token: ${{secrets.GITHUB_TOKEN}} |
| 264 | + script: | |
| 265 | + const path = require('path'); |
| 266 | + const fs = require('fs'); |
| 267 | + const release_id = '${{ steps.create_release.outputs.id }}'; |
| 268 | + for (let file of await fs.readdirSync('./artifact')) { |
| 269 | + if (path.extname(file) === '.zip') { |
| 270 | + console.log('uploadReleaseAsset', file); |
| 271 | + await github.repos.uploadReleaseAsset({ |
| 272 | + owner: context.repo.owner, |
| 273 | + repo: context.repo.repo, |
| 274 | + release_id: release_id, |
| 275 | + name: file, |
| 276 | + data: await fs.readFileSync(`./artifact/${file}`) |
| 277 | + }); |
| 278 | + } |
| 279 | + } |
0 commit comments