Both OnnxCreate/OnnxCreateFromBuffer and OnnxRun take a ulong flags argument — a bitmask drawn from ENUM_ONNX_FLAGS. The flags control which execution provider runs the session, what gets logged, whether profiling is enabled, and whether type conversions happen. This article documents every flag, the combinations that work, and what changed in Build 5572.
The flags, grouped
Execution provider selection
| Flag | Effect |
|---|---|
ONNX_DEFAULT | Use GPU if available; fall back to CPU. Recommended default. |
ONNX_USE_CPU_ONLY | Force CPU. Use when GPU is below Turing, or when CPU is faster for your model. Replaces removed ONNX_CUDA_DISABLE. |
ONNX_GPU_DEVICE_0 … ONNX_GPU_DEVICE_7 | Pin to a specific CUDA device on multi-GPU systems. New in Build 5572. |
Logging
| Flag | Effect |
|---|---|
ONNX_LOGLEVEL_VERBOSE | Every log line. Use during integration. Replaces ONNX_DEBUG_LOGS. |
ONNX_LOGLEVEL_WARNING | Warnings + errors only. Use in production. |
ONNX_LOGLEVEL_ERROR | Errors only. Quietest. |
Profiling
| Flag | Effect |
|---|---|
ONNX_ENABLE_PROFILING | Dump per-node execution trace to JSON in MQL5\Files\OnnxProfileReports\. New in Build 5572. |
Runtime hints
| Flag | Effect |
|---|---|
ONNX_NO_CONVERSION | Skip MQL5's automatic type conversion. Use when your matrixf/vectorf types already match the model's expected dtypes — a few percent faster. |
Combining flags
Flags are a bitmask — combine with the OR operator (|):
common flag combinations
// Default — use GPU if available
OnnxCreateFromBuffer(buf, ONNX_DEFAULT);
// Production — default behavior, only log warnings/errors
OnnxCreateFromBuffer(buf, ONNX_DEFAULT | ONNX_LOGLEVEL_WARNING);
// Force CPU on a machine with incompatible GPU
OnnxCreateFromBuffer(buf, ONNX_USE_CPU_ONLY);
// Pin to GPU 1 on a dual-GPU rig, enable profiling
OnnxCreateFromBuffer(buf, ONNX_GPU_DEVICE_1 | ONNX_ENABLE_PROFILING);
// Full debug mode during integration
OnnxCreateFromBuffer(buf, ONNX_DEFAULT | ONNX_LOGLEVEL_VERBOSE | ONNX_ENABLE_PROFILING);
Deprecated and removed flags
ONNX_CUDA_DISABLE— removed in Build 5572. UseONNX_USE_CPU_ONLY.ONNX_DEBUG_LOGS— deprecated. UseONNX_LOGLEVEL_VERBOSE.
Code that references either removed flag will not compile against Build 5572.
Flag-precedence rules
OnnxRunflags override session flags. IfOnnxCreatewas called withONNX_DEFAULTbut a specificOnnxRuncall passesONNX_USE_CPU_ONLY, that one inference uses CPU.- Conflicting flags resolve to the most restrictive.
ONNX_USE_CPU_ONLY | ONNX_GPU_DEVICE_0resolves to CPU-only (the explicit "use CPU" wins). - Multiple
ONNX_GPU_DEVICE_Nresolve to the lowest N. PassingONNX_GPU_DEVICE_0 | ONNX_GPU_DEVICE_3uses device 0. - A non-existent device index falls back to auto-pick.
ONNX_GPU_DEVICE_5on a single-GPU machine doesn't error — the runtime picks a device for you.