From 316607f004ba5fe6bb2c0a4032ef3f9dc0b23f9f Mon Sep 17 00:00:00 2001 From: Christopher Milan Date: Tue, 12 May 2026 14:11:03 -0700 Subject: [PATCH] dsp: don't use docker in ci (#16167) * dsp: don't use docker in ci * add setup script for macos docker --- .github/actions/setup-tinygrad/action.yml | 18 +++++++++++++----- .github/workflows/test.yml | 12 +----------- extra/setup_mock_dsp_osx.sh | 16 ++++++++++++++++ tinygrad/runtime/ops_dsp.py | 4 +--- 4 files changed, 31 insertions(+), 19 deletions(-) create mode 100755 extra/setup_mock_dsp_osx.sh diff --git a/.github/actions/setup-tinygrad/action.yml b/.github/actions/setup-tinygrad/action.yml index 5b86080f37..df2095c40c 100644 --- a/.github/actions/setup-tinygrad/action.yml +++ b/.github/actions/setup-tinygrad/action.yml @@ -49,6 +49,10 @@ inputs: description: "Install tinydreno" required: false default: 'false' + qemu: + description: "Install qemu" + required: false + default: 'false' runs: using: "composite" steps: @@ -129,7 +133,7 @@ runs: # ******************* apt ******************* - name: Setup apt - if: runner.os == 'Linux' && (inputs.opencl == 'true' || inputs.amd == 'true' || inputs.cuda == 'true' || inputs.webgpu == 'true' || inputs.llvm == 'true') + if: runner.os == 'Linux' && (inputs.opencl == 'true' || inputs.amd == 'true' || inputs.cuda == 'true' || inputs.webgpu == 'true' || inputs.llvm == 'true' || inputs.qemu == 'true') shell: bash run: | sudo chown -R $USER:$USER /var/cache/apt/archives @@ -161,7 +165,7 @@ runs: echo "deb http://apt.llvm.org/$(lsb_release -cs)/ llvm-toolchain-$(lsb_release -cs)-20 main" | sudo tee /etc/apt/sources.list.d/llvm.list - name: Compute Package List + Hash - if: runner.os == 'Linux' && (inputs.opencl == 'true' || inputs.amd == 'true' || inputs.cuda == 'true' || inputs.webgpu == 'true' || inputs.llvm == 'true') + if: runner.os == 'Linux' && (inputs.opencl == 'true' || inputs.amd == 'true' || inputs.cuda == 'true' || inputs.webgpu == 'true' || inputs.llvm == 'true' || inputs.qemu == 'true') id: apt-pkgs shell: bash run: | @@ -190,25 +194,29 @@ runs: if [[ "${{ inputs.llvm }}" == "true" ]]; then pkgs+=" libllvm20 clang-20 lld-20" fi + # **** QEMU **** + if [[ "${{ inputs.qemu }}" == "true" ]]; then + pkgs+=" qemu-user-static" + fi echo "pkgs=$pkgs" >> "$GITHUB_OUTPUT" echo "hash=$(echo -n "$pkgs" | sha256sum | cut -d' ' -f1)" >> "$GITHUB_OUTPUT" - name: Cache apt (PR) - if: runner.os == 'Linux' && (inputs.opencl == 'true' || inputs.amd == 'true' || inputs.cuda == 'true' || inputs.webgpu == 'true' || inputs.llvm == 'true') && github.event_name == 'pull_request' + if: runner.os == 'Linux' && (inputs.opencl == 'true' || inputs.amd == 'true' || inputs.cuda == 'true' || inputs.webgpu == 'true' || inputs.llvm == 'true' || inputs.qemu == 'true') && github.event_name == 'pull_request' uses: actions/cache/restore@v4 with: path: /var/cache/apt/archives/ key: ${{ runner.os }}-${{ runner.arch }}-apt-${{ steps.apt-pkgs.outputs.hash }}-${{ env.CACHE_VERSION }} - name: Cache apt - if: runner.os == 'Linux' && (inputs.opencl == 'true' || inputs.amd == 'true' || inputs.cuda == 'true' || inputs.webgpu == 'true' || inputs.llvm == 'true') && github.event_name != 'pull_request' + if: runner.os == 'Linux' && (inputs.opencl == 'true' || inputs.amd == 'true' || inputs.cuda == 'true' || inputs.webgpu == 'true' || inputs.llvm == 'true' || inputs.qemu == 'true') && github.event_name != 'pull_request' uses: actions/cache@v5 with: path: /var/cache/apt/archives/ key: ${{ runner.os }}-${{ runner.arch }}-apt-${{ steps.apt-pkgs.outputs.hash }}-${{ env.CACHE_VERSION }} - name: Run apt Update + Install - if: runner.os == 'Linux' && (inputs.opencl == 'true' || inputs.amd == 'true' || inputs.cuda == 'true' || inputs.webgpu == 'true' || inputs.llvm == 'true') + if: runner.os == 'Linux' && (inputs.opencl == 'true' || inputs.amd == 'true' || inputs.cuda == 'true' || inputs.webgpu == 'true' || inputs.llvm == 'true' || inputs.qemu == 'true') shell: bash run: | sudo apt -qq update || true diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c0871d1f31..1e11ead9d3 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -594,17 +594,7 @@ jobs: deps: testing_unit pydeps: "onnx==1.18.0 onnxruntime ml_dtypes" llvm: "true" - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v4 - - name: Build QEMU Docker with cache - uses: docker/build-push-action@v7 - with: - file: extra/dsp/Dockerfile - push: false - load: true - tags: qemu-hexagon:latest - cache-from: type=gha - cache-to: ${{ github.event_name != 'pull_request' && 'type=gha,mode=min' || '' }} + qemu: "true" - name: Set MOCKDSP env run: printf "MOCKDSP=1" >> $GITHUB_ENV - name: Run test_tiny on DSP diff --git a/extra/setup_mock_dsp_osx.sh b/extra/setup_mock_dsp_osx.sh new file mode 100755 index 0000000000..0daf1c4b49 --- /dev/null +++ b/extra/setup_mock_dsp_osx.sh @@ -0,0 +1,16 @@ +#!/bin/sh +install_loc="$HOME/.local/bin" +docker build -t qemu-hexagon-static:latest - <<'EOF' +FROM ubuntu:24.04 +RUN apt-get update && apt-get install -y --no-install-recommends qemu-user-static ca-certificates && rm -rf /var/lib/apt/lists/* +EOF + +mkdir -p "$install_loc" +tee "$install_loc/qemu-hexagon-static" >/dev/null <<'EOF' +#!/bin/sh +set -eu +exec docker run --rm -i \ + -v /var/folders:/var/folders -v "$HOME":"$HOME" \ + qemu-hexagon-static:latest qemu-hexagon-static "$@" +EOF +chmod +x "$install_loc/qemu-hexagon-static" diff --git a/tinygrad/runtime/ops_dsp.py b/tinygrad/runtime/ops_dsp.py index 745e4fcc29..70f7b048ae 100644 --- a/tinygrad/runtime/ops_dsp.py +++ b/tinygrad/runtime/ops_dsp.py @@ -297,9 +297,7 @@ class MockDSPProgram: dsp_lib.write(self.lib) dsp_lib.flush() os.chmod(dsp_lib.name, 0o0777) - # NOTE: this timing includes a docker launch - proc = subprocess.run(["docker", "run", "--rm", "-i", "-v", f"{os.path.abspath(os.path.dirname(dsp_lib.name))}:/work", "-w", "/work", - "qemu-hexagon", "-c", f"qemu-hexagon {'-strace' if DEBUG >= 5 else ''} /work/"+os.path.basename(dsp_lib.name)], + proc = subprocess.run(["qemu-hexagon-static", *(['-strace'] if DEBUG >= 5 else []), dsp_lib.name], input=b''.join([bytes(to_mv(x.va_addr, x.size)) for x in bufs] + [struct.pack("I", x) for x in vals]), stdout=subprocess.PIPE, check=True) offset = 4 for x in bufs: