diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index b71a818e5..8a3c78854 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -37,12 +37,25 @@ jobs: uses: SimenB/github-actions-cpu-cores@v2 id: cpu-cores + # FindSIMD compiles with -march=native, which bakes the building runner's + # ISA into every cached object file, but ccache hashes the flag string and + # not the CPU it expands to. Without a CPU component in the cache key, + # objects built on one runner model get restored onto another, and a + # translation unit compiled fresh on the new CPU then disagrees with the + # cached ones about xsimd::default_arch. Key the cache on the CPU so it + # only restores onto matching hardware. + - name: CPU fingerprint + run: | + CPU=$(grep -m1 '^model name' /proc/cpuinfo | cut -d: -f2-) + echo "CPU: $CPU" + echo "CPU_KEY=$(printf '%s' "$CPU" | sha256sum | cut -c1-12)" >> "$GITHUB_ENV" + - name: Cache Build id: cache-build uses: actions/cache@v5 with: path: ${{ env.CACHE_PATH }} - key: coverage-cache + key: coverage-${{ env.CPU_KEY }}-cache - name: Prepare ccache run: | diff --git a/.github/workflows/cuda.yml b/.github/workflows/cuda.yml index a777807b0..ce36f64a3 100644 --- a/.github/workflows/cuda.yml +++ b/.github/workflows/cuda.yml @@ -51,12 +51,25 @@ jobs: uses: SimenB/github-actions-cpu-cores@v2 id: cpu-cores + # FindSIMD compiles with -march=native, which bakes the building runner's + # ISA into every cached object file, but ccache hashes the flag string and + # not the CPU it expands to. Without a CPU component in the cache key, + # objects built on one runner model get restored onto another, and a + # translation unit compiled fresh on the new CPU then disagrees with the + # cached ones about xsimd::default_arch. Key the cache on the CPU so it + # only restores onto matching hardware. + - name: CPU fingerprint + run: | + CPU=$(grep -m1 '^model name' /proc/cpuinfo | cut -d: -f2-) + echo "CPU: $CPU" + echo "CPU_KEY=$(printf '%s' "$CPU" | sha256sum | cut -c1-12)" >> "$GITHUB_ENV" + - name: Cache Build id: cache-build uses: actions/cache@v5 with: path: ${{ env.CACHE_PATH }} - key: ${{ runner.os }}-${{ matrix.config }}-cache + key: ${{ runner.os }}-${{ matrix.config }}-${{ env.CPU_KEY }}-cache - name: Prepare ccache run: | diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 9451bb919..b9f529d98 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -64,12 +64,41 @@ jobs: choco install ccache "CACHE_PATH=${env:LOCALAPPDATA}\ccache" | Out-File -FilePath $env:GITHUB_ENV -Append + # FindSIMD compiles with -march=native, which bakes the building runner's + # ISA into every cached object file, but ccache hashes the flag string and + # not the CPU it expands to. Without a CPU component in the cache key, + # objects built on one runner model get restored onto another, and a + # translation unit compiled fresh on the new CPU then disagrees with the + # cached ones about xsimd::default_arch. Key the cache on the CPU so it + # only restores onto matching hardware. + - name: CPU fingerprint (Linux/macOS) + if: runner.os != 'Windows' + run: | + if [ "$RUNNER_OS" = "Linux" ]; then + CPU=$(grep -m1 '^model name' /proc/cpuinfo | cut -d: -f2-) + KEY=$(printf '%s' "$CPU" | sha256sum | cut -c1-12) + else + CPU=$(sysctl -n machdep.cpu.brand_string) + KEY=$(printf '%s' "$CPU" | shasum -a 256 | cut -c1-12) + fi + echo "CPU: $CPU" + echo "CPU_KEY=$KEY" >> "$GITHUB_ENV" + + - name: CPU fingerprint (Windows) + if: runner.os == 'Windows' + run: | + $cpu = Get-CimInstance Win32_Processor | Select-Object -First 1 -ExpandProperty Name + Write-Host "CPU: $cpu" + $stream = [IO.MemoryStream]::new([Text.Encoding]::UTF8.GetBytes($cpu)) + $key = (Get-FileHash -InputStream $stream -Algorithm SHA256).Hash.Substring(0, 12) + "CPU_KEY=$key" | Out-File -FilePath $env:GITHUB_ENV -Append + - name: Cache Build id: cache-build uses: actions/cache@v5 with: path: ${{ env.CACHE_PATH }} - key: ${{ runner.os }}-Python${{ matrix.python-version }}-cache + key: ${{ runner.os }}-Python${{ matrix.python-version }}-${{ env.CPU_KEY }}-cache - name: Prepare Ccache run: |