GpuDiagnosticsConfig

Options & Configuration · AiDotNet.Configuration

Process-global control for GPU backend diagnostic output visibility. Exposes three orthogonal knobs matching github.com/ooples/AiDotNet#1122’s requested-change checklist: environment variable, static configuration, and ILogger / custom sink.

How It Works

AiDotNet’s GPU backends (OpenCL, HIP, CUDA) emit status messages during device discovery, kernel compilation, and availability checks. Historically these were always written to WriteLine, producing ~40 lines of output on every AiModelBuilder.BuildAsync(). This class provides the AiDotNet-side facade for controlling that output.

Three orthogonal controls (all work simultaneously):

Example

// Option A: Environment variable — set before starting the process.
//   AIDOTNET_GPU_VERBOSE=1
            
// Option B: Static configuration
AiDotNet.Configuration.GpuDiagnosticsConfig.Level = GpuDiagnosticLevel.Silent;
            
Microsoft.Extensions.Logging.ILogger myLogger =
    Microsoft.Extensions.Logging.Abstractions.NullLogger.Instance;

// Option C: Custom sink (route to any logging framework).
AiDotNet.Configuration.GpuDiagnosticsConfig.Sink =
    (level, msg) => Console.WriteLine($"[gpu:{level}] {msg}");
            
// Or via ILogger extension
AiDotNet.Configuration.GpuDiagnosticsConfig.Sink = myLogger.ToSink();

Properties

Property Summary
GpuDiagnosticLevel Level { get; set; } Current verbosity level.
GpuDiagnosticSink Sink { get; set; } Optional sink that receives diagnostic messages when set.
bool Verbose { get; set; } Legacy bool flag.

Methods

Method Summary
IDisposable PushLevel(GpuDiagnosticLevel level) Push a scoped override of Level that automatically restores the previous value when the returned IDisposable is disposed (typically via using var _ = PushLevel(...)).
void Emit(GpuDiagnosticLevel level, string message) Emits a diagnostic message, respecting the current Level and routing through Sink if set (else Console).