Class SensorReading
- Namespace
- DotCompute.Abstractions.Health
- Assembly
- DotCompute.Abstractions.dll
Represents a single sensor reading from a compute device.
public sealed record SensorReading : IEquatable<SensorReading>
- Inheritance
-
SensorReading
- Implements
- Inherited Members
Remarks
This immutable record captures a point-in-time sensor measurement with metadata about availability, units, and quality indicators. Sensor readings are typically collected at 1-10 second intervals to balance monitoring overhead with responsiveness.
Performance Characteristics: - Reading collection: 1-5ms per device (NVML/CUPTI) - Memory footprint: ~100 bytes per reading - Typical collection interval: 5-10 seconds
Usage Example:
var readings = await accelerator.GetSensorReadingsAsync();
var tempReading = readings.FirstOrDefault(r => r.SensorType == SensorType.Temperature);
if (tempReading?.IsAvailable == true)
{
Console.WriteLine($"GPU Temperature: {tempReading.Value}°C");
if (tempReading.Value > 85.0)
{
logger.LogWarning("GPU temperature critical: {temp}°C", tempReading.Value);
}
}
Properties
IsAvailable
Gets whether this sensor is available on the current device.
public required bool IsAvailable { get; init; }
Property Value
Remarks
When false, Value should be ignored. This typically occurs when:
- The hardware doesn't support this sensor type
- Driver capabilities are insufficient
- Permissions are lacking (e.g., reading power on Linux without root)
- The sensor failed to initialize
Backend Availability: - CUDA: All standard sensors typically available (requires NVML) - Metal: Temperature, memory, utilization available; power limited - OpenCL: Varies widely by vendor and platform - CPU: Temperature and utilization usually available
MaxValue
Gets optional maximum expected value for this sensor. Used for validation and alerting thresholds.
public double? MaxValue { get; init; }
Property Value
Remarks
Common Max Values:
- Temperature: 95-105°C (thermal shutdown threshold)
- PowerDraw: TDP (Thermal Design Power) of the device
- Utilization/FanSpeed: 100 (percent)
- Clocks: Maximum boost clock frequency
MinValue
Gets optional minimum expected value for this sensor. Used for validation and normalization.
public double? MinValue { get; init; }
Property Value
Remarks
For percentage-based sensors (utilization, fan speed), typically 0. For temperature sensors, typically ambient temperature (~20-30°C).
Name
Gets an optional human-readable name for this sensor. Useful for custom sensors or vendor-specific metrics.
public string? Name { get; init; }
Property Value
Examples
"GPU Core Temperature", "NVLink Throughput", "Infinity Fabric Bandwidth"
Quality
Gets the quality indicator for this reading (0.0-1.0).
public double Quality { get; init; }
Property Value
Remarks
Quality factors that may reduce this value: - Age of reading (stale data) - Sensor accuracy/precision - Thermal/electrical noise - Interpolated vs. directly measured
Quality Guidelines: - 1.0: Fresh, directly measured, high precision - 0.9-1.0: Good quality, acceptable for most uses - 0.5-0.9: Moderate quality, may be stale or estimated - 0.0-0.5: Poor quality, use with caution
SensorType
Gets the type of sensor this reading represents.
public required SensorType SensorType { get; init; }
Property Value
Timestamp
Gets the timestamp when this reading was captured (UTC).
public required DateTimeOffset Timestamp { get; init; }
Property Value
Unit
Gets the unit of measurement for this sensor reading.
public required string Unit { get; init; }
Property Value
Examples
"Celsius", "Watts", "Percent", "MHz", "Bytes", "Bytes/sec", "Count"
Value
Gets the sensor value. Interpretation depends on SensorType.
public required double Value { get; init; }
Property Value
Remarks
Common Units by Sensor Type:
- Temperature: Degrees Celsius
- PowerDraw: Watts
- ComputeUtilization/MemoryUtilization/FanSpeed: Percentage (0-100)
- GraphicsClock/MemoryClock: MHz
- Memory*Bytes: Bytes
- PcieThroughput*: Bytes per second
- ThrottlingStatus/PowerThrottlingStatus: Enumerated severity (0-3+)
- ErrorCount: Count
Always check Unit for authoritative unit information.
Methods
Create(SensorType, double, double?, double?, string?)
Creates an available sensor reading with standard unit and timestamp.
public static SensorReading Create(SensorType sensorType, double value, double? minValue = null, double? maxValue = null, string? name = null)
Parameters
sensorTypeSensorTypeThe type of sensor.
valuedoubleThe measured value.
minValuedouble?Optional minimum expected value.
maxValuedouble?Optional maximum expected value.
namestringOptional human-readable name.
Returns
- SensorReading
An available sensor reading.
ToString()
Returns a string representation of this sensor reading.
public override string ToString()
Returns
Unavailable(SensorType, string?)
Creates a sensor reading indicating the sensor is unavailable.
public static SensorReading Unavailable(SensorType sensorType, string? name = null)
Parameters
sensorTypeSensorTypeThe type of sensor.
namestringOptional human-readable name.
Returns
- SensorReading
An unavailable sensor reading with default values.