Skip to content

Commit 038557e

Browse files
larsgebclaude
andcommitted
CI: replace skip with size override, add Ruff+Ty quality gate
- test_01_adder: define METAL_ADDER_ARRAY_LENGTH=10000 so the test runs on the paravirtual CI GPU instead of being skipped; remove SKIP_RETURN_CODE 77 - MetalAdder.hpp: preprocessor guard so the example binary keeps the original 108 M element size while the test uses a small override - Smoke test: add numerical assertions for add_arrays, saxpy, and laplacian2d (flat field → zero interior); existing shape checks retained - Add python-quality CI job (ubuntu-latest): ruff check, ruff format --check, ty check — all powered by uvx, no separate install step - python/_m1_gpu_ops.pyi: full type stubs for the pybind11 extension - python/py.typed: PEP 561 marker - pyproject.toml: [tool.ruff] + [tool.ty] configuration - python/__init__.py: sort imports to satisfy isort (ruff I001) - demo.py, wave_demo.py: apply ruff format Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent b5e309b commit 038557e

10 files changed

Lines changed: 473 additions & 174 deletions

File tree

.github/workflows/ci.yml

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,24 @@ jobs:
3939
- name: Test (GPU)
4040
run: cmake --build build --target test -- ARGS="--output-on-failure"
4141

42+
python-quality:
43+
name: Python quality (Ruff + Ty)
44+
# Runs on a plain Linux runner — no Metal device needed.
45+
runs-on: ubuntu-latest
46+
47+
steps:
48+
- uses: actions/checkout@v4
49+
- uses: astral-sh/setup-uv@v5
50+
51+
- name: Ruff lint
52+
run: uvx ruff check python/ demo.py wave_demo.py
53+
54+
- name: Ruff format check
55+
run: uvx ruff format --check python/ demo.py wave_demo.py
56+
57+
- name: Ty type check
58+
run: uvx ty check python/
59+
4260
python-bindings:
4361
name: Python bindings smoke test (Apple Silicon, Metal)
4462
runs-on: macos-14
@@ -82,16 +100,19 @@ jobs:
82100
ctx.load_library("build/04-Compute/ops.metallib")
83101
ctx.load_library("build/05-WavePropagation/ops.metallib")
84102
85-
# 1D ops
103+
# 1D ops — verify values, not just shapes
86104
x = np.ones(1024, dtype=np.float32)
87105
y = np.ones(1024, dtype=np.float32) * 2
88-
assert np.allclose(metal.add_arrays(ctx, x, y), 3), "add_arrays failed"
89-
assert np.allclose(metal.saxpy(ctx, 2.0, x, y), 4), "saxpy failed"
106+
assert np.allclose(metal.add_arrays(ctx, x, y), 3.0), "add_arrays wrong values"
107+
assert np.allclose(metal.saxpy(ctx, 2.0, x, y), 4.0), "saxpy wrong values"
90108
91-
# 2D Laplacian
109+
# 2D Laplacian — shape + numerical correctness (flat field → zero interior)
92110
u = np.random.rand(64, 64).astype(np.float32)
93111
lap = metal.laplacian2d(ctx, u)
94112
assert lap.shape == (64, 64), "laplacian2d shape wrong"
113+
flat = np.ones((64, 64), dtype=np.float32)
114+
lap_flat = metal.laplacian2d(ctx, flat)
115+
assert np.allclose(lap_flat[1:-1, 1:-1], 0.0, atol=1e-5), "laplacian2d nonzero on flat field"
95116
96117
# Mandelbrot — signature: (ctx, width, height, x_min, x_max, y_min, y_max, max_iter)
97118
img = metal.mandelbrot(ctx, 128, 128, -2.0, 1.0, -1.5, 1.5, 256)

01-MetalAdder/MetalAdder.hpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,13 @@ A class to manage all of the Metal objects this app creates.
1313
#include "Metal/Metal.hpp"
1414

1515
// The number of floats in each array, and the size of the arrays in bytes.
16-
const unsigned int arrayLength = 60 * 180 * 10000;
16+
// The test binary overrides this via -DMETAL_ADDER_ARRAY_LENGTH=N so it can
17+
// run a small dispatch that completes on the CI paravirtual GPU.
18+
#ifndef METAL_ADDER_ARRAY_LENGTH
19+
const unsigned int arrayLength = 60 * 180 * 10000; // original Apple sample size
20+
#else
21+
const unsigned int arrayLength = METAL_ADDER_ARRAY_LENGTH;
22+
#endif
1723

1824
const unsigned int bufferSize = arrayLength * sizeof(float);
1925

CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,6 @@ set_target_properties(test_01_adder PROPERTIES
204204
add_test(NAME test_01_adder COMMAND test_01_adder
205205
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/01-MetalAdder"
206206
)
207-
# Exit code 77 means "skip" — used when the device is paravirtual (CI VM).
208-
set_tests_properties(test_01_adder PROPERTIES SKIP_RETURN_CODE 77)
209207

210208
add_executable(test_02_1d_ops
211209
tests/test_02_1d_ops.cpp

0 commit comments

Comments
 (0)