From d213f9d52ba2bc89af5bbfcf0e283b0db04b0dcc Mon Sep 17 00:00:00 2001 From: anzz1 Date: Sat, 25 Mar 2023 16:28:09 +0200 Subject: [PATCH 1/7] CMake: add AVX512 option --- CMakeLists.txt | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 51af97c4d2969..aff7eaec253e6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -54,6 +54,7 @@ option(LLAMA_SANITIZE_UNDEFINED "llama: enable undefined sanitizer" # instruction set specific option(LLAMA_AVX "llama: enable AVX" ON) option(LLAMA_AVX2 "llama: enable AVX2" ON) +option(LLAMA_AVX512 "llama: enable AVX512" OFF) option(LLAMA_FMA "llama: enable FMA" ON) # 3rd party libs @@ -185,7 +186,9 @@ if (${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm" OR ${CMAKE_SYSTEM_PROCESSOR} MATCHES elseif (${CMAKE_SYSTEM_PROCESSOR} MATCHES "^(x86_64|i686|AMD64)$") message(STATUS "x86 detected") if (MSVC) - if (LLAMA_AVX2) + if (LLAMA_AVX512) + add_compile_options(/arch:AVX512) + elseif (LLAMA_AVX2) add_compile_options(/arch:AVX2) elseif (LLAMA_AVX) add_compile_options(/arch:AVX) @@ -201,6 +204,12 @@ elseif (${CMAKE_SYSTEM_PROCESSOR} MATCHES "^(x86_64|i686|AMD64)$") if (LLAMA_AVX2) add_compile_options(-mavx2) endif() + if (LLAMA_AVX512) + add_compile_options(-mavx512f) + # add_compile_options(-mavx512cd) + # add_compile_options(-mavx512dq) + # add_compile_options(-mavx512bw) + endif() endif() else() # TODO: support PowerPC From 43e1cf86935565efe302c55850fa038a0616f4f5 Mon Sep 17 00:00:00 2001 From: anzz1 Date: Sat, 25 Mar 2023 16:30:25 +0200 Subject: [PATCH 2/7] CI: (Windows) Add AVX / AVX512 builds --- .github/workflows/build.yml | 40 +++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e9826a7357a04..eca0a667db1c8 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -122,14 +122,14 @@ jobs: run: | mkdir build cd build - cmake .. - cmake --build . --config Release + mkdir avx2 & mkdir avx & mkdir avx512 + cmake -S .. -B ./avx2 && cmake -S .. -B ./avx -DLLAMA_AVX2=OFF && cmake -S .. -B ./avx512 -DLLAMA_AVX512=ON + cmake --build ./avx2 --config Release && cmake --build ./avx --config Release && cmake --build ./avx512 --config Release - name: Test id: cmake_test run: | - cd build - ctest -C Release --output-on-failure + cd build/avx2 && ctest -C Release --output-on-failure && cd ../avx && ctest -C Release --output-on-failure && cd ../avx512 && ctest -C Release --output-on-failure - name: Get commit hash id: commit @@ -140,12 +140,15 @@ jobs: id: pack_artifacts if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }} run: | - 7z a llama-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-win-x64.zip .\build\bin\Release\* + mkdir artifacts + 7z a .\artifacts\llama-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-win-avx2-x64.zip .\build\avx2\bin\Release\* + 7z a .\artifacts\llama-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-win-avx-x64.zip .\build\avx\bin\Release\* + 7z a .\artifacts\llama-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-win-avx512-x64.zip .\build\avx512\bin\Release\* - name: Create release id: create_release if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }} - uses: zendesk/action-create-release@v1 + uses: anzz1/action-create-release@v1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: @@ -154,14 +157,25 @@ jobs: - name: Upload release id: upload_release if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }} - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + uses: actions/github-script@v3 with: - upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: .\llama-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-win-x64.zip - asset_name: llama-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-win-x64.zip - asset_content_type: application/octet-stream + github-token: ${{secrets.GITHUB_TOKEN}} + script: | + const path = require('path'); + const fs = require('fs'); + const release_id = '${{ steps.create_release.outputs.id }}'; + for (let file of await fs.readdirSync('./artifacts')) { + if (path.extname(file) === '.zip') { + console.log('uploadReleaseAsset', file); + await github.repos.uploadReleaseAsset({ + owner: context.repo.owner, + repo: context.repo.repo, + release_id: release_id, + name: file, + data: await fs.readFileSync(`./artifacts/${file}`) + }); + } + } # ubuntu-latest-gcc: # runs-on: ubuntu-latest From a52f6b43b7293fa0c9226473eb81056e51c7809e Mon Sep 17 00:00:00 2001 From: anzz1 Date: Sat, 25 Mar 2023 18:54:28 +0200 Subject: [PATCH 3/7] CI: option 2 --- .github/workflows/build.yml | 57 +++++++++++++++++++++++++++++-------- 1 file changed, 45 insertions(+), 12 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index eca0a667db1c8..9c531d2cf23e4 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -112,6 +112,16 @@ jobs: windows-latest-cmake: runs-on: windows-latest + strategy: + matrix: + include: + - build: 'avx2' + defines: '' + - build: 'avx' + defines: '-DLLAMA_AVX2=OFF' + - build: 'avx512' + defines: '-DLLAMA_AVX512=ON' + steps: - name: Clone id: checkout @@ -122,14 +132,14 @@ jobs: run: | mkdir build cd build - mkdir avx2 & mkdir avx & mkdir avx512 - cmake -S .. -B ./avx2 && cmake -S .. -B ./avx -DLLAMA_AVX2=OFF && cmake -S .. -B ./avx512 -DLLAMA_AVX512=ON - cmake --build ./avx2 --config Release && cmake --build ./avx --config Release && cmake --build ./avx512 --config Release + cmake .. ${{ matrix.defines }} + cmake --build . --config Release - name: Test id: cmake_test run: | - cd build/avx2 && ctest -C Release --output-on-failure && cd ../avx && ctest -C Release --output-on-failure && cd ../avx512 && ctest -C Release --output-on-failure + cd build + ctest -C Release --output-on-failure - name: Get commit hash id: commit @@ -140,14 +150,38 @@ jobs: id: pack_artifacts if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }} run: | - mkdir artifacts - 7z a .\artifacts\llama-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-win-avx2-x64.zip .\build\avx2\bin\Release\* - 7z a .\artifacts\llama-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-win-avx-x64.zip .\build\avx\bin\Release\* - 7z a .\artifacts\llama-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-win-avx512-x64.zip .\build\avx512\bin\Release\* + 7z a llama-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-win-${{ matrix.build }}-x64.zip .\build\bin\Release\* + + - name: Upload artifacts + if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }} + uses: actions/upload-artifact@v3 + with: + path: | + llama-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-win-${{ matrix.build }}-x64.zip + + release: + if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }} + + runs-on: ubuntu-latest + + needs: + - ubuntu-latest-make + - ubuntu-latest-cmake + - macOS-latest-make + - macOS-latest-cmake + - windows-latest-cmake + + steps: + - name: Download artifacts + id: download-artifact + uses: actions/download-artifact@v3 + + - name: Get commit hash + id: commit + uses: pr-mpt/actions-commit-hash@v2 - name: Create release id: create_release - if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }} uses: anzz1/action-create-release@v1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} @@ -156,7 +190,6 @@ jobs: - name: Upload release id: upload_release - if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }} uses: actions/github-script@v3 with: github-token: ${{secrets.GITHUB_TOKEN}} @@ -164,7 +197,7 @@ jobs: const path = require('path'); const fs = require('fs'); const release_id = '${{ steps.create_release.outputs.id }}'; - for (let file of await fs.readdirSync('./artifacts')) { + for (let file of await fs.readdirSync('./artifact')) { if (path.extname(file) === '.zip') { console.log('uploadReleaseAsset', file); await github.repos.uploadReleaseAsset({ @@ -172,7 +205,7 @@ jobs: repo: context.repo.repo, release_id: release_id, name: file, - data: await fs.readFileSync(`./artifacts/${file}`) + data: await fs.readFileSync(`./artifact/${file}`) }); } } From c2916bb4a0ea525f06ee23668dc0429d0ed1d5be Mon Sep 17 00:00:00 2001 From: anzz1 Date: Sat, 25 Mar 2023 19:09:34 +0200 Subject: [PATCH 4/7] disable avx512 test on runner for now until i figure out how to check for the capability in gh actions --- .github/workflows/build.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 9c531d2cf23e4..57f28cae42e5e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -137,6 +137,7 @@ jobs: - name: Test id: cmake_test + if: ${{ matrix.build != 'avx512' }} # todo: check whether runner support avx512 run: | cd build ctest -C Release --output-on-failure From 2d2701334374a79ce43c23e7c18cb7fefd270363 Mon Sep 17 00:00:00 2001 From: anzz1 Date: Sat, 25 Mar 2023 21:28:31 +0200 Subject: [PATCH 5/7] test avx-512f only when possible --- .github/workflows/build.yml | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 57f28cae42e5e..2f4e94a20b114 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -135,9 +135,18 @@ jobs: cmake .. ${{ matrix.defines }} cmake --build . --config Release + - name: Check AVX512F support + id: check_avx512f + if: ${{ matrix.build == 'avx512' }} + continue-on-error: true + run: | + cd build + Set-Content -Path .\avx512f.exe -Value ([Convert]::FromBase64String('TVqQAAMAAAAEAAAA//8AALgAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAyAAAAA4fug4AtAnNIbgBTM0hVGhpcyBwcm9ncmFtIGNhbm5vdCBiZSBydW4gaW4gRE9TIG1vZGUuDQ0KJAAAAAAAAAClmfXY4fibi+H4m4vh+JuL4fiai+P4m4si98aL4vibi7Xbq4vg+JuLUmljaOH4m4sAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABQRQAATAEBAGo6H2QAAAAAAAAAAOAADwELAQYAAAIAAAAAAAAAAAAADBAAAAAQAAAAIAAAAABAAAAQAAAAAgAABAAAAAAAAAAEAAAAAAAAAAAgAAAAAgAAAAAAAAMAAAAAABAAABAAAAAAEAAAEAAAAAAAABAAAAAAAAAAAAAAAFQQAAAoAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAADAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAC50ZXh0AAAAsgAAAAAQAAAAAgAAAAIAAAAAAAAAAAAAAAAAACAAAGAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACUEAAAiBAAAAAAAABVi+xRUVNTuAcAAAAPosHrEGaD4wGJXfxbg0X8MI1F+GoAUI1F/GoBUGr1/xUAEEAAUP8VBBBAAItF/FuDwND32BvAQMnDzMx8EAAAAAAAAAAAAACkEAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAlBAAAIgQAAAAAAAApANXcml0ZUZpbGUAuQFHZXRTdGRIYW5kbGUAAEtFUk5FTDMyLmRsbAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==')) -AsByteStream + .\avx512f.exe && echo " - AVX512F: YES" && ( echo HAS_AVX512F=1 >> $env:GITHUB_ENV ) || echo " - AVX512F: NO" + - name: Test id: cmake_test - if: ${{ matrix.build != 'avx512' }} # todo: check whether runner support avx512 + if: ${{ matrix.build != 'avx512' || env.HAS_AVX512F == '1' }} # Test AVX-512 only when possible run: | cd build ctest -C Release --output-on-failure From 779c37f9169827195168318c6060f3876385c6d5 Mon Sep 17 00:00:00 2001 From: anzz1 Date: Sat, 25 Mar 2023 21:39:05 +0200 Subject: [PATCH 6/7] cmake: make sanitizers linking #468 --- CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index aff7eaec253e6..0b429e708653b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -76,14 +76,17 @@ find_package(Threads REQUIRED) if (NOT MSVC) if (LLAMA_SANITIZE_THREAD) add_compile_options(-fsanitize=thread) + link_libraries(-fsanitize=thread) endif() if (LLAMA_SANITIZE_ADDRESS) add_compile_options(-fsanitize=address -fno-omit-frame-pointer) + link_libraries(-fsanitize=address) endif() if (LLAMA_SANITIZE_UNDEFINED) add_compile_options(-fsanitize=undefined) + link_libraries(-fsanitize=undefined) endif() endif() From 004fddfed79e403bc788a988dd260c464336f361 Mon Sep 17 00:00:00 2001 From: anzz1 Date: Sat, 25 Mar 2023 21:44:27 +0200 Subject: [PATCH 7/7] CI: Add sanitizer build (Ubuntu) --- .github/workflows/build.yml | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 2f4e94a20b114..126e1e66daa4f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -64,6 +64,38 @@ jobs: cd build ctest --output-on-failure + ubuntu-latest-cmake-sanitizer: + runs-on: ubuntu-latest + + strategy: + matrix: + sanitizer: [ADDRESS, THREAD, UNDEFINED] + + steps: + - name: Clone + id: checkout + uses: actions/checkout@v1 + + - name: Dependencies + id: depends + run: | + sudo apt-get update + sudo apt-get install build-essential + + - name: Build + id: cmake_build + run: | + mkdir build + cd build + cmake .. -DLLAMA_SANITIZE_${{ matrix.sanitizer }}=ON + cmake --build . --config Release + + - name: Test + id: cmake_test + run: | + cd build + ctest --output-on-failure + macOS-latest-make: runs-on: macos-latest @@ -142,7 +174,7 @@ jobs: run: | cd build Set-Content -Path .\avx512f.exe -Value ([Convert]::FromBase64String('TVqQAAMAAAAEAAAA//8AALgAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAyAAAAA4fug4AtAnNIbgBTM0hVGhpcyBwcm9ncmFtIGNhbm5vdCBiZSBydW4gaW4gRE9TIG1vZGUuDQ0KJAAAAAAAAAClmfXY4fibi+H4m4vh+JuL4fiai+P4m4si98aL4vibi7Xbq4vg+JuLUmljaOH4m4sAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABQRQAATAEBAGo6H2QAAAAAAAAAAOAADwELAQYAAAIAAAAAAAAAAAAADBAAAAAQAAAAIAAAAABAAAAQAAAAAgAABAAAAAAAAAAEAAAAAAAAAAAgAAAAAgAAAA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UB_ENV ) || echo " - AVX512F: NO" + .\avx512f.exe && echo " AVX512F: YES" && ( echo HAS_AVX512F=1 >> $env:GITHUB_ENV ) || echo " AVX512F: NO" - name: Test id: cmake_test