Files
Misaki.HighPerformance/Misaki.HighPerformance.Mathematics.SPMD/README.md
Misaki eb01e557d5 Relax SPMD job constraints, improve safety and docs
Removed unmanaged struct requirement from SPMD job wrappers and extension methods, allowing managed types. Updated all wrappers and extension methods to require only the interface constraint. Refactored SPMD test jobs to use safe ref-based Store overloads. Improved README and docs with clearer debug/mimalloc instructions and a better SPMD example. Cleaned up Program.cs by removing obsolete experimental code. Enhanced math precision in GGXMipGenerationBenchmark. Updated T4 template to generate new constraints and APIs.
2026-05-01 12:39:37 +09:00

67 lines
2.0 KiB
Markdown

# Misaki.HighPerformance.Mathematics.SPMD
SPMD-oriented math abstractions built on top of the mathematics layer.
This package is intended for code that wants to express vectorized work in a way that is portable across lane widths and easier to reason about than raw intrinsics alone.
## What it includes
- SPMD lane interfaces
- scalar and wide lane abstractions
- vector template helpers
- shuffle table generation support
- job-oriented SPMD helpers
## Highlights
- abstracts lane width through a common interface
- supports sequence creation, load/store, and compress-store style workflows
- built for vectorized algorithms and data-parallel execution
- useful when you need explicit lane semantics rather than ad hoc SIMD code
## Main types
- `ISPMDLane`
- `ISPMDLane<TSelf, TNumber>`
- `ScalerLane`
- `WideLane`
- `IJobSPMD`
- `Vector{T}Helper`
## Example
```csharp
public struct Vector2LerpJob : IJobSPMD<float>
{
public float2[] arrayA;
public float2[] arrayB;
public float[] results;
public readonly void Execute<TLane>(int baseIndex, ref readonly JobExecutionContext ctx)
where TLane : unmanaged, ISPMDLane<TLane, float>
{
var a = MathV.LoadVector2<TLane, float>(ref arrayA[baseIndex].x);
var b = MathV.LoadVector2<TLane, float>(ref arrayB[baseIndex].x);
var t = TLane.Create(0.5f);
var lerped = MathV.Lerp(a, b, t);
var len = TLane.Sqrt(MathV.LengthSquared(lerped));
len.Store(ref results[baseIndex]);
}
}
```
You can visit `GGXMipGenerationBenchmark.cs` for a more complete example of how to use the SPMD abstractions in a real algorithm.
## Package reference
```bash
dotnet add package Misaki.HighPerformance.Mathematics.SPMD
```
## Notes
This project targets `net10.0` and depends on the mathematics project for shared numeric concepts.
You can enable `MHP_FASTMATH` to allow the use of faster math intrinsics where appropriate, but be aware that this may lead to less precise results in some cases.