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

FlagEffect
ONNX_DEFAULTUse GPU if available; fall back to CPU. Recommended default.
ONNX_USE_CPU_ONLYForce CPU. Use when GPU is below Turing, or when CPU is faster for your model. Replaces removed ONNX_CUDA_DISABLE.
ONNX_GPU_DEVICE_0ONNX_GPU_DEVICE_7Pin to a specific CUDA device on multi-GPU systems. New in Build 5572.

Logging

FlagEffect
ONNX_LOGLEVEL_VERBOSEEvery log line. Use during integration. Replaces ONNX_DEBUG_LOGS.
ONNX_LOGLEVEL_WARNINGWarnings + errors only. Use in production.
ONNX_LOGLEVEL_ERRORErrors only. Quietest.

Profiling

FlagEffect
ONNX_ENABLE_PROFILINGDump per-node execution trace to JSON in MQL5\Files\OnnxProfileReports\. New in Build 5572.

Runtime hints

FlagEffect
ONNX_NO_CONVERSIONSkip 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

Code that references either removed flag will not compile against Build 5572.

Flag-precedence rules

  1. OnnxRun flags override session flags. If OnnxCreate was called with ONNX_DEFAULT but a specific OnnxRun call passes ONNX_USE_CPU_ONLY, that one inference uses CPU.
  2. Conflicting flags resolve to the most restrictive. ONNX_USE_CPU_ONLY | ONNX_GPU_DEVICE_0 resolves to CPU-only (the explicit "use CPU" wins).
  3. Multiple ONNX_GPU_DEVICE_N resolve to the lowest N. Passing ONNX_GPU_DEVICE_0 | ONNX_GPU_DEVICE_3 uses device 0.
  4. A non-existent device index falls back to auto-pick. ONNX_GPU_DEVICE_5 on a single-GPU machine doesn't error — the runtime picks a device for you.