|
| 1 | +name: Build MacOS |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + inputs: |
| 6 | + matrix: |
| 7 | + required: true |
| 8 | + type: string |
| 9 | + |
| 10 | +jobs: |
| 11 | + build-macos: |
| 12 | + runs-on: ${{ matrix.runner }} |
| 13 | + strategy: |
| 14 | + matrix: |
| 15 | + runner: ${{ fromJson(inputs.matrix) }} |
| 16 | + timeout-minutes: 60 |
| 17 | + env: |
| 18 | + RUNNER_TYPE: ${{ matrix.runner[0] }} |
| 19 | + TRITON_BUILD_WITH_CLANG_LLD: "TRUE" |
| 20 | + name: Build MacOS |
| 21 | + steps: |
| 22 | + - name: Checkout |
| 23 | + uses: actions/checkout@v4 |
| 24 | + with: |
| 25 | + submodules: "true" |
| 26 | + - name: Install brew dependencies |
| 27 | + run: | |
| 28 | + brew update |
| 29 | + brew install ccache llvm@19 lld coreutils |
| 30 | + - name: Compute cache keys |
| 31 | + id: cache-key |
| 32 | + run: | |
| 33 | + llvm_file="cmake/llvm-hash.txt" |
| 34 | + nvidia_file="cmake/nvidia-toolchain-version.json" |
| 35 | + json_file="cmake/json-version.txt" |
| 36 | +
|
| 37 | + # Check if files exist before proceeding |
| 38 | + if [[ ! -f "$llvm_file" || ! -f "$nvidia_file" || ! -f "$json_file" ]]; then |
| 39 | + echo "Error: Required dependency files are missing." |
| 40 | + exit 1 |
| 41 | + fi |
| 42 | +
|
| 43 | + # Process the files if they exist |
| 44 | + echo "llvm=$(cat $llvm_file | cut -c 1-8)" >> $GITHUB_OUTPUT |
| 45 | + echo "nvidia=$(sha256sum $nvidia_file | cut -d ' ' -f 1)" >> $GITHUB_OUTPUT |
| 46 | + echo "json=$(cat $json_file)" >> $GITHUB_OUTPUT |
| 47 | + echo "datetime=$(date -u -Iseconds)" >> $GITHUB_OUTPUT |
| 48 | + shell: bash |
| 49 | + - name: Cache build dependencies |
| 50 | + uses: actions/cache@v4 |
| 51 | + with: |
| 52 | + # Note that we cannot use environment variables here given there is |
| 53 | + # no shell to interpret them in the paths. |
| 54 | + path: | |
| 55 | + ~/.triton/llvm |
| 56 | + ~/.triton/nvidia |
| 57 | + ~/.triton/json |
| 58 | + key: ${{ runner.os }}-${{ runner.arch }}-llvm-${{ steps.cache-key.outputs.llvm }}-nvidia-${{ steps.cache-key.outputs.nvidia }}-json-${{ steps.cache-key.outputs.json }} |
| 59 | + - # Cache ~/.cache/ccache to speed up compilation. |
| 60 | + # |
| 61 | + # On branch `main` we always start from an empty cache, i.e. we skip the |
| 62 | + # "restore" step. This is to prevent the caches from accumulating stale |
| 63 | + # files over time. |
| 64 | + name: Restore cache of ccache and Triton compilation artifacts |
| 65 | + id: restore-build-cache |
| 66 | + if: github.ref != 'refs/heads/main' |
| 67 | + uses: actions/cache/restore@v4 |
| 68 | + with: |
| 69 | + path: | |
| 70 | + ~/.ccache |
| 71 | + # Restore the most recent cache entry. |
| 72 | + restore-keys: | |
| 73 | + triton-artifacts-${{ runner.os }}-${{ runner.arch }}-${{ env.RUNNER_TYPE }}-llvm-${{ steps.cache-key.outputs.llvm }}- |
| 74 | + triton-artifacts-${{ runner.os }}-${{ runner.arch }}-${{ env.RUNNER_TYPE }}- |
| 75 | + # We expect this cache key never to hit and for us to fall back |
| 76 | + # unconditionally to the restore-key, so it doesn't actually matter |
| 77 | + # what we put here (so long as it doesn't hit an existing key). |
| 78 | + key: triton-artifacts-${{ runner.os }}-${{ runner.arch }}-${{ env.RUNNER_TYPE }}-llvm-${{ steps.cache-key.outputs.llvm }}-${{ steps.cache-key.outputs.datetime }} |
| 79 | + - name: Inspect cache directories |
| 80 | + run: | |
| 81 | + mkdir -p ~/.triton |
| 82 | + du -h -d 1 ~/.triton |
| 83 | +
|
| 84 | + mkdir -p ~/.ccache |
| 85 | + du -h -d 1 ~/.ccache |
| 86 | + - name: Update PATH |
| 87 | + run: | |
| 88 | + echo "$HOME/.local/bin" >> $GITHUB_PATH |
| 89 | + echo "/opt/homebrew/opt/llvm/bin" >> $GITHUB_PATH |
| 90 | + - name: Create venv |
| 91 | + run: | |
| 92 | + python3 -m venv ~/.venv |
| 93 | + source ~/.venv/bin/activate |
| 94 | + python3 -m pip install --upgrade pip |
| 95 | + - name: Install Triton |
| 96 | + env: |
| 97 | + TRITON_BUILD_WITH_O1: "true" |
| 98 | + # macos-latest has 3 vcpus and 7GB DRAM, to save memory we limit the number of jobs to 3 |
| 99 | + # https://docs.github.com/en/actions/reference/github-hosted-runners-reference#standard-github-hosted-runners-for-public-repositories |
| 100 | + MAX_JOBS: 3 |
| 101 | + # Add elapsed time in seconds to ninja status to monitor where build stalls |
| 102 | + NINJA_STATUS: "[%f/%t, %es elapsed] " |
| 103 | + run: | |
| 104 | + source ~/.venv/bin/activate |
| 105 | + echo "PATH is '$PATH'" |
| 106 | + ccache --zero-stats |
| 107 | + export PATH="/opt/homebrew/opt/llvm@19/bin:$PATH" |
| 108 | + export CC="/opt/homebrew/opt/llvm@19/bin/clang" |
| 109 | + export CXX="/opt/homebrew/opt/llvm@19/bin/clang++" |
| 110 | + export CXXFLAGS="-stdlib=libc++" |
| 111 | + export LDFLAGS="-L/opt/homebrew/opt/llvm@19/lib" |
| 112 | + which clang++ |
| 113 | + clang++ --version |
| 114 | + make dev-install |
| 115 | + - name: CCache Stats |
| 116 | + run: ccache --print-stats |
| 117 | + - name: Inspect cache directories |
| 118 | + run: | |
| 119 | + mkdir -p ~/.triton |
| 120 | + du -h -d 1 ~/.triton |
| 121 | +
|
| 122 | + mkdir -p ~/.ccache |
| 123 | + du -h -d 1 ~/.ccache |
| 124 | + - # If we're on branch `main`, save the ccache Triton compilation artifacts |
| 125 | + # to the cache so they can be used by other (non-main) CI runs. |
| 126 | + # |
| 127 | + # (It wouldn't be a problem to save the cache on every run, because github |
| 128 | + # evicts cache entries LRU, but maybe this saves a bit of time in CI.) |
| 129 | + name: Save ccache and Triton compilation artifacts to cache |
| 130 | + if: github.ref == 'refs/heads/main' |
| 131 | + uses: actions/cache/save@v4 |
| 132 | + with: |
| 133 | + path: | |
| 134 | + ~/.ccache |
| 135 | + key: triton-artifacts-${{ runner.os }}-${{ runner.arch }}-${{ env.RUNNER_TYPE }}-llvm-${{ steps.cache-key.outputs.llvm }}-${{ steps.cache-key.outputs.datetime }} |
0 commit comments