Repository navigation
Module_ComputingContext
Location: Home / ComputingContext module
Lightweight CPU execution policy for choosing scalar, SIMD, or parallel implementations per call or code block without global mutable state. Covers FFT, statistics, linear algebra, batch deep learning, MFCC/audio frontends, and training entry points (see “Integrated APIs” below).
No GPU:
ComputingContextschedules CPU work only (scalar / SIMD / multithreaded). The main package has dropped built-in CUDA/ILGPU; see GPU policy.
Namespace: Vorcyc.Mathematics
| Type | Description |
|---|---|
ComputingContext |
Immutable execution policy (Normal / Simd / Parallel / Auto) |
ComputingScope |
AsyncLocal scope; using (ComputingScope.Enter(ctx)) { ... }
|
CpuExecutionMode |
CPU mode enum |
ComputingContextExecution |
Parallel thresholds and worker-count helpers |
explicit context parameter > ComputingContext.Current (scope) > Default
context: null means “unspecified” and follows the chain above — not forced scalar.
ComputingContext.Normal // scalar
ComputingContext.Simd // SIMD
ComputingContext.Parallel // parallel (large data)
ComputingContext.Auto // heuristic by problemSize
ComputingContext.Default // process default (initially Auto)Auto thresholds (elements / flop count): ≥1024 → SIMD, ≥16384 → Parallel (see ResolveCpuMode).
signal.TransformToFrequencyDomain();
values.Sum();
var c = a * b;signal.TransformToFrequencyDomain(ComputingContext.Parallel, WindowType.Hamming);
FastFourierTransform.Forward(input, output, ComputingContext.Simd);
var sum = span.Sum(ComputingContext.Parallel);
var product = Matrix.Multiply(a, b, ComputingContext.Parallel);using (ComputingScope.Enter(ComputingContext.Parallel))
{
var spec1 = s1.TransformToFrequencyDomain();
var spec2 = s2.TransformToFrequencyDomain(ComputingContext.Simd); // single-call override
var mean = buffer.Average(); // uses Parallel from scope
}ComputingContext.ConfigureDefault(ComputingContext.Auto);ITimeDomainSignal.TransformToFrequencyDomain(ComputingContext?, WindowType?)-
FastFourierTransform.Forward / Inverse(..., ComputingContext?)(real/complex span and array overloads) TimeDomainCharacteristicOps.GetRms / GetAmplitude / GetAveragePower / ...-
ISingleThreadTimeDomainSignal.GetRms(context)and related extensions (bypass cached properties)
-
Basic.Sum / Average / Variance / StandardDeviation(Span<float/double>and generic floating-point) IComparableExtension.CompareMax / CompareMin
-
Matrix.Multiply(a, b, context),Matrix<T>.Multiply(...) Matrix.Multiply(vector, result, context)VectorSpan.Dot / Sum / Norm / Add / Subtract / Axpy / Scale(..., context)
APIs that accept ComputingContext? context call ComputingContext.Resolve(null) when context == null, so ComputingScope applies even when null is passed explicitly (consistent with the resolution order above). Legacy overloads without a context parameter are unchanged.
-
TensorStatistics.MeanAlongAxis / StandardDeviationAlongAxis / NormalizeAlongAxis / MeanAlongDepth(optionalcontext) -
Basic.WeightedAverage(values, weights, context)(generic floating-point)
-
ComputingContextExecution.ForEach— batch-dimension / index parallel scheduling -
BatchConv2DMath.Forward,BatchMaxPool2DMath.Forward,BatchFullyConnectedLayer,BatchDepthwiseConvolution2DLayerforward (readsComputingScope/Resolve) -
BatchConv2DIm2Col.Forward— im2col +TensorOps.GemmTransposeRight(..., context) -
Trainer.Fit / FitBatched / FitBatchSequential / FitBatchParallelConcat / FitCnnMlpoptionalcomputingContextparameter MlpTrainingOptions.ComputingContext- Legacy single-sample layers
Layers.Conv2D / Dense / LinearLayer / MaxPool2D / ReLU / Sigmoid / BatchNorm / JoinLayer / Fusion— channel-dimensionForEachDepth(respectsComputingScope)
-
TensorOps.GemmTransposeRight(..., ComputingContext?)— im2col convolution GEMM row parallelism
-
FeatureExtractor.ParallelChunksComputeFrom / ParallelComputeFrom(..., ComputingContext?)— thread count and chunked parallelism -
MfccExtractorand subclasses viaParallelComputeFrom(samples, context: ComputingContext.Parallel)or outerComputingScopefor unified policy
-
Trainer.FitCnnMlp(..., computingContext)— same scope installation asFitBatched -
BatchPreEmphasisLayer / BatchStftMagnitudeLayer / BatchMelFilterbankLayer— batch-dimensionForEach(STFT parallelism uses per-threadStftinstances) -
BatchNormLayer / BatchBatchNormLayer— channel parallelism (for large data)
// Offline MFCC features
using (ComputingScope.Enter(ComputingContext.Parallel))
var mfcc = extractor.ParallelComputeFrom(samples);
// CNN + Mel frontend training
trainer.FitCnnMlp(model, loss, opt, batches, epochs, computingContext: ComputingContext.Parallel);The following APIs are marked [Obsolete]; migrate to ComputingContext:
| Legacy API | New API |
|---|---|
FftVersion.SIMD |
ComputingContext.Simd |
FftVersion.Parallel |
ComputingContext.Parallel |
FftVersion.Normal |
ComputingContext.Normal |
TransformToFrequencyDomain(window, fftVersion) |
TransformToFrequencyDomain(context, window) |
FastFourierTransform.Version = ... |
ComputingScope.Enter(...) or per-call context
|
Pointer-based FFT overloads without a context parameter still use the global Version delegate; prefer span/array overloads in new code.
| Constant | Value | Use |
|---|---|---|
ParallelReductionThreshold |
65536 | Sum, variance, dot product, etc. |
ParallelMatrixMultiplyThreshold |
262144 | Matrix multiply |
-
Cached properties such as
Signal.Rms/Amplitude— fixed SIMD path; useGetRms(context)etc. for policy-aware behavior -
Matrix operator *, parameterlessvalues.Sum()— library default; useMultiply(..., context)/Sum(context)when needed
- Matrix decomposition (SVD / LU / QR) — no parallel hot spots
-
RealOnlyFFT, overlap-add filters — single-threaded implementations -
Experimental.CurveFitting.NeuralNetwork— separate optimization path - GPU / CUDA — not provided in the main package; see GPU policy
- Alignment with
OptimizationMode(curve fitting) - Removal of
FftVersionandFastFourierTransform.Version
Note: Legacy APIs without a
contextparameter keep their previous behavior; only hot paths listed in this document readComputingContext/ComputingScope.
The main package executes on CPU only today. These enums describe a future extension surface; they are not wired into ComputingContext yet.
| Value | Meaning |
|---|---|
CPU |
Host processor (current default) |
GPU |
Graphics / compute GPU |
FPGA |
Field-programmable gate array |
ASIC |
Application-specific integrated circuit |
TPU |
Tensor processing unit |
NPU |
Neural processing unit |
Maps a backend choice to an execution style: Sequential_Normal, Sequential_SIMD, Parallel.
See GPU policy for why GPU is not shipped in the main NuGet package.
Numerical equivalence across Normal / Parallel (and SIMD) paths is covered by tests:
| Test project | Content |
|---|---|
TESTS/core_module_test |
ComputingContext_test: statistics, matrices, VectorSpan, FFT roundtrip, large-array parallelism |
TESTS/DL_module_test |
ComputingContext_equivalence_test: 27 forward/backward/training/MFCC/frontend-layer Normal vs Parallel cases |
Run (Release):
dotnet run --project TESTS/core_module_test/core_module_test.csproj -c Release
dotnet run --project TESTS/DL_module_test/DL_module_test.csproj -c ReleaseEquivalence tolerances: forward/backward 1e-4; post-training inference 5e-3 (floating-point accumulation order differences).
-
- 🔖 ArrayExtension class
- 🔖 BaseConverter class
- 🔖 BitMathExtension class
- 🔖 Combinatorics class
- 🔖 ConstantsFp32 class
- 🔖 NumberMapper class
- 🔖 PinnableArray<T> class
- 🔖 SimpleRNG_Fp32 and SimpleRNG_Fp64 classes
- 🔖 TrigonometryHelper class
- 🔖 VMath class
- 🔖 Pinned buffers (Buffers)
- 🔖 IPinnedBuffer<T> interface
- 🔖 POHBuffer<T> class
- 🔖 NativeBuffer<T> class
-
- 🔖 0.9 classifier walkthrough
- 🔖 KNN<T> class
- 🔖 MultipleLinearRegression<T> class
- 🔖 SimpleLinearRegression<T> class
- 🔖 SupportVectorMachine<TSelf> class
- 🔖 DBSCAN<T> class
- 🔖 ExpectationMaximization<T> class
- 🔖 GMM<T> class
- 🔖 HierarchicalClustering<T> class
- 🔖 KMeansClusterer<T> class
- 🔖 VectorQuantization<T> class
- 🔖 FactorAnalysis<T> class
- 🔖 PCA<TSelf> class
- 🔖 TSNE<T> class
- 🔖 Distance metric classes
-
📒 Examples
-
📒 GPU 策略说明
- 🔖 为何放弃主包 GPU
- 🔖 当前性能路径
- 🔖 若仍需要更强算力
-
📒 计算上下文模块
-
📒 核心模块
-
📒 深度学习模块
-
📒 线性代数模块
-
📒 机器学习模块
- 🔖 0.9 分类器完整示例
- 🔖 KNN<T> 类
- 🔖 MultipleLinearRegression<T> 类
- 🔖 SimpleLinearRegression<T> 类
- 🔖 SupportVectorMachine<TSelf> 类
- 🔖 DBSCAN<T> 类
- 🔖 ExpectationMaximization<T> 类
- 🔖 GMM<T> 类
- 🔖 HierarchicalClustering<T> 类
- 🔖 KMeansClusterer<T> 类
- 🔖 VectorQuantization<T> 类
- 🔖 FactorAnalysis<T> 类
- 🔖 PCA<TSelf> 类
- 🔖 TSNE<T> 类
- 🔖 距离度量类
-
📒 信号处理模块
-
📒 数值模块
-
📒 统计模块
- 🔖 基础统计函数
- 🔖 高级统计函数
- 🔖 稳健统计 / RunningMoments
- 🔖 其它统计函数
- 🔖 分布相关函数
- 🔖 时间序列分析
- 🔖 IComparable 扩展
- 🔖 ExtremeValueFinder
- 🔖 INumber 扩展
-
📒 FFTW 扩展
-
📒 示例