DotCompute.Plugins
0.6.2
dotnet add package DotCompute.Plugins --version 0.6.2
NuGet\Install-Package DotCompute.Plugins -Version 0.6.2
<PackageReference Include="DotCompute.Plugins" Version="0.6.2" />
<PackageVersion Include="DotCompute.Plugins" Version="0.6.2" />
<PackageReference Include="DotCompute.Plugins" />
paket add DotCompute.Plugins --version 0.6.2
#r "nuget: DotCompute.Plugins, 0.6.2"
#:package DotCompute.Plugins@0.6.2
#addin nuget:?package=DotCompute.Plugins&version=0.6.2
#tool nuget:?package=DotCompute.Plugins&version=0.6.2
DotCompute Plugin System
A robust, extensible plugin system for DotCompute that enables dynamic loading of backend implementations with full isolation, hot-reload support, and comprehensive lifecycle management.
Features
- Dynamic Loading: Load plugins at runtime from assemblies
- Isolation: Each plugin runs in its own AssemblyLoadContext for complete isolation
- Hot Reload: Support for reloading plugins without restarting the application
- Lifecycle Management: Full control over plugin initialization, start, stop, and disposal
- Health Monitoring: Built-in health checks and metrics collection
- Configuration Support: Dynamic configuration with hot-reload capabilities
- Dependency Management: Automatic resolution of plugin dependencies
- Security: Sandboxing and permission management for plugins
- Performance Tracking: Built-in metrics and telemetry
Installation
dotnet add package DotCompute.Plugins --version 0.5.3
Quick Start
1. Add Plugin Support to Your Host
var host = Host.CreateDefaultBuilder(args)
.UsePlugins(builder => builder
.SetPluginsDirectory("./plugins")
.EnableHotReload()
.SetHealthCheckInterval(TimeSpan.FromMinutes(1))
.EnableMetrics())
.Build();
2. Create a Plugin
[Plugin("my.plugin", "My Custom Plugin")]
[PluginCapability("compute.custom", Version = "1.0.0")]
public class MyPlugin : BackendPluginBase
{
public override string Id => "my.plugin";
public override string Name => "My Custom Plugin";
public override Version Version => new(1, 0, 0);
public override string Description => "A custom compute backend";
public override string Author => "Your Name";
public override PluginCapabilities Capabilities =>
PluginCapabilities.ComputeBackend | PluginCapabilities.HotReloadable;
protected override async Task OnInitializeAsync(CancellationToken cancellationToken)
{
// Initialize your plugin
Logger?.LogInformation("Initializing My Plugin");
}
protected override Task OnStartAsync(CancellationToken cancellationToken)
{
// Start your plugin services
return Task.CompletedTask;
}
protected override Task OnStopAsync(CancellationToken cancellationToken)
{
// Stop your plugin services
return Task.CompletedTask;
}
}
3. Configure Your Plugin
{
"Plugins": {
"PluginsDirectory": "./plugins",
"EnableHotReload": true,
"HealthCheckInterval": "00:01:00",
"my.plugin": {
"Enabled": true,
"Settings": {
"CustomOption": "value"
}
}
}
}
Architecture
Core Components
- IBackendPlugin: Base interface for all plugins
- BackendPluginBase: Abstract base class providing common functionality
- PluginLoader: Handles assembly loading with isolation
- PluginManager: Manages plugin lifecycle and orchestration
- PluginLoadContext: Custom AssemblyLoadContext for isolation
Plugin Lifecycle
Unknown → Loading → Loaded → Initializing → Initialized → Starting → Running
↓
Unloaded ← Unloading ← Stopped ← Stopping ←─────────────────────────────┘
Plugin Capabilities
Plugins can declare various capabilities:
ComputeBackend: Provides compute functionalityStorageProvider: Provides storage servicesNetworkProvider: Provides networking servicesSecurityProvider: Provides security servicesMonitoringProvider: Provides monitoring capabilitiesHotReloadable: Supports hot reloadScalable: Supports horizontal scalingClusterable: Supports clustering
Advanced Features
Hot Reload
Enable hot reload for development:
builder.EnableHotReload()
.ConfigureLoader(options =>
{
options.EnableHotReload = true;
options.ReloadDelay = TimeSpan.FromMilliseconds(500);
});
Resource Limits
Set resource limits per plugin:
builder.SetResourceLimits(maxMemoryMB: 512, maxCpuPercent: 50);
Custom Dependencies
Add shared assemblies and probing paths:
builder.AddSharedAssemblies("MyShared.dll")
.AddProbingPaths("./lib", "./dependencies");
Health Monitoring
Access plugin health and metrics:
var manager = serviceProvider.GetRequiredService<PluginManager>();
var stats = manager.GetStatistics();
var metrics = manager.GetPlugin("my.plugin")?.GetMetrics();
Plugin Discovery
Discover plugins in a directory:
var discoveries = await pluginLoader.DiscoverPluginsAsync("./plugins");
foreach (var discovery in discoveries.Where(d => d.Success))
{
Console.WriteLine($"Found: {discovery.AssemblyName}");
foreach (var plugin in discovery.PluginTypes)
{
Console.WriteLine($" - {plugin.Id}: {plugin.Name} v{plugin.Version}");
}
}
Security
Sandboxing
Enable sandboxing for untrusted plugins:
builder.EnableSandboxing()
.ConfigureManager(options =>
{
options.ValidateSignatures = true;
options.TrustedCertificateThumbprints.Add("THUMBPRINT");
});
Permissions
Configure plugin permissions:
{
"PluginSecurity": {
"my.plugin": {
"AllowFileSystemAccess": false,
"AllowNetworkAccess": true,
"AllowedNetworkEndpoints": ["https://api.example.com"]
}
}
}
Best Practices
- Implement IDisposable: Always clean up resources in your plugins
- Use Logging: Leverage the provided logger for debugging
- Handle Cancellation: Respect cancellation tokens in async operations
- Update Metrics: Keep metrics updated for monitoring
- Validate Configuration: Implement proper validation in your plugins
- Document Dependencies: Clearly document external dependencies
- Version Carefully: Use semantic versioning for your plugins
- Test Isolation: Test plugins in isolation before deployment
Examples
See the Examples folder for complete plugin examples:
ExampleBackendPlugin.cs: Basic plugin implementationComputePlugin.cs: Compute backend pluginStoragePlugin.cs: Storage provider pluginMonitoringPlugin.cs: Monitoring provider plugin
Troubleshooting
Plugin Won't Load
- Check the plugin implements
IBackendPlugin - Verify the
[Plugin]attribute is present - Ensure all dependencies are available
- Check platform requirements are met
Hot Reload Not Working
- Ensure the plugin has
SupportsHotReload = true - Check file permissions on the plugin directory
- Verify no file locks on the plugin assembly
Performance Issues
- Monitor plugin metrics for high CPU/memory usage
- Check for memory leaks in plugin disposal
- Review plugin health status
- Enable performance profiling
Documentation & Resources
Comprehensive documentation is available for DotCompute:
Architecture Documentation
- Backend Integration - Plugin system architecture
- System Overview - Plugin integration in framework
Developer Guides
- Getting Started - Installation and setup
- Backend Selection - Creating custom backends
API Documentation
- API Reference - Complete API documentation
Support
- Documentation: Comprehensive Guides
- Issues: GitHub Issues
- Discussions: GitHub Discussions
Contributing
When contributing plugins:
- Follow the established patterns
- Include comprehensive tests
- Document all public APIs
- Provide configuration examples
- Test hot reload scenarios
- Validate cross-platform compatibility
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net9.0
- DotCompute.Core (>= 0.6.2)
- McMaster.NETCore.Plugins (>= 2.0.0)
- Microsoft.Extensions.Configuration.Abstractions (>= 10.0.2)
- Microsoft.Extensions.Configuration.Binder (>= 10.0.2)
- Microsoft.Extensions.DependencyInjection (>= 10.0.2)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.2)
- Microsoft.Extensions.Hosting.Abstractions (>= 10.0.2)
- Microsoft.Extensions.Logging (>= 10.0.2)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.2)
- Microsoft.Extensions.Options (>= 10.0.2)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 10.0.2)
- Microsoft.NET.ILLink.Tasks (>= 9.0.12)
- NuGet.Common (>= 7.0.1)
- NuGet.Configuration (>= 7.0.1)
- NuGet.Frameworks (>= 7.0.1)
- NuGet.Packaging (>= 7.0.1)
- NuGet.Protocol (>= 7.0.1)
- NuGet.Resolver (>= 7.0.1)
- NuGet.Versioning (>= 7.0.1)
- System.Composition (>= 10.0.2)
- System.Diagnostics.PerformanceCounter (>= 10.0.2)
- System.Formats.Asn1 (>= 10.0.2)
- System.Runtime.Loader (>= 4.3.0)
- System.Security.Cryptography.Pkcs (>= 10.0.2)
- System.Security.Cryptography.X509Certificates (>= 4.3.2)
- System.Text.Json (>= 10.0.2)
NuGet packages (5)
Showing the top 5 NuGet packages that depend on DotCompute.Plugins:
| Package | Downloads |
|---|---|
|
DotCompute.Backends.CUDA
Production-ready NVIDIA CUDA GPU backend for DotCompute. Provides GPU acceleration (21-92x speedup) through CUDA with NVRTC compilation, P2P transfers, Ring Kernels with NCCL support, and unified memory. Requires CUDA 12.0+ and Compute Capability 5.0+ NVIDIA GPU. Benchmarked on RTX 2000 Ada (CC 8.9). |
|
|
DotCompute.Backends.CPU
Production-ready CPU compute backend for DotCompute. Provides SIMD vectorization (3.7x faster) using AVX2/AVX512/NEON instructions, multi-threaded kernel execution, and Ring Kernel simulation. Benchmarked: Vector Add (100K elements) 2.14ms → 0.58ms. Native AOT compatible with sub-10ms startup. |
|
|
DotCompute.Backends.OpenCL
Production-ready OpenCL backend for DotCompute. Cross-platform GPU acceleration for NVIDIA, AMD, Intel, ARM Mali, and Qualcomm Adreno GPUs. Supports OpenCL 1.2+, Ring Kernels with atomic message queues, runtime kernel compilation, and multi-device workload distribution. Works with nvidia-opencl-icd, ROCm, intel-opencl-icd, and vendor drivers. |
|
|
DotCompute.Backends.Metal
Metal backend for DotCompute with GPU acceleration for Apple Silicon (macOS/iOS). Foundation complete with native API bindings, device management, unified memory support, and command buffer execution. MSL (Metal Shading Language) compilation in development. Supports M1/M2/M3/M4 and A-series chips. |
|
|
DotCompute.Algorithms
GPU-accelerated algorithms for DotCompute. Includes FFT, AutoDiff, sparse matrix operations, signal processing, and cryptographic primitives. |
GitHub repositories
This package is not used by any popular GitHub repositories.