Skip to content

perf: vectorize CPU bottlenecks with vDSP and cblas - #11

Closed
alvgeppetto wants to merge 1 commit into
maderix:mainfrom
alvgeppetto:perf/cpu-vectorization
Closed

perf: vectorize CPU bottlenecks with vDSP and cblas#11
alvgeppetto wants to merge 1 commit into
maderix:mainfrom
alvgeppetto:perf/cpu-vectorization

Conversation

@alvgeppetto

Copy link
Copy Markdown

Vectorize CPU bottlenecks in the training loop using Accelerate framework.

Changes:

  • Adam optimizer vectorized with vDSP batch ops (vDSP_vsmul, vsma, vsq, vdiv, vvsqrtf, vsadd) in both backward.h and stories_cpu_ops.h
  • dW accumulation replaced with cblas_sgemm (CblasRowMajor, CblasTrans, CblasNoTrans) in backward.h
  • dx backward pass replaced with cblas_sgemm in backward.h
  • Added -framework Accelerate to train target in Makefile (was only on train_large)

Both make train and make train_large compile cleanly on macOS.

- Vectorize adam_update with vDSP batch ops (stories_cpu_ops.h)
  Replaces scalar per-element loop with vDSP_vsmul/vsma/vsq/vdiv
  Expected ~3-4x faster for 2.4M parameter updates

- Vectorize model_adam_step ADAM_UPDATE macro with vDSP (backward.h)
  Same batch ops pattern for the train.m model pipeline

- Replace cpu_accum_dW with cblas_sgemm (backward.h)
  dW += dy^T @ x is a standard BLAS GEMM operation
  Expected 5-10x faster for weight gradient accumulation

- Replace cpu_matmul_backward_dx with cblas_sgemm (backward.h)
  dx = dy @ W^T is also a standard BLAS GEMM

- Add -framework Accelerate to train target (Makefile)
@alvgeppetto alvgeppetto closed this Mar 2, 2026
@alvgeppetto
alvgeppetto deleted the perf/cpu-vectorization branch March 2, 2026 22:44
ebowwa pushed a commit to ebowwa/ANE that referenced this pull request Aug 4, 2026
maderix#9 GraphDescriptor: operation entries now include op.args (graph dependencies). Constants use
their BLOBFILE/file attr as digest instead of placeholder "const".
maderix#10 IR pipeline: rejects unparseable MIL at the tensor-IR level (rejected_at_tensor_ir) before
reaching ANE-IR lint — previously reported "validated" for meaningless input.
maderix#11 ExecutionPlan + PlanSegment: frozen=True (immutable as documented). __post_init__ uses
object.__setattr__ for the auto-generated id.
maderix#12 Communication: recv() now verifies consumer_exec_id + checksum before returning data.
maderix#13 Transforms: docstring honestly states these are VariantIntents (metadata), not transformed
graphs — quantize() labels int8, doesn't produce int8 MIL.
maderix#14 Autotuner: select_and_benchmark now passes weights to bridge.bench (previously discarded).
Evidence keyed by real mil-hash fingerprint + shape, not "auto"/"default". All-failed case
returns best_variant=None instead of picking an infinite-latency variant.

bridge.bench now accepts a weights param (for constant-weight autotuning).
138 tests.

Co-Authored-By: Claude <noreply@anthropic.com>
ebowwa pushed a commit to ebowwa/ANE that referenced this pull request Aug 4, 2026
…, capability-aware tests, byte-bounded retention, artifact manifests

maderix#5 MLX backend: load() now stores the operation spec (executable_id → spec dict). execute()
uses the stored spec, not the input's layout field. Respects per-input dtype/shape/byte_offset
(no longer assumes contiguous fp16). Produces correct output descriptors with actual output
shape (no longer reuses input descriptor).

maderix#9 Capability-aware tests: MLX tests skip when mlx unavailable or on non-Darwin-arm64
platforms. TestClient-based tests don't assert MLX availability universally.

maderix#10 Byte-bounded submissions: SubmissionRegistry now has max_result_bytes (256 MiB default).
_prune() evicts terminal submissions by total result byte size, not just count.

maderix#11 Artifact manifests: LocalArtifactBackend.put_artifact() stores each file as a tensor +
a manifest linking all files. resolve_artifact() returns the full manifest. Multi-file
artifacts (compiled ANE programs with multiple BLOBFILEs) can now be reconstructed.

149 tests.

Co-Authored-By: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant