GPU-accelerated algorithms for DotCompute. Includes FFT, AutoDiff, sparse matrix operations, signal processing, and cryptographic primitives.
$ dotnet add package DotCompute.AlgorithmsComprehensive library of GPU-accelerated algorithms for scientific computing, signal processing, and numerical analysis.
The Algorithms library provides implementations across multiple domains:
dotnet add package DotCompute.Algorithms --version 0.5.3
using DotCompute.Algorithms.LinearAlgebra;
using DotCompute.Abstractions;
// Create GPU linear algebra provider
var provider = new GPULinearAlgebraProvider(accelerator, logger);
// Create matrices
var matrixA = new Matrix(rows: 1024, cols: 512);
var matrixB = new Matrix(rows: 512, cols: 2048);
// Fill with data
matrixA.Fill(/* data */);
matrixB.Fill(/* data */);
// Perform matrix multiplication on GPU
var result = await provider.MultiplyAsync(matrixA, matrixB);
// Result is a 1024x2048 matrix
Console.WriteLine($"Result: {result.Rows}x{result.Columns}");
using DotCompute.Algorithms.LinearAlgebra.Operations;
var decomposition = new LuDecomposition(accelerator);
// Decompose matrix A into L and U
var (L, U, P) = await decomposition.DecomposeAsync(matrixA);
// Solve Ax = b using LU decomposition
var solution = await decomposition.SolveAsync(L, U, P, vectorB);
using DotCompute.Algorithms.SignalProcessing;
var fft = new FFT(accelerator);
// Perform 1D FFT
var signal = new Complex[1024];
// ... fill signal with data ...
var spectrum = await fft.ForwardAsync(signal);
// Perform inverse FFT
var reconstructed = await fft.InverseAsync(spectrum);
using DotCompute.Algorithms.SignalProcessing;
var convOps = new ConvolutionOperations(accelerator);
// 1D convolution
float[] signal = /* input signal */;
float[] kernel = /* convolution kernel */;
var output = await convOps.Convolve1DAsync(signal, kernel);
// 2D convolution (for images)
float[,] image = /* input image */;
float[,] filter = /* filter kernel */;
var filtered = await convOps.Convolve2DAsync(image, filter);
using DotCompute.Algorithms.Optimized.Simd;
using System.Runtime.Intrinsics;
// Check SIMD capabilities
var capabilities = SimdCapabilities.Detect();
Console.WriteLine($"AVX2: {capabilities.HasAvx2}");
Console.WriteLine($"AVX-512: {capabilities.HasAvx512}");
// Vectorized addition
float[] a = new float[1024];
float[] b = new float[1024];
float[] result = new float[1024];
SimdMathOperations.Add(a, b, result);
// Vectorized reduction (sum)
float sum = SimdReductionOperations.Sum(a);
// Dot product
float dotProduct = SimdReductionOperations.DotProduct(a, b);
using DotCompute.Algorithms.NumericalMethods;
var integration = new AdvancedIntegration();
// Integrate f(x) = x^2 from 0 to 10
double result = integration.AdaptiveQuadrature(
x => x * x,
lowerBound: 0,
upperBound: 10,
tolerance: 1e-6
);
Console.WriteLine($"Integral: {result:F6}");
using DotCompute.Algorithms.Optimized;
var autoTuner = new AutoTuner(accelerator);
// Auto-tune matrix multiplication parameters
var tuningResult = await autoTuner.TuneMatrixMultiplicationAsync(
matrixSize: 2048,
dataType: typeof(float)
);
Console.WriteLine($"Optimal tile size: {tuningResult.OptimalTileSize}");
Console.WriteLine($"Optimal work group: {tuningResult.OptimalWorkGroupSize}");
Console.WriteLine($"Expected performance: {tuningResult.EstimatedGFlops:F2} GFLOPS");
using DotCompute.Algorithms.Management;
var discovery = new AlgorithmPluginDiscovery(logger);
// Discover all available algorithms
var algorithms = await discovery.DiscoverAsync(searchPaths);
foreach (var algorithm in algorithms)
{
Console.WriteLine($"Algorithm: {algorithm.Name}");
Console.WriteLine($"Version: {algorithm.Version}");
Console.WriteLine($"Backends: {string.Join(", ", algorithm.SupportedBackends)}");
}
using DotCompute.Algorithms.Security;
var scanner = new VulnerabilityScanner(logger);
// Scan project dependencies
var scanOptions = new VulnerabilityScanOptions
{
ScanNuGetPackages = true,
ScanGitHubAdvisories = true,
MinimumSeverity = Severity.Medium,
IncludeDevDependencies = false
};
var vulnerabilities = await scanner.ScanAsync(projectPath, scanOptions);
// Generate report
var report = scanner.GenerateReport(vulnerabilities);
Console.WriteLine(report.Summary);
foreach (var vuln in vulnerabilities.Where(v => v.Severity >= Severity.High))
{
Console.WriteLine($"[{vuln.Severity}] {vuln.PackageName} - {vuln.CveId}");
Console.WriteLine($" Description: {vuln.Description}");
Console.WriteLine($" Fix: Upgrade to {vuln.RecommendedVersion}");
}
DotCompute.Algorithms/
├── LinearAlgebra/ # Matrix and vector operations
│ ├── Components/ # GPU implementation components
│ ├── Operations/ # High-level operations (solvers, decompositions)
│ └── LinearAlgebraKernels/ # Kernel implementations
├── SignalProcessing/ # FFT, convolution, filtering
├── NumericalMethods/ # Integration, ODE solvers, polynomial ops
├── Optimized/ # Performance-optimized implementations
│ └── Simd/ # SIMD vectorized operations
├── Kernels/ # GPU kernel library
│ └── LinearAlgebra/ # Linear algebra GPU kernels
├── Management/ # Algorithm plugin management
│ ├── Discovery/ # Algorithm discovery
│ ├── Lifecycle/ # Plugin lifecycle
│ └── Execution/ # Algorithm execution
├── Security/ # Vulnerability scanning
│ ├── DataTransfer/ # CVE database integration
│ └── Reports/ # Security report generation
└── Selection/ # Algorithm selection strategies
Linear algebra operations use provider pattern for backend abstraction:
Algorithm selection uses strategy pattern:
Algorithms can be loaded as plugins:
| Implementation | CPU Time | GPU Time | Speedup |
|---|---|---|---|
| Naive | 8,240ms | 142ms | 58x |
| Tiled | N/A | 47ms | 175x |
| BLAS-optimized | 89ms | 38ms | 2.3x over CPU BLAS |
| Implementation | Time | Throughput |
|---|---|---|
| CPU FFT | 156ms | 6.4 MSamples/s |
| GPU FFT | 8.4ms | 119 MSamples/s |
| Speedup | 18.6x |
| Implementation | Time | Speedup |
|---|---|---|
| Scalar | 45ms | 1x |
| SSE (128-bit) | 12ms | 3.75x |
| AVX2 (256-bit) | 6ms | 7.5x |
| AVX-512 (512-bit) | 3ms | 15x |
var options = new AlgorithmOptions
{
DefaultBackend = AcceleratorType.Auto,
EnableAutoTuning = true,
CacheKernels = true,
ValidationLevel = ValidationLevel.Release,
PerformanceProfile = PerformanceProfile.Balanced
};
var laConfig = new LinearAlgebraConfiguration
{
TileSize = 16, // For tiled matrix multiplication
UseSharedMemory = true,
EnableFusedOperations = true,
NumericalStability = NumericalStability.Balanced
};
var fftConfig = new FFTConfiguration
{
Algorithm = FFTAlgorithm.CooleyTukey,
UseRadix4 = true, // When input size is power of 4
EnableCaching = true
};
SimdCapabilities.Detect() for hardware supportAutoTuner to find optimal parametersImplement custom algorithms as plugins:
public class CustomAlgorithm : IAlgorithmPlugin
{
public string Name => "CustomAlgorithm";
public Version Version => new Version(1, 0, 0);
public AcceleratorType[] SupportedBackends => new[] { AcceleratorType.CUDA };
public async Task<object> ExecuteAsync(object input, CancellationToken ct)
{
// Custom algorithm implementation
return result;
}
}
using DotCompute.Algorithms.Kernels.LinearAlgebra;
// Create sparse matrix in CSR format
var sparseMatrix = SparseMatrix.CreateCSR(rows, cols, nonZeroValues, columnIndices, rowPointers);
// Sparse matrix-vector multiplication
var result = await sparseMatrix.MultiplyVectorAsync(vector);
// Use float for computation, double for accumulation
var result = await provider.MultiplyAsync<float, double>(matrixA, matrixB);
Comprehensive documentation is available for DotCompute:
Contributions are welcome in:
See CONTRIBUTING.md for guidelines.
MIT License - Copyright (c) 2025 Michael Ivertowski