Skip to main content

SLiM-CUDA

PyPI Downloads

SLiM-CUDA is a backend collection for large-scale hologram generation and wavefront synthesis, designed for high-performance spatial light modulator (SLM) workflows.

The package contains CUDA, Apple MLX/Metal, and NumPy CPU fallback backends under one slimcuda namespace. The CUDA and MLX backends are intentionally independent because they target machines that normally cannot share the same accelerator stack.


Features

  • CUDA-accelerated weighted Gerchberg–Saxton (WGS)–style solvers
  • MLX/Metal backend for Apple Silicon using the original _og math path
  • NumPy CPU backend for RS-only fallback and oracle testing
  • Designed for large multi-focus hologram synthesis
  • Backend-specific optional dependencies
  • Drop-in CUDA upgrade path for optimized kernels (no API changes)

Installation

pip install slimcuda

The base install is CPU-safe and only installs shared Python code plus NumPy. Select the accelerator backend explicitly:

# CUDA machines
pip install "slimcuda[cuda]"

# Apple Silicon / Metal machines
pip install "slimcuda[mlx]"

# Let packaging markers choose CUDA on non-macOS and MLX on Apple Silicon
pip install "slimcuda[auto]"

# CPU oracle plus optional simulation plotting
pip install "slimcuda[cpu]"

Canonical dispatching import:

from slimcuda import SlimCuda

slm = SlimCuda()                            # CUDA + OpenGL render, legacy default
slm = SlimCuda(backend="cuda", render=False)
slm = SlimCuda(backend="mlx", render=False)
slm = SlimCuda(backend="cpu", render=False)

Direct backend imports remain available:

from slimcuda import SlimCudaGl, SlimCuda_base        # CUDA backend
from slimcuda import SlimCudaMlx, SlimCudaMlx_base    # MLX backend
from slimcuda import SlimCudaCpu, SlimCudaCpu_base    # NumPy fallback

Backend and render-environment diagnosis is available through the tester:

python slimcuda_tester.py --backend auto --diagnose-only
python slimcuda_tester.py --backend auto --render --diagnose-only

SlimCudaCpu_base implements RS methods only. WGS is intentionally not implemented on CPU because it is not practically useful at full SLM scale.

Kernel Architecture & Performance Model

Public CUDA kernel set

The PyPI wheel ships with CUDA source and public PTX assets, but CUDA runtime dependencies are installed only through the cuda or auto extras.

The public CUDA kernel set includes:

  • slimcuda_og.ptx
  • Corresponding CUDA source (.cu, .cuh) files

This build prioritizes:

  • Broad GPU compatibility
  • Reproducibility
  • Ease of installation

⚠️ Performance note

The PTX kernels are not performance-optimized for modern GPUs. They exist to ensure correctness and portability.

Optimized builds (collaborators)

Highly optimized, GPU-specific kernels are distributed as fatbin / cubin binaries and are not included in the public wheel.

If an optimized kernel is present locally, SLiM-CUDA will automatically detect and load it.

Benefits:

  • Substantially higher throughput
  • Reduced launch overhead
  • Architecture-specific tuning

If you are a collaborator or have a supported GPU and need optimized kernels, please contact the author.

Runtime Banner

SLiM-CUDA runtime banners have two layers:

  • a loaded-backend indicator, for example [SLiM-CUDA] Loaded legacy PTX kernels ...
  • an optional explanatory note for non-fatbin backends such as public PTX, MLX/Metal, or NumPy CPU

The optimized fatbin path only prints the loaded-backend indicator. Non-fatbin backends also print a short performance note by default; hide that note with:

# Linux / macOS
export SLIMCUDA_BANNER=0

# Windows (PowerShell)
setx SLIMCUDA_BANNER 0

To silence both layers programmatically, pass show_banner=False to the backend constructor/factory.

GPU Compatibility

  • Public PTX kernels: should run on most CUDA-capable GPUs
  • Optimized kernels: GPU- and build-specific

If you have an optimized kernel but encounter issues on your GPU, please contact the author for a tailored build.

License

  • Python code: MIT License
  • Public CUDA source (PTX / .cu): MIT License
  • Optimized CUDA binaries: distributed separately under collaborator-specific terms

Citation

If you use SLiM-CUDA in academic work, please cite the following:

SLiM-CUDA was originally developed to support the methodology described in:

Z. Qu et al., Deep-learning-aided multi-focal hologram generation, Optics & Laser Technology, 2025. DOI: 10.1016/j.optlastec.2024.112056

@article{jwangSlimCuda,
  title   = {Deep-learning-aided multi-focal hologram generation},
  author  = {Qu, Z. and others},
  journal = {Optics & Laser Technology},
  year    = {2025},
  doi     = {10.1016/j.optlastec.2024.112056}
}

If your work builds upon or uses the algorithms and concepts enabled by SLiM-CUDA,
please cite this publication.

Software citation

If you prefer to cite the software directly (e.g. for tooling or infrastructure use), you may cite:

SLiM-CUDA: GPU-accelerated hologram generation backend.
https://pypi.org/project/slimcuda/

A formal software citation entry (BibTeX) will be provided in a future release.

Disclaimer

This software is intended for research and advanced technical use.

API stability is maintained, but internal kernel implementations may evolve.

Metadata

Release files for slimcuda 0.9.4.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for slimcuda 0.9.4.2
File Size Uploaded
slimcuda-0.9.4.2.tar.gz 48.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for slimcuda 0.9.4.2
File Interpreter ABI Platform
slimcuda-0.9.4.2-py3-none-any.whl Python 3 none any Details

Total release size: 97.5 kB

Release files / slimcuda-0.9.4.2.tar.gz

Download URL slimcuda-0.9.4.2.tar.gz
Size 48.2 kB
Tags Source
SHA-256 checksum
How to use checksums
137726e79f79564430591acca8399393a3df82608141fa099deb855d82519cc4
BLAKE2b-256 checksum
How to use checksums
7a2534731a2d8342ae8caf570a2451176b161e636f12e770c5565fb2c51ad95f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.5

Release files / slimcuda-0.9.4.2-py3-none-any.whl

Download URL slimcuda-0.9.4.2-py3-none-any.whl
Size 49.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
df840191f610d46b9a52eb92448e78a8479bc6693d9d2ac1523d4f874f619b21
BLAKE2b-256 checksum
How to use checksums
9a1c1c0ff9f648e2044da4a79ef2d8afe17c45f507343e332ea723f6acc42bea
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.5

Release history Release notifications | RSS feed

This release

0.9.4.2 This release

2 release files

0.9.4

2 release files

0.9.3

2 release files

0.7.5

2 release files

0.7.4

2 release files

0.7.1

2 release files

0.7.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page