# AI Scheduler Model Integration

## Model Configuration

Place ONNX models in `/etc/mvgal/models/` directory.

### Required Model Format

The AI scheduling model should:
- Accept input tensor of shape `[1, 48]` (features vector)
- Output tensor of shape `[1, 8]` (per-GPU scores)
- Be compatible with ONNX Runtime

### Feature Vector Layout

```c
// mvgal_ai_features_t (48 floats = 192 bytes)
gpu_utilization[8]      // 0.0-1.0 per GPU
vram_pressure[8]        // 0.0-1.0 per GPU  
queue_depth[8]          // Normalized queue depth
workload_history[16]    // Recent distribution history
temperature[8]          // Normalized temperature
num_gpus               // Actual GPU count
workload_type          // Hint for workload classification
reserved[8]            // Padding/alignment
```

### Model Training Data

For production training, collect:
1. Workload type (render/compute/memory)
2. GPU telemetry during execution
3. Latency measurements
4. Power consumption
5. User/application preferences

## Integration Notes

### Current Implementation

- `mvgal_ai_model_load()` - Mock implementation (loads path string)
- `mvgal_ai_model_predict()` - Heuristic-based prediction
- `mvgal_ai_model_unload()` - Resource cleanup

### ONNX Runtime Integration

To enable real AI inference:

```cmake
# CMakeLists.txt addition
find_package(ONNXRuntime REQUIRED)
target_link_libraries(mvgal_ai PRIVATE onnxruntime)
```

Then replace mock prediction with:
```cpp
#include <onnxruntime_cxx_api.h>

int mvgal_ai_model_predict(mvgal_ai_model_t model, ...) {
    Ort::Session* session = (Ort::Session*)model->handle;
    // Convert features to tensor
    // Run inference
    // Extract recommendation
}
```

## Model Deployment

```bash
# Default model path (configured in mvgal.conf)
/etc/mvgal/models/scheduler.onnx

# Or explicit path via environment
MVGAL_AI_MODEL_PATH=/path/to/model.onnx
```

## Testing

The AI features test (`test_mvgal_ai_features`) validates:
- Feature extraction from GPU state
- Prediction with mock model
- Fallback behavior when no model available
- NULL safety for all API calls