Spaces:
Running on Zero
Running on Zero
File size: 27,828 Bytes
3bf6e3e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 | diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index 2c0e811..a7540f4 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -30,6 +30,8 @@ concurrency:
env:
CARGO_TERM_COLOR: always
CARGO_INCREMENTAL: 0
+ # Turing, Ampere, Ada and Blackwell consumer GPUs, as in ci.yml; newer GPUs JIT the sm_120 PTX.
+ CUDA_ARCH: sm_75,sm_86,sm_89,sm_120
jobs:
version:
@@ -75,7 +77,9 @@ jobs:
echo "publish=$publish" >> "$GITHUB_OUTPUT"
echo "Building $version (publish: $publish)" >> "$GITHUB_STEP_SUMMARY"
- gpu-library:
+ # Each GPU library job uploads gpu-<system>-<vendor>, which the package job
+ # puts beside the binary in the matching altd-sim-*-<vendor> archive.
+ gpu-linux-amd:
runs-on: ubuntu-latest
timeout-minutes: 30
container: rocm/dev-ubuntu-24.04:7.1.1
@@ -91,13 +95,117 @@ jobs:
sort gpu/release-targets | diff -u - embedded
- uses: actions/upload-artifact@v4
with:
- name: gpu-library
+ name: gpu-linux-amd
path: dist/libaltd_gpu.so
if-no-files-found: error
+ gpu-linux-nvidia:
+ runs-on: ubuntu-latest
+ timeout-minutes: 30
+ # Keep the CUDA version in step with ci.yml. Ubuntu 22.04 matches the
+ # package job, so the library needs no newer glibc than the binary.
+ container: nvidia/cuda:13.4.2-devel-ubuntu22.04
+ steps:
+ - name: Install the tools the CUDA image lacks
+ run: apt-get update && apt-get install -y --no-install-recommends python3
+ - uses: actions/checkout@v4
+ - name: Build for every consumer GPU target
+ run: OUT=dist gpu/build-cuda.sh
+ - uses: actions/upload-artifact@v4
+ with:
+ name: gpu-linux-nvidia
+ path: dist/libaltd_gpu.so
+ if-no-files-found: error
+
+ gpu-windows-amd:
+ # The HIP SDK 7.1 clang headers clash with the MSVC 14.5x <cmath> of Visual
+ # Studio 2026 (windows-latest): its isgreater and friends are already
+ # __host__ __device__. Visual Studio 2022 builds.
+ runs-on: windows-2022
+ timeout-minutes: 60
+ env:
+ RUSTFLAGS: -C target-cpu=x86-64
+ HIP_SDK: C:\hip-sdk
+ steps:
+ - run: git config --global core.autocrlf false
+ - uses: actions/checkout@v4
+ - name: Install the HIP SDK
+ # HIP SDK for Windows 7.1.1, in step with the ROCm 7.1.1 Linux builds. The
+ # bundle also installs a driver, so only its SDK core package is installed.
+ run: |
+ $installer = Join-Path $env:RUNNER_TEMP "hip-sdk.exe"
+ curl.exe -fsSL -o $installer https://download.amd.com/developer/eula/rocm-hub/AMD-Software-PRO-Edition-26.Q1-Win11-For-HIP.exe
+ if ($LASTEXITCODE -ne 0) { throw "cannot download the HIP SDK" }
+ $unpacked = Join-Path $env:RUNNER_TEMP "hip-sdk"
+ 7z x $installer "-o$unpacked" | Out-Null
+ if ($LASTEXITCODE -ne 0) { throw "cannot unpack the HIP SDK" }
+ $msi = Get-ChildItem $unpacked -Recurse -Filter ROCm_SDK_Core.msi | Select-Object -First 1
+ if (-not $msi) { throw "the HIP SDK bundle has no ROCm_SDK_Core.msi" }
+ $log = Join-Path $env:RUNNER_TEMP "hip-sdk.log"
+ $install = Start-Process msiexec -Wait -PassThru -ArgumentList "/i", "`"$($msi.FullName)`"", "INSTALLDIR=$env:HIP_SDK", "/qn", "/norestart", "/l*v", "`"$log`""
+ if ($install.ExitCode -ne 0) { Get-Content $log -Tail 50; throw "HIP SDK install failed with $($install.ExitCode)" }
+ $hipcc = Get-ChildItem $env:HIP_SDK -Recurse -Filter hipcc.exe | Select-Object -First 1
+ if (-not $hipcc) { throw "no hipcc.exe under $env:HIP_SDK" }
+ & $hipcc.FullName --version
+ "HIP_PATH=$(Split-Path $hipcc.DirectoryName)" >> $env:GITHUB_ENV
+ # gpu-info below loads the HIP runtime (amdhip64_7.dll) from here.
+ $hipcc.DirectoryName >> $env:GITHUB_PATH
+ - name: Build for every consumer GPU target
+ run: ./gpu/build.ps1 -Out dist -Arch (Get-Content gpu/release-targets -Raw)
+ - uses: dtolnay/rust-toolchain@1.94.0
+ - uses: Swatinem/rust-cache@v2
+ with:
+ key: gpu-windows-x86-64
+ - name: Check the library against the Rust layouts
+ # No GPU is needed: gpu-info checks the device struct layouts and the exports on the host.
+ run: cargo run --locked --bin altd-sim -- gpu-info --library dist/altd_gpu.dll
+ - uses: actions/upload-artifact@v4
+ with:
+ name: gpu-windows-amd
+ path: dist/altd_gpu.dll
+ if-no-files-found: error
+
+ gpu-windows-nvidia:
+ runs-on: windows-latest
+ timeout-minutes: 30
+ env:
+ CUDA_VERSION: 13.4.2
+ steps:
+ - run: git config --global core.autocrlf false
+ - uses: actions/checkout@v4
+ - name: Install the CUDA compiler
+ # Only the redistributable parts nvcc needs, not the whole toolkit installer.
+ run: |
+ $base = "https://developer.download.nvidia.com/compute/cuda/redist"
+ $manifest = Invoke-RestMethod "$base/redistrib_$env:CUDA_VERSION.json"
+ $parts = Join-Path $env:RUNNER_TEMP "cuda-parts"
+ $cuda = Join-Path $env:RUNNER_TEMP "cuda"
+ foreach ($name in "cuda_nvcc", "cuda_crt", "cuda_cudart", "libnvvm", "cccl") {
+ $zip = Join-Path $env:RUNNER_TEMP "$name.zip"
+ curl.exe -fsSL -o $zip "$base/$($manifest.$name.'windows-x86_64'.relative_path)"
+ if ($LASTEXITCODE -ne 0) { throw "cannot download $name" }
+ 7z x $zip "-o$parts" | Out-Null
+ if ($LASTEXITCODE -ne 0) { throw "cannot unpack $name" }
+ }
+ # Each archive unpacks into its own directory; merge them into one toolkit.
+ foreach ($dir in Get-ChildItem $parts -Directory) {
+ robocopy $dir.FullName $cuda /E /NFL /NDL /NJH /NJS /NP | Out-Null
+ if ($LASTEXITCODE -ge 8) { throw "cannot merge $($dir.Name)" }
+ }
+ "CUDA_PATH=$cuda" >> $env:GITHUB_ENV
+ "$cuda\bin" >> $env:GITHUB_PATH
+ & "$cuda\bin\nvcc.exe" --version
+ - name: Build for every consumer GPU target
+ run: ./gpu/build-cuda.ps1 -Out dist
+ - uses: actions/upload-artifact@v4
+ with:
+ name: gpu-windows-nvidia
+ path: dist/altd_gpu.dll
+ if-no-files-found: error
+
package:
name: package (${{ matrix.target }})
- needs: [version, gpu-library]
+ needs: [version, gpu-linux-amd, gpu-linux-nvidia, gpu-windows-amd, gpu-windows-nvidia]
runs-on: ${{ matrix.os }}
timeout-minutes: 45
strategy:
@@ -108,18 +216,29 @@ jobs:
- os: ubuntu-22.04
target: x86_64-unknown-linux-gnu
rustflags: -C target-cpu=x86-64
- gpu: true
+ system: linux
+ library: libaltd_gpu.so
+ variants: cpu amd nvidia
- os: windows-latest
target: x86_64-pc-windows-msvc
rustflags: -C target-cpu=x86-64
exe: .exe
+ system: windows
+ library: altd_gpu.dll
+ variants: cpu amd nvidia
- os: macos-latest
target: aarch64-apple-darwin
+ system: macos
+ variants: cpu
env:
# Overrides target-cpu=native from .cargo/config.toml on x86 hosts.
RUSTFLAGS: ${{ matrix.rustflags }}
ALTD_BUILD_VERSION: ${{ needs.version.outputs.version }}
+ # Each variant becomes the archive $PACKAGE-<variant>: cpu has no GPU
+ # library, amd and nvidia carry that vendor's library beside the binary.
PACKAGE: altd-sim-${{ needs.version.outputs.label }}-${{ matrix.target }}
+ VARIANTS: ${{ matrix.variants }}
+ LIBRARY: ${{ matrix.library }}
defaults:
run:
shell: bash
@@ -134,48 +253,72 @@ jobs:
with:
key: release-${{ matrix.target }}
- run: cargo build --locked --release --bin altd-sim --target ${{ matrix.target }}
- - name: Assemble the package
- run: |
- mkdir -p "dist/$PACKAGE"
- cp "target/${{ matrix.target }}/release/altd-sim${{ matrix.exe }}" README.md LICENSE GODOT_LICENSE "dist/$PACKAGE/"
- cp -R assets docs "dist/$PACKAGE/"
- mkdir -p "dist/$PACKAGE/math"
- cp math/README.md "dist/$PACKAGE/math/"
- - if: matrix.gpu
+ - if: matrix.library
uses: actions/download-artifact@v4
with:
- name: gpu-library
- path: dist/${{ env.PACKAGE }}
+ pattern: gpu-${{ matrix.system }}-*
+ path: gpu-libraries
+ - name: Assemble the packages
+ run: |
+ for variant in $VARIANTS; do
+ name="$PACKAGE-$variant"
+ mkdir -p "dist/$name/math"
+ cp "target/${{ matrix.target }}/release/altd-sim${{ matrix.exe }}" README.md LICENSE GODOT_LICENSE "dist/$name/"
+ cp -R assets docs "dist/$name/"
+ cp math/README.md "dist/$name/math/"
+ if [ "$variant" != cpu ]; then
+ cp "gpu-libraries/gpu-${{ matrix.system }}-$variant/$LIBRARY" "dist/$name/"
+ fi
+ done
- name: Archive
working-directory: dist
run: |
- if [ "$RUNNER_OS" = Windows ]; then
- 7z a -tzip "$PACKAGE.zip" "$PACKAGE" > /dev/null
- else
- tar -czf "$PACKAGE.tar.gz" "$PACKAGE"
- fi
- rm -rf "$PACKAGE"
- - name: Smoke test the unpacked archive
+ for variant in $VARIANTS; do
+ name="$PACKAGE-$variant"
+ if [ "$RUNNER_OS" = Windows ]; then
+ 7z a -tzip "$name.zip" "$name" > /dev/null
+ else
+ tar -czf "$name.tar.gz" "$name"
+ fi
+ rm -rf "$name"
+ done
+ - name: Smoke test the unpacked archives
run: |
- mkdir smoke
- cd smoke
- if [ "$RUNNER_OS" = Windows ]; then 7z x "../dist/$PACKAGE.zip" > /dev/null; else tar -xzf "../dist/$PACKAGE.tar.gz"; fi
- cd "$PACKAGE"
- ./altd-sim --version | tee version.txt
- grep -qxF "altd-sim $ALTD_BUILD_VERSION" version.txt
- ./altd-sim --threads 2 train-scratch \
- --scene assets/scenes/rally_template.json --track-mode random \
- --random-track-settings assets/random_track_settings.json \
- --population 16 --generations 1 --ticks 60 --seed 1 --out-dir smoke-run
- test -s smoke-run/run.json
- if [ "${{ matrix.gpu }}" = true ]; then
- # Hosted runners lack ROCm: the packaged library must be found and
- # its missing HIP runtime reported. gpu-verify loads it with ROCm.
- if ./altd-sim gpu-info 2> gpu-info.txt; then exit 1; fi
- cat gpu-info.txt
- grep -q "$PWD/libaltd_gpu.so" gpu-info.txt
- grep -q "ROCm 7.x runtime" gpu-info.txt
- fi
+ for variant in $VARIANTS; do
+ name="$PACKAGE-$variant"
+ mkdir -p "smoke/$variant"
+ cd "smoke/$variant"
+ if [ "$RUNNER_OS" = Windows ]; then 7z x "../../dist/$name.zip" > /dev/null; else tar -xzf "../../dist/$name.tar.gz"; fi
+ cd "$name"
+ ./altd-sim --version | tee version.txt
+ grep -qxF "altd-sim $ALTD_BUILD_VERSION" version.txt
+ ./altd-sim --threads 2 train-scratch \
+ --scene assets/scenes/rally_template.json --track-mode random \
+ --random-track-settings assets/random_track_settings.json \
+ --population 16 --generations 1 --ticks 60 --seed 1 --out-dir smoke-run
+ test -s smoke-run/run.json
+ # The path the binary reports for the library beside it.
+ if [ "$RUNNER_OS" = Windows ]; then library=$(cygpath -w "$PWD/$LIBRARY"); else library="$PWD/$LIBRARY"; fi
+ case "$variant" in
+ amd)
+ # Hosted runners lack the HIP runtime: the packaged library must be
+ # found and fail to load. gpu-verify and gpu-windows-amd load it with HIP.
+ if ./altd-sim gpu-info 2> gpu-info.txt; then exit 1; fi
+ cat gpu-info.txt
+ grep -qF "$library" gpu-info.txt
+ if [ "$RUNNER_OS" = Linux ]; then grep -q "ROCm 7.x runtime" gpu-info.txt; fi
+ ;;
+ nvidia)
+ # The CUDA runtime is linked in and finds no driver, so the library
+ # loads and gpu-info checks its layouts without a GPU.
+ ./altd-sim gpu-info | tee gpu-info.json
+ grep -q '"layout": "ok"' gpu-info.json
+ grep -q '"platform": "CUDA"' gpu-info.json
+ grep -qF "\"${library//\\/\\\\}\"" gpu-info.json
+ ;;
+ esac
+ cd "$GITHUB_WORKSPACE"
+ done
- uses: actions/upload-artifact@v4
with:
name: ${{ env.PACKAGE }}
@@ -195,8 +338,8 @@ jobs:
name: ${{ env.PACKAGE }}
- name: Load the packaged HIP library with the ROCm runtime
run: |
- tar -xzf "$PACKAGE.tar.gz"
- cd "$PACKAGE"
+ tar -xzf "$PACKAGE-amd.tar.gz"
+ cd "$PACKAGE-amd"
# No GPU is needed: gpu-info checks the device struct layouts on the host.
./altd-sim gpu-info | tee gpu-info.json
grep -q '"layout": "ok"' gpu-info.json
@@ -242,3 +385,7 @@ jobs:
gh release create nightly --prerelease --latest=false --verify-tag --title "$title" --notes "$notes"
fi
gh release upload nightly dist/* --clobber
+ # Drop assets this build no longer produces, such as renamed archives.
+ gh release view nightly --json assets --jq '.assets[].name' | while read -r asset; do
+ if [ ! -e "dist/$asset" ]; then gh release delete-asset nightly "$asset" --yes; fi
+ done
diff --git a/Cargo.lock b/Cargo.lock
index 26d9448..dd79258 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -4,7 +4,7 @@ version = 4
[[package]]
name = "altd_sim"
-version = "1.2.0"
+version = "1.3.0"
dependencies = [
"clap",
"console_error_panic_hook",
diff --git a/Cargo.toml b/Cargo.toml
index 5d466cd..2fbcad8 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "altd_sim"
-version = "1.2.0"
+version = "1.3.0"
edition = "2021"
description = "CPU game-fidelity simulator and trainer for AI Learns To Drive"
license = "MIT"
diff --git a/README.md b/README.md
index 9e9cdc3..d8384d3 100644
--- a/README.md
+++ b/README.md
@@ -16,15 +16,19 @@ Download the archive for your system from [Releases](https://github.com/Zorro909
| System | Archive | Training on |
| --- | --- | --- |
-| Linux x86_64 | `altd-sim-<version>-x86_64-unknown-linux-gnu.tar.gz` | CPU, or AMD GPU through HIP |
-| Windows x86_64 | `altd-sim-<version>-x86_64-pc-windows-msvc.zip` | CPU |
-| macOS, Apple silicon | `altd-sim-<version>-aarch64-apple-darwin.tar.gz` | CPU |
+| Linux x86_64 | `altd-sim-<version>-x86_64-unknown-linux-gnu-cpu.tar.gz` | CPU |
+| | `altd-sim-<version>-x86_64-unknown-linux-gnu-amd.tar.gz` | CPU, or AMD GPU through HIP |
+| | `altd-sim-<version>-x86_64-unknown-linux-gnu-nvidia.tar.gz` | CPU, or NVIDIA GPU through CUDA |
+| Windows x86_64 | `altd-sim-<version>-x86_64-pc-windows-msvc-cpu.zip` | CPU |
+| | `altd-sim-<version>-x86_64-pc-windows-msvc-amd.zip` | CPU, or AMD GPU through HIP |
+| | `altd-sim-<version>-x86_64-pc-windows-msvc-nvidia.zip` | CPU, or NVIDIA GPU through CUDA |
+| macOS, Apple silicon | `altd-sim-<version>-aarch64-apple-darwin-cpu.tar.gz` | CPU |
-Unpack it and open a terminal in the unpacked folder:
+The `amd` and `nvidia` archives add that vendor's GPU library beside the same `altd-sim` binary. Unpack one and open a terminal in the unpacked folder:
```sh
-tar -xzf altd-sim-nightly-x86_64-unknown-linux-gnu.tar.gz
-cd altd-sim-nightly-x86_64-unknown-linux-gnu
+tar -xzf altd-sim-nightly-x86_64-unknown-linux-gnu-cpu.tar.gz
+cd altd-sim-nightly-x86_64-unknown-linux-gnu-cpu
./altd-sim --version
```
@@ -68,13 +72,13 @@ Each browser connection gets its own session. Only one session at a time can use
All builds include all three math profiles. Windows 11 24H2 and newer default to `win11-fma3`; earlier Windows releases use `win10-fma3`; Linux and macOS use `proton`. To train on Linux for a game running on current Windows, for example, pass `--math-profile win11-fma3`. Checkpoints retain their profile. [Math profiles](math/README.md) describes the kernels and captured reference data.
-### Training on an AMD GPU
+### Training on a GPU
-The Linux archive contains `libaltd_gpu.so` next to `altd-sim`. It needs a ROCm 7.x runtime and one of the [covered GPU architectures](gpu/README.md). `./altd-sim gpu-info` checks that the library loads and prints `"layout": "ok"`; with a GPU present it also runs one kernel and prints the device, and fails if the library has no code for that GPU; the server's `HIP:` line shows the device or why HIP is unavailable.
+The `amd` and `nvidia` archives contain the GPU library next to `altd-sim`: `libaltd_gpu.so` on Linux, `altd_gpu.dll` on Windows. AMD libraries need a ROCm 7.x runtime that provides `libamdhip64.so.7` on Linux, or an AMD driver or HIP SDK 7.1 that provides `amdhip64_7.dll` on Windows, and one of the [covered GPU architectures](gpu/README.md). NVIDIA libraries need only an NVIDIA driver that supports CUDA 13 (580 or newer) and a consumer GPU from RTX 20 (Turing) to RTX 50 (Blackwell) or newer; datacenter GPUs such as A100 and H100 need a library built for their target, see the [GPU guide](gpu/README.md#nvidia-cuda). `./altd-sim gpu-info` checks that the library loads and prints `"layout": "ok"`; with a GPU present it also runs one kernel and prints the device, and fails if the library has no code for that GPU; the server's `HIP:` line shows the device or why HIP is unavailable.
A HIP session drives its first 12 ticks on both the GPU and the CPU and compares them. If they differ, or the network or track needs something HIP does not support, the session trains on CPU and Drive Lab shows the reason. Native CPU and HIP produce the same results. Browser training can differ from both in the last digits of a few values ([issue #3](https://github.com/Zorro909/driving_sim_rs/issues/3)), so a run moved between the browser and the server can develop differently from then on.
-NVIDIA GPUs use the same backend: build the library with `gpu/build-cuda.sh` (Linux) or `gpu/build-cuda.ps1` (Windows) as described in the [GPU guide](gpu/README.md#nvidia-cuda). The release archives do not include it.
+NVIDIA GPUs use the same backend, so HIP in Drive Lab and the server output also covers CUDA. To build a library yourself, see the [GPU guide](gpu/README.md).
### Troubleshooting
@@ -178,6 +182,6 @@ cargo build --offline --target wasm32-unknown-unknown --no-default-features --fe
Tests retain self-contained native captures and label generated golden data as current-code regressions. Browser integration checks live in `wasm/test/`; HIP equivalence checks use `gpu_check`. The exhaustive trigonometry scan and hardware-dependent tests are opt-in. See [performance](docs/performance.md), [GPU internals](docs/gpu.md) and [WASM fidelity](docs/wasm.md).
-GitHub Actions checks formatting, native and WASM Clippy, native release and debug tests, Windows and macOS Clippy and release tests, the HIP library build and layout, rustdoc, Rust 1.93 compatibility, and WASM packages with CPU browser comparisons. The release workflow builds and smoke-tests the archives, then publishes tags and nightly builds. Its native jobs override `target-cpu=native` with `x86-64` and include the flags in their cache keys, so cached builds can move between runner CPUs. Serial/threaded browser tests retain the documented expanded native differences. HIP equivalence and hardware WebGPU checks run separately because the hosted runners have no GPU.
+GitHub Actions checks formatting, native and WASM Clippy, native release and debug tests, Windows and macOS Clippy and release tests, the HIP library build and layout, rustdoc, Rust 1.93 compatibility, and WASM packages with CPU browser comparisons. The release workflow builds the AMD and NVIDIA libraries for Linux and Windows, smoke-tests the CPU, AMD and NVIDIA archives, then publishes tags and nightly builds. Its native jobs override `target-cpu=native` with `x86-64` and include the flags in their cache keys, so cached builds can move between runner CPUs. Serial/threaded browser tests retain the documented expanded native differences. HIP equivalence and hardware WebGPU checks run separately because the hosted runners have no GPU.
The project uses the [MIT license](LICENSE). Godot-derived code retains the [Godot notice](GODOT_LICENSE), and numerical modules retain their source notices.
diff --git a/docs/server.md b/docs/server.md
index 3c7c41d..937fb1e 100644
--- a/docs/server.md
+++ b/docs/server.md
@@ -39,7 +39,7 @@ There is no LAN binding, TLS or authentication token. These checks restrict brow
The first frame is a JSON text greeting:
```json
-{"type":"hello","protocol":1,"version":"1.2.0","threads":8,"carStateStride":14,"carStateFields":["x","y","..."],"hip":{"available":true,"device":"AMD Radeon RX 7900 XTX","platform":"HIP"},"mathProfile":"proton","mathProfiles":["proton","win10-fma3","win11-fma3"]}
+{"type":"hello","protocol":1,"version":"1.3.0","threads":8,"carStateStride":14,"carStateFields":["x","y","..."],"hip":{"available":true,"device":"AMD Radeon RX 7900 XTX","platform":"HIP"},"mathProfile":"proton","mathProfiles":["proton","win10-fma3","win11-fma3"]}
```
Read `carStateStride` and `carStateFields` from the greeting rather than hard-coding them. The example's fields are abbreviated. `platform` is `"HIP"` for the AMD library and `"CUDA"` for the NVIDIA one. When HIP is unavailable, `hip` instead contains `{"available":false,"reason":"..."}`. Availability means the process opened the library and device; a particular session can still fall back to CPU. `mathProfile` is the default math profile and `mathProfiles` lists every profile a session can choose; [math profiles](../math/README.md) documents their runtime variants.
diff --git a/gpu/README.md b/gpu/README.md
index 4a51bb6..5fbc237 100644
--- a/gpu/README.md
+++ b/gpu/README.md
@@ -4,7 +4,7 @@ The GPU library runs whole driving generations on an AMD GPU (HIP) or an NVIDIA
## Build and use
-Linux release archives include `libaltd_gpu.so` beside `altd-sim`, built with ROCm 7.1 for the targets in `release-targets`. They need a ROCm 7.x runtime that provides `libamdhip64.so.7`, but no compiler. `altd-sim gpu-info` reports the loaded library. To build the library yourself, install ROCm with `hipcc`, then build from the repository root:
+The `amd` release archives include the library beside `altd-sim`, built for the targets in `release-targets`: `libaltd_gpu.so` with ROCm 7.1 on Linux, `altd_gpu.dll` with the HIP SDK 7.1 on Windows. They need a ROCm 7.x runtime that provides `libamdhip64.so.7` (Linux), or an AMD driver or HIP SDK 7.1 that provides `amdhip64_7.dll` (Windows), but no compiler. `altd-sim gpu-info` reports the loaded library. To build the library yourself, install ROCm with `hipcc` (or the HIP SDK on Windows, then use `gpu/build.ps1`), and build from the repository root:
```sh
gpu/build.sh
@@ -46,6 +46,8 @@ gpu/build-cuda.sh # Linux, writes target/gpu/libaltd_gpu.so
gpu/build-cuda.ps1 # Windows, writes target/gpu/altd_gpu.dll
```
+The `nvidia` release archives include a library built with CUDA 13.4 for `sm_75,sm_86,sm_89,sm_120` plus `sm_120` PTX: RTX 20 to RTX 50 GPUs, and later GPUs through the PTX. Other targets, such as `sm_80` (A100) and `sm_90` (H100), need their own build. It links the CUDA runtime statically, so it needs only an NVIDIA driver that supports CUDA 13 (580 or newer).
+
`OUT` overrides the output directory. `CUDA_ARCH` defaults to `native`, which builds for the GPUs of the build machine. Without a GPU, nvcc 13.4 warns and builds `sm_75` code and PTX instead, which newer GPUs compile at load time. To build for other GPUs, or several, list `sm_` targets separated by commas or spaces; `nvidia-smi --query-gpu=compute_cap --format=csv` reports the number, so 8.6 is `sm_86`. A list also embeds PTX for its newest target, which the driver compiles at load time for a newer GPU. CUDA 13 builds for Turing (`sm_75`, RTX 20 series) and newer only; older GPUs need a CUDA 12 toolkit, which is untested. Both scripts check the double tables with `gpu/gen_tables.py --check` (`python3` on Linux, the `py` launcher or `python` on Windows). The binary loads `ALTD_GPU_LIB`, then the library beside the executable, then `target/gpu`, as on AMD. `altd-sim gpu-info` runs one kernel when a GPU is present, so a library built for another GPU fails there with HIP error 209.
nvcc rejects a Visual Studio newer than the toolkit supports. `gpu/build-cuda.ps1 -AllowUnsupportedCompiler` (or `CUDA_ALLOW_UNSUPPORTED_COMPILER=1`) builds anyway with a warning; NVIDIA has not validated that combination, so run the checks below before trusting the library.
diff --git a/gpu/build.ps1 b/gpu/build.ps1
new file mode 100644
index 0000000..499450f
--- /dev/null
+++ b/gpu/build.ps1
@@ -0,0 +1,28 @@
+# Build altd_gpu.dll (the GPU simulator parts) for AMD GPUs with the HIP SDK for Windows into $OUT.
+# GPU_ARCH lists one or more offload targets separated by commas or spaces.
+# -ffp-contract=off: hipcc otherwise fuses a*b+c into FMA, which rounds once.
+# HIP_PATH is the HIP SDK root, which its installer sets.
+param(
+ [string]$Out = $(if ($env:OUT) { $env:OUT } else { Join-Path $PSScriptRoot "..\target\gpu" }),
+ [string]$Arch = $(if ($env:GPU_ARCH) { $env:GPU_ARCH } else { "gfx1100" })
+)
+$ErrorActionPreference = "Stop"
+New-Item -ItemType Directory -Force $Out | Out-Null
+$Out = (Resolve-Path $Out).Path
+
+# The py launcher first: python3 on Windows is often the Microsoft Store placeholder.
+$tables = Join-Path $PSScriptRoot "gen_tables.py"
+if (Get-Command py -ErrorAction SilentlyContinue) { py -3 $tables --check } else { python $tables --check }
+if ($LASTEXITCODE -ne 0) { throw "gen_tables.py --check failed" }
+
+$targets = @($Arch -split '[,\s]+' | Where-Object { $_ })
+if (-not $targets) { throw "GPU_ARCH lists no targets" }
+if (-not $env:HIP_PATH) { throw "HIP_PATH is not set; install the HIP SDK for Windows" }
+$hipcc = Join-Path $env:HIP_PATH "bin\hipcc.exe"
+
+$src = Join-Path $PSScriptRoot "sim\altd_gpu.hip"
+$dll = Join-Path $Out "altd_gpu.dll"
+& $hipcc -O3 -ffp-contract=off @($targets | ForEach-Object { "--offload-arch=$_" }) -shared -std=c++20 `
+ -fhip-fp32-correctly-rounded-divide-sqrt -o $dll $src -L (Join-Path $env:HIP_PATH "lib") -lamdhip64
+if ($LASTEXITCODE -ne 0) { throw "hipcc failed" }
+Write-Host "built $dll for $($targets -join ' ')"
diff --git a/gpu/sim/altd_gpu.hip b/gpu/sim/altd_gpu.hip
index b0962e3..fafb3ee 100644
--- a/gpu/sim/altd_gpu.hip
+++ b/gpu/sim/altd_gpu.hip
@@ -502,7 +502,8 @@ double thread_cpu_seconds() {
// runtime's single-dispatch limit, so by default every launch allocates and
// frees it (0.2-1.7 ms per launch). Keeping the scratch avoids that. Runs at
// load, before the first HIP call initialises HSA; an explicit setting wins.
-#if !defined(__CUDACC__)
+// HIP on Windows runs on PAL instead of HSA, and its C runtime has no setenv.
+#if !defined(__CUDACC__) && !defined(_WIN32)
__attribute__((constructor)) void keep_scratch() { setenv("HSA_NO_SCRATCH_RECLAIM", "1", 0); }
#endif
|