From 9b8e3d9f19c25db603c70cfefbc9cf40ab44c2e5 Mon Sep 17 00:00:00 2001 From: Ludovic Henry Date: Mon, 16 Nov 2026 13:12:19 +0000 Subject: [PATCH 1/6] Add triton port (riscv64) via RuyiAI-Stack/triton-riscv Upstream triton-lang/triton is GPU-only with no riscv64 target (gotcha 41, not-feasible). This builds the RuyiAI-Stack/triton-riscv fork instead, which replaces the NVIDIA/AMD codegen with a CPU/riscv64 backend (triton-shared -> Buddy Compiler -> LLVM llc) against prebuilt riscv64 LLVM/buddy-mlir toolchains, and reuses that fork's own scripts/release.sh directly rather than reimplementing its build. --- .github/workflows/build-triton.yml | 179 +++++++++++++++++++++++++++++ docs/packages/triton.yaml | 17 +++ 2 files changed, 196 insertions(+) create mode 100644 .github/workflows/build-triton.yml create mode 100644 docs/packages/triton.yaml diff --git a/.github/workflows/build-triton.yml b/.github/workflows/build-triton.yml new file mode 100644 index 00000000000..e65ba5c05e3 --- /dev/null +++ b/.github/workflows/build-triton.yml @@ -0,0 +1,179 @@ +# SPDX-FileCopyrightText: 2026 The RISE Project +# SPDX-License-Identifier: MIT +--- +# Upstream triton-lang/triton is triaged not-feasible on riscv64 (gotcha 41): it is +# a GPU-only compiler with proprietary NVIDIA/AMD vendor blobs and no riscv64 +# target anywhere in the stack. This workflow instead builds the +# RuyiAI-Stack/triton-riscv fork, which replaces the GPU codegen with a real +# LLVM/MLIR-native path (TTIR -> Linalg via triton-shared, Linalg -> LLVM IR via +# Buddy Compiler, then riscv64 `llc` codegen) and ships it as a `triton.backends` +# plugin, so no part of upstream's own build is patched. +# +# triton-riscv's own scripts/release.sh is reused directly rather than +# reimplemented: given a ` ` pair it does the whole job itself -- +# docker-runs the riscv64 manylinux image, installs its own clang/lld toolchain, +# clones the pinned triton-lang/triton commit (triton-hash.txt), downloads +# prebuilt riscv64 LLVM and buddy-mlir toolchains (buddy-hash.txt, as GitHub +# release tarballs -- no from-source LLVM build), builds Triton with the +# triton-shared plugin against the stable Python ABI (TRITON_STABLE_ABI=ON, so +# the wheel is tagged cp312-abi3), strips the bundled LLVM/buddy tool binaries, +# and runs auditwheel repair. TRITON_RISCV_REF below pins their release tag +# independently of docs/packages/triton.yaml's version (which tracks triton's own +# __version__, not triton-riscv's release cadence). +name: Build triton wheels (riscv64) + +on: + workflow_dispatch: + inputs: + version: + description: 'Version glob to (re)build; empty builds every version of docs/packages/triton.yaml not released yet' + required: false + default: '' + cancel-in-progress: + description: Cancel an in-progress run in the same concurrency group. + required: false + type: boolean + default: true + pull_request: + branches: [main] + paths: + - '.github/workflows/build-triton.yml' + - 'docs/packages/triton.yaml' + push: + branches: [main] + paths: + - '.github/workflows/build-triton.yml' + - 'docs/packages/triton.yaml' + +concurrency: + group: ${{ github.workflow }}-${{ github.head_ref || github.ref }} + cancel-in-progress: ${{ github.event_name != 'workflow_dispatch' || inputs['cancel-in-progress'] }} + +permissions: + contents: read # to fetch code (actions/checkout) + +env: + # The triton-riscv tag this workflow builds, independent of the triton version + # matrix below (see the header comment). + TRITON_RISCV_REF: release/20261115-e99c326 + +jobs: + setup: + uses: $/.github/workflows/_setup.yml + with: + package: triton + version: ${{ inputs.version }} + + build_wheels: + needs: [setup] + if: needs.setup.outputs.versions != '[]' + strategy: + fail-fast: false + matrix: + version: ${{ fromJSON(needs.setup.outputs.versions) }} + name: Build triton ${{ matrix.version }} cp312-abi3-manylinux_riscv64 + runs-on: ubuntu-24.04-riscv + # A full Triton + triton-shared C++ build (plus the one-time LLVM/buddy-mlir + # toolchain download) comfortably clears an hour; leave generous headroom + # rather than guess from upstream's own x86_64 CI timing. + timeout-minutes: 360 + + env: + TRITON_VERSION: ${{ matrix.version }} + + steps: + - name: Checkout triton-riscv ${{ env.TRITON_RISCV_REF }} + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + repository: RuyiAI-Stack/triton-riscv + ref: ${{ env.TRITON_RISCV_REF }} + path: triton-riscv + persist-credentials: false + + - name: Build wheel + working-directory: triton-riscv + env: + # Anonymous git from this fleet's self-hosted runners gets a 401 on + # some hosts (their own ci.yml carries the same workaround); setup.sh + # clones triton-lang/triton and Triton's own cmake clones googletest. + GITHUB_TOKEN: ${{ github.token }} + run: | + # release.sh docker-runs quay.io/pypa/manylinux_2_39_riscv64 itself when + # IN_DOCKER is unset, so nothing here needs to set up that container. + # + # NB: if this OOMs, it's the same root cause as gotcha 421 (this + # fleet's riscv64 runners have ~15GB RAM and no usable swap) - + # release.sh's docker run does not forward MAX_JOBS/ + # CMAKE_BUILD_PARALLEL_LEVEL into the container the way their own + # ci.yml sets them on the host, so a fix would need to cap + # concurrency inside the container rather than in this step's env. + ./scripts/release.sh cp312-cp312 riscv64 + ls -la build/release/riscv64/cp312-cp312/ + + - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 + with: + name: triton-${{ env.TRITON_VERSION }}-cp312-abi3-manylinux_riscv64 + path: triton-riscv/build/release/riscv64/cp312-cp312/*.whl + if-no-files-found: error + + - name: setup uv + uses: astral-sh/setup-uv@20cfd1bf945f4377ade1205e4dbc17946fc9a30d # v10.0.1 + with: + python-version: '3.12' + activate-environment: true + enable-cache: false + + - name: Test triton wheel + env: + PIP_EXTRA_INDEX_URL: https://pypi.riseproject.dev/simple/ + run: | + # torch is this registry's own riscv64 CPU build (docs/packages/torch.yaml); + # Triton's kernel launch path expects torch tensors, and installing it from + # the registry here (rather than triton-riscv's own external + # ruyirepo.ruyicommunity.cn index, used only by their own CI) keeps this + # entirely within this repo's normal wheel supply. + uv pip install --only-binary=:all: torch + uv pip install triton-riscv/build/release/riscv64/cp312-cp312/*.whl + python3 -c " + import torch + import triton + import triton.language as tl + + @triton.jit + def add_kernel(x_ptr, y_ptr, out_ptr, n_elements, BLOCK_SIZE: tl.constexpr): + pid = tl.program_id(axis=0) + offsets = pid * BLOCK_SIZE + tl.arange(0, BLOCK_SIZE) + mask = offsets < n_elements + x = tl.load(x_ptr + offsets, mask=mask) + y = tl.load(y_ptr + offsets, mask=mask) + tl.store(out_ptr + offsets, x + y, mask=mask) + + x = torch.rand(98432) + y = torch.rand(98432) + out = torch.empty_like(x) + n_elements = out.numel() + grid = lambda meta: (triton.cdiv(n_elements, meta['BLOCK_SIZE']),) + add_kernel[grid](x, y, out, n_elements, BLOCK_SIZE=1024) + expected = x + y + assert torch.allclose(out, expected), (out, expected) + print('triton riscv64/triton_shared kernel OK, max abs diff', + (out - expected).abs().max().item()) + " + + publish: + name: Publish triton ${{ matrix.version }} + needs: [setup, build_wheels] + if: needs.setup.outputs.versions != '[]' + strategy: + fail-fast: false + matrix: + version: ${{ fromJSON(needs.setup.outputs.versions) }} + permissions: + contents: write + pull-requests: write + uses: $/.github/workflows/_publish-wheel.yml + secrets: + app-private-key: ${{ secrets.RISEPROJECT_APP_PRIVATE_KEY }} + with: + matrix: ${{ needs.setup.outputs.matrix }} + artifact-pattern: triton-${{ matrix.version }}-*-manylinux_riscv64 diff --git a/docs/packages/triton.yaml b/docs/packages/triton.yaml new file mode 100644 index 00000000000..51b35e8bfc5 --- /dev/null +++ b/docs/packages/triton.yaml @@ -0,0 +1,17 @@ +package-name: triton +source-code: https://github.com/RuyiAI-Stack/triton-riscv +license: MIT AND Apache-2.0 WITH LLVM-exception AND Apache-2.0 +comment: >- + Upstream triton-lang/triton is GPU-only with no riscv64 target (CLAUDE.md + gotcha 41). This builds the RuyiAI-Stack/triton-riscv fork instead, which + replaces the NVIDIA/AMD codegen with a CPU/riscv64 backend (triton-shared's + TTIR->Linalg lowering, then Buddy Compiler's Linalg->LLVM-MLIR lowering, then + LLVM `llc`), built against prebuilt riscv64 LLVM and buddy-mlir toolchains + (no from-source LLVM build). The wheel bundles those toolchains' `opt`, + `llc`, and `buddy-*` binaries alongside Triton itself, hence the compound + license: MIT (triton, triton-shared), Apache-2.0 WITH LLVM-exception (LLVM), + Apache-2.0 (buddy-mlir). +versions: +- version: 3.9.0 + files: + - python: '3.12-abi3:manylinux' From 4ff6e51b41b58a460440b408569d99b7bc0c68b8 Mon Sep 17 00:00:00 2001 From: Ludovic Henry Date: Mon, 16 Nov 2026 20:12:56 +0000 Subject: [PATCH 2/6] build-triton: fix torch install env var for Test wheel step uv pip install only honors UV_* env vars, never PIP_* - PIP_EXTRA_INDEX_URL silently no-ops, so uv only ever saw public PyPI (no riscv64 torch there) and never consulted this registry at all (gotcha 244). Confirmed from this PR's own CI run 43873735422/job 133321388047: the wheel build itself succeeded, only the torch install in the test step failed, with uv's error citing only PyPI's own non-riscv64 torch releases. Rename to UV_EXTRA_INDEX_URL and add UV_INDEX_STRATEGY: unsafe-best-match so uv actually queries this registry and picks its riscv64 wheel over PyPI's incompatible ones, matching the pattern used by ~90 other build-*.yml workflows in this repo. --- .github/workflows/build-triton.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build-triton.yml b/.github/workflows/build-triton.yml index e65ba5c05e3..86ed4fb841e 100644 --- a/.github/workflows/build-triton.yml +++ b/.github/workflows/build-triton.yml @@ -125,7 +125,12 @@ jobs: - name: Test triton wheel env: - PIP_EXTRA_INDEX_URL: https://pypi.riseproject.dev/simple/ + # `uv pip install` only reads `UV_*` env vars, never `PIP_*` - a plain + # PIP_EXTRA_INDEX_URL here silently no-ops, so uv only ever sees public + # PyPI (no riscv64 torch there) and nothing in this registry at all + # (CLAUDE.md gotcha 244). + UV_EXTRA_INDEX_URL: https://pypi.riseproject.dev/simple/ + UV_INDEX_STRATEGY: unsafe-best-match run: | # torch is this registry's own riscv64 CPU build (docs/packages/torch.yaml); # Triton's kernel launch path expects torch tensors, and installing it from From ce1ec4d2d1a9043feac5a06494226b0e6ecb0355 Mon Sep 17 00:00:00 2001 From: Ludovic Henry Date: Tue, 17 Nov 2026 02:42:19 +0000 Subject: [PATCH 3/6] build-triton: raise build job timeout to 600 minutes Real riscv64 CI: the first successful build of this PR (run 43873735422) took the whole wheel-build step close to 7h end to end. A rerun of the exact same commit (run 43947463976) hit the previous 360-minute (6h) cap, cancelled mid-build - pip's own 'Building editable for triton: still running...' heartbeat printed continuously right up to the timeout, so the build was never hung, just genuinely this slow (and apparently somewhat variable) on this hardware. The original 360 was a guess from upstream's x86_64 CI timing, not this fleet's own riscv64 numbers. 600 gives real headroom above the observed ~7h without masking an actual hang, which would still show up as a timeout well past that. --- .github/workflows/build-triton.yml | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build-triton.yml b/.github/workflows/build-triton.yml index 86ed4fb841e..e5ce930ed58 100644 --- a/.github/workflows/build-triton.yml +++ b/.github/workflows/build-triton.yml @@ -73,10 +73,13 @@ jobs: version: ${{ fromJSON(needs.setup.outputs.versions) }} name: Build triton ${{ matrix.version }} cp312-abi3-manylinux_riscv64 runs-on: ubuntu-24.04-riscv - # A full Triton + triton-shared C++ build (plus the one-time LLVM/buddy-mlir - # toolchain download) comfortably clears an hour; leave generous headroom - # rather than guess from upstream's own x86_64 CI timing. - timeout-minutes: 360 + # Real riscv64 CI evidence (this PR's own two runs): the first successful + # build took ~7h end to end; a rerun of the exact same build hit the 360 + # (6h) cap this comment originally guessed from upstream's x86_64 CI + # timing, with pip's own "Building editable for triton: still running..." + # heartbeat printing continuously right up to the timeout - the build was + # never hung, just genuinely this slow (and variable) on this hardware. + timeout-minutes: 600 env: TRITON_VERSION: ${{ matrix.version }} From 3bc203ef3d48db67408cdc4c8adcb18e446e9084 Mon Sep 17 00:00:00 2001 From: Ludovic Henry Date: Tue, 17 Nov 2026 13:29:54 +0000 Subject: [PATCH 4/6] build-triton: write the kernel test to a real .py file, not python3 -c Real riscv64 CI (run 44039510021, job 133890584028): the actual build succeeded and torch+triton installed fine, but the smoke test crashed with ValueError: '@jit functions should be defined in a Python file'. triton.jit's JITFunction.__init__ calls inspect.getsourcelines(fn) to grab the decorated function's source, which raises OSError('could not get source code') for anything defined via python3 -c - there is no real file on disk for inspect to read lines from. This has nothing to do with riscv64; the same script would fail identically on any platform, it just never ran far enough to hit this until the earlier UV_EXTRA_INDEX_URL and 600-minute-timeout fixes landed. Write the kernel to test_triton_kernel.py via a heredoc and run that file directly instead. --- .github/workflows/build-triton.yml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-triton.yml b/.github/workflows/build-triton.yml index e5ce930ed58..328c4ae01d0 100644 --- a/.github/workflows/build-triton.yml +++ b/.github/workflows/build-triton.yml @@ -142,7 +142,12 @@ jobs: # entirely within this repo's normal wheel supply. uv pip install --only-binary=:all: torch uv pip install triton-riscv/build/release/riscv64/cp312-cp312/*.whl - python3 -c " + # @triton.jit needs inspect.getsourcelines() to find the decorated + # function's real source, which fails for code handed to `python3 + # -c` (there is no file to read lines from) - write a real .py file + # instead (unrelated to riscv64; this would fail identically on + # any platform). + cat > test_triton_kernel.py <<'EOF' import torch import triton import triton.language as tl @@ -166,7 +171,8 @@ jobs: assert torch.allclose(out, expected), (out, expected) print('triton riscv64/triton_shared kernel OK, max abs diff', (out - expected).abs().max().item()) - " + EOF + python3 test_triton_kernel.py publish: name: Publish triton ${{ matrix.version }} From f49132d87176a66b8ff6db8046e9fb37dcbfa754 Mon Sep 17 00:00:00 2001 From: Ludovic Henry Date: Tue, 17 Nov 2026 19:22:47 +0000 Subject: [PATCH 5/6] build-triton: point LLVM_BINARY_DIR at the unpacked toolchain for mlir-translate Real riscv64 CI (run 44093346560, job 134074094167): the kernel test now actually compiles (the earlier real-file fix held) and fails further in, inside triton_shared's own backend: RuntimeError: Unable to locate LLVM tool 'mlir-translate' via LLVM_BINARY_DIR, the bundled package bin/, or PATH. Confirmed against the real triton-riscv source (backend/paths.py's _get_llvm_bin_path, backend/compiler.py's two mlir-translate call sites, and scripts/release.sh's own packaging loop): release.sh copies opt, buddy-llc, llvm-objdump, llvm-readobj, buddy-opt and buddy-translate into the wheel's backend/bin/, but never mlir-translate, so neither the bundled-copy nor the PATH fallback in paths.py ever finds it. scripts/setup.sh's download_release() unpacks the real LLVM release tarball (which does ship mlir-translate) under triton-riscv/.cache/llvm, and release.sh's own docker invocation bind-mounts the checkout into the container rather than copying it in, so that directory is still present on the runner's filesystem here, in the step right after the build step's container has already exited. Point LLVM_BINARY_DIR (paths.py's first-checked resolution path) at it directly, rather than patching upstream's packaging list. --- .github/workflows/build-triton.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/.github/workflows/build-triton.yml b/.github/workflows/build-triton.yml index 328c4ae01d0..7f9a2361a3e 100644 --- a/.github/workflows/build-triton.yml +++ b/.github/workflows/build-triton.yml @@ -134,6 +134,18 @@ jobs: # (CLAUDE.md gotcha 244). UV_EXTRA_INDEX_URL: https://pypi.riseproject.dev/simple/ UV_INDEX_STRATEGY: unsafe-best-match + # The wheel's own backend/paths.py looks up mlir-translate via + # LLVM_BINARY_DIR, a bundled backend/bin/ copy, or PATH - but + # release.sh's own packaging loop only copies opt/buddy-llc/ + # llvm-objdump/llvm-readobj/buddy-opt/buddy-translate into the + # wheel, never mlir-translate, so the bundled-copy and PATH + # fallbacks both come up empty. setup.sh's download_release() + # unpacks the real LLVM toolchain (which does have mlir-translate) + # under triton-riscv/.cache/llvm, and because release.sh's docker + # run bind-mounts the checkout rather than copying it in, that + # directory is still on the runner's filesystem here, outside the + # now-exited container. + LLVM_BINARY_DIR: ${{ github.workspace }}/triton-riscv/.cache/llvm/bin run: | # torch is this registry's own riscv64 CPU build (docs/packages/torch.yaml); # Triton's kernel launch path expects torch tensors, and installing it from From e727e88b811ba301caec20187e6355aded78bc8f Mon Sep 17 00:00:00 2001 From: Ludovic Henry Date: Wed, 18 Nov 2026 00:17:03 +0000 Subject: [PATCH 6/6] build-triton: cap build parallelism to avoid the OOM kill Real riscv64 CI (run 44157994959, job 134304033843): the 'Building editable for triton' step ran for ~1h40m then died with exit code 137 (SIGKILL) and no other error text - gotcha 421's signature on this fleet's low-RAM, no-swap riscv64 runners, exactly as this step's own prior comment anticipated. release.sh's own docker-run wrap forwards no MAX_JOBS/ CMAKE_BUILD_PARALLEL_LEVEL into the container, so there is no env var on the host side that reaches the actual ninja/make invocation deep inside triton's own build. release.sh already supports being invoked with IN_DOCKER pre-set (it then skips its own docker-run wrapping entirely), so this reproduces its exact documented riscv64 container invocation itself, adding only --cpuset-cpus to halve the visible core count - nproc and hardware_concurrency() respect cpuset affinity but not a cgroup CPU quota, so --cpus alone would not actually have reduced the inferred build parallelism. --- .github/workflows/build-triton.yml | 48 ++++++++++++++++++++++++------ 1 file changed, 39 insertions(+), 9 deletions(-) diff --git a/.github/workflows/build-triton.yml b/.github/workflows/build-triton.yml index 7f9a2361a3e..928eb44a2f1 100644 --- a/.github/workflows/build-triton.yml +++ b/.github/workflows/build-triton.yml @@ -101,16 +101,46 @@ jobs: # clones triton-lang/triton and Triton's own cmake clones googletest. GITHUB_TOKEN: ${{ github.token }} run: | - # release.sh docker-runs quay.io/pypa/manylinux_2_39_riscv64 itself when - # IN_DOCKER is unset, so nothing here needs to set up that container. + # Real riscv64 CI (run 44157994959, job 134304033843): the previous + # plain `./scripts/release.sh cp312-cp312 riscv64` invocation let + # release.sh's own docker-run wrap the build in a fresh container + # with no concurrency cap, and the "Building editable for triton" + # step was silently SIGKILLed (exit 137) after ~1h40m with no other + # error text - gotcha 421's signature (this fleet's riscv64 runners + # have ~15GB RAM and no usable swap, and release.sh's own docker-run + # forwards no MAX_JOBS/CMAKE_BUILD_PARALLEL_LEVEL into the container + # the way their own ci.yml sets on the host). # - # NB: if this OOMs, it's the same root cause as gotcha 421 (this - # fleet's riscv64 runners have ~15GB RAM and no usable swap) - - # release.sh's docker run does not forward MAX_JOBS/ - # CMAKE_BUILD_PARALLEL_LEVEL into the container the way their own - # ci.yml sets them on the host, so a fix would need to cap - # concurrency inside the container rather than in this step's env. - ./scripts/release.sh cp312-cp312 riscv64 + # release.sh already supports being invoked with IN_DOCKER pre-set + # (it then skips its own docker-run wrapping entirely and proceeds + # straight to the build), so this reproduces its exact documented + # riscv64 container invocation (same image, same volumes, same env + # vars - see the `if [ -z "${IN_DOCKER:-}" ]` branch in + # scripts/release.sh) with one addition: --cpuset-cpus, to restrict + # the affinity mask ninja/make read when picking their default -j, + # since nproc/hardware_concurrency() respect cpuset affinity but not + # a cgroup CPU quota (--cpus alone would not actually reduce the + # inferred build parallelism). Halving the visible cores (floor 2) + # is a cap, not a tune - the exact number matters far less than + # having one at all. + total_cpus="$(nproc)" + half_cpus="$(( total_cpus / 2 ))" + [ "${half_cpus}" -lt 2 ] && half_cpus=2 + [ "${half_cpus}" -gt "${total_cpus}" ] && half_cpus="${total_cpus}" + docker run --rm -i --cpuset-cpus="0-$((half_cpus - 1))" \ + -e IN_DOCKER=1 \ + -e PY_TAG=cp312-cp312 \ + -e TARGET_ARCH=riscv64 \ + -e HOST_UID="$(id -u)" \ + -e HOST_GID="$(id -g)" \ + -e HOME=/workspace \ + -e GITHUB_TOKEN \ + -v "$(pwd):/workspace/triton-riscv" \ + -v /tmp/triton_riscv_docker_dnf_cache:/var/cache/dnf \ + -v /tmp/triton_riscv_docker_pip_cache:/workspace/.cache/pip \ + -w /workspace/triton-riscv \ + quay.io/pypa/manylinux_2_39_riscv64:latest \ + /bin/bash ./scripts/release.sh cp312-cp312 riscv64 ls -la build/release/riscv64/cp312-cp312/ - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1