Skip to main content

Module gpu

Module gpu 

Source
Expand description

GPU acceleration foundation for spintronics (v0.9.0).

This module provides a Device trait abstraction that lets the same LLG simulation code run on CPU or GPU backends. v0.9.0 ships:

  • CpuDevice — always available, drop-in baseline that reuses the existing crate::dynamics::llg::calc_dm_dt scalar path
  • [CudaDevice] (feature = cuda) — stub that constructs successfully but reports is_available() == false and returns crate::error::Error::NumericalError on every operation. v1.0.0 will wire this to a real CUDA backend (planned: cudarc + PTX kernels) without breaking existing call sites.

The intent is to establish the type signatures and contracts now so that the v1.0.0 CUDA implementation can land as a drop-in replacement.

§Design intent

Operations work on flat &mut [[f64; 3]] arrays (per-spin x, y, z) for FFI-friendliness and zero-copy compatibility with future GPU memory buffers. Implementations decide whether to copy data to GPU and back per call, batch operations, or maintain persistent device buffers.

The Device trait is intentionally object-safe so users can store Box<dyn Device> and switch backends at runtime via select_best_device.

§Example

use spintronics::gpu::{CpuDevice, Device};

let device = CpuDevice::new();
let mut spins = vec![[1.0_f64, 0.0, 0.0], [0.0, 1.0, 0.0]];
let h_eff = vec![[0.0_f64, 0.0, 1.0e5]; 2];
device.step_llg_rk4(&mut spins, &h_eff, 0.01, 1.0e-13).unwrap();

§References

  • A. Vansteenkiste, J. Leliaert, M. Dvornik, M. Helsen, F. Garcia-Sanchez, and B. Van Waeyenberge, “The design and verification of MuMax3”, AIP Advances 4, 107133 (2014).
  • MuMAX³ Pro — GPU-accelerated micromagnetics framework (reference design for batched LLG kernels).

Re-exports§

pub use cpu::CpuDevice;

Modules§

cpu
CPU implementation of the Device trait.

Traits§

Device
Device abstraction for LLG simulation on CPU or GPU backends.

Functions§

available_devices
Enumerate all devices that the current build can construct.
select_best_device
Select the best available device.