mojo-simd-optimize

Apply SIMD optimizations to Mojo code for parallel computation. Use when optimizing performance-critical tensor and array operations.

⭐5stars🔀1forks📁View on GitHub🕐Updated Jan 11, 2026

When & Why to Use This Skill

This Claude skill automates the application of SIMD (Single Instruction, Multiple Data) optimizations to Mojo code, enabling high-performance parallel computation. It streamlines the process of vectorizing tensor and array operations, ensuring efficient hardware utilization and significant speedups (typically 4x-8x) for compute-intensive tasks by handling complex logic like SIMD width calculation and remainder processing.

Use Cases

  • Accelerating tensor operations and mathematical kernels in machine learning frameworks built with Mojo.
  • Vectorizing element-wise computations in large-scale data processing pipelines to reduce latency and CPU overhead.
  • Optimizing performance-critical loops with over 1000 elements by implementing hardware-aware SIMD width calculations.
  • Refactoring scalar Mojo code into parallelized versions while ensuring memory safety and correct handling of remainder elements.
namemojo-simd-optimize
description"Apply SIMD optimizations to Mojo code for parallel computation. Use when optimizing performance-critical tensor and array operations."
mcp_fallbacknone
categorymojo

SIMD Optimization Skill

Parallelize tensor and array operations using SIMD.

When to Use

  • Optimizing tensor operations
  • Vectorizing element-wise computations
  • Performance-critical loops (>1000 elements)
  • Benchmark results show optimization potential

Quick Reference

from sys.info import simdwidthof

comptime width = simdwidthof[DType.float32]()

# SIMD vector add
for i in range(0, size, width):
    result.store(i, a.load[width](i) + b.load[width](i))

Workflow

  1. Identify bottleneck - Profile code to find hot loops
  2. Get SIMD width - Use simdwidthof[dtype]()
  3. Vectorize loop - Process width elements per iteration
  4. Handle remainder - Process leftover elements
  5. Benchmark - Verify performance improvement (4x-8x expected)

Mojo-Specific Notes

  • SIMD width varies by CPU and dtype (usually 8-16 for float32)
  • Always handle remainder elements with scalar loop
  • Prefer alias for compile-time SIMD width constants
  • Test on target hardware - SIMD width is platform-specific

Error Handling

Error Cause Solution
Out of bounds Remainder not handled Add scalar remainder loop
No speedup Wrong SIMD width Use simdwidthof[dtype]()
Compilation fails Type mismatch Check load/store types match
Segfault Misaligned access Ensure stride is correct

References

  • .claude/shared/mojo-guidelines.md - SIMD patterns section
  • Mojo manual: SIMD documentation