Class GenAI
java.lang.Object
smile.onnx.genai.GenAI
Process-wide ONNX Runtime GenAI controls: library availability, telemetry,
logging helpers, and shutdown.
Both onnxruntime and onnxruntime-genai shared libraries
must be on the OS library search path. The JVM also needs
--enable-native-access=ALL-UNNAMED.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringDirectory containingonnxruntime-genai(system propertyonnxruntime-genai.native.path).static final StringDirectory containingonnxruntime(system propertyonnxruntime.native.path).static final StringEnvironment variable forPROVIDER_PROPERTY.static final StringExecution-provider preference:auto(default),cuda,npu,ryzenai/hybrid,openvino,qnn,dml/directml, orcpu. -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanReturns whether theonnxruntime-genainative library can be loaded.static booleanReturns whether CUDA-capable GenAI/ORT shared libraries were found on the configured native library path (e.g.static BooleanReturns whether a previousModel.open(Path)successfully used the CUDA EP, ornullif CUDA has not been attempted yet in this process.static voidinit()Forces native library load.static booleanReturns whether the GenAI library has been initialized in this process.static StringReturns the preferred GenAI execution-provider mode.static GenAIOliveTargetResolves Oliveoptimize--device/--provider/ default precision fromproviderPreference()and EP natives (same order asModel.open(Path)).static voidsetLogBool(String name, boolean value) Sets a boolean logging option (e.g.static voidsetLogString(String name, String value) Sets a string logging option (e.g.static voidsetTelemetry(boolean enabled) Enables or disables non-essential GenAI telemetry events.static voidshutdown()Tears down GenAI globals.static booleansupportsFp8(String candidateId) Returns whether candidateidis known to support FP8 Olive builds.
-
Field Details
-
ORT_NATIVE_PATH_PROPERTY
Directory containingonnxruntime(system propertyonnxruntime.native.path).- See Also:
-
GENAI_NATIVE_PATH_PROPERTY
Directory containingonnxruntime-genai(system propertyonnxruntime-genai.native.path).- See Also:
-
PROVIDER_PROPERTY
Execution-provider preference:auto(default),cuda,npu,ryzenai/hybrid,openvino,qnn,dml/directml, orcpu. Environment variableSMILE_ONNX_GENAI_PROVIDERoverrides the system propertysmile.onnx.genai.provider.Classical Vitis AI for general ONNX is configured via
SessionOptions.appendVitisAiExecutionProvider(), not this GenAI preference.- See Also:
-
PROVIDER_ENV
-
-
Method Details
-
providerPreference
Returns the preferred GenAI execution-provider mode.- Returns:
- normalized preference:
auto,cuda,npu,ryzenai,openvino,qnn,dml, orcpu.
-
cudaProviderUsable
Returns whether a previousModel.open(Path)successfully used the CUDA EP, ornullif CUDA has not been attempted yet in this process.- Returns:
true/falseafter a CUDA attempt, elsenull.
-
cudaNativesPresent
public static boolean cudaNativesPresent()Returns whether CUDA-capable GenAI/ORT shared libraries were found on the configured native library path (e.g. piponnxruntime-genai-cuda).- Returns:
truewhen CUDA companion natives are present.
-
supportsFp8
Returns whether candidateidis known to support FP8 Olive builds.Olive
optimizecurrently does not acceptfp8in its CLI precision enum; keep thisfalseuntil that changes.- Parameters:
candidateId- GenAI cascade id (e.g.cuda).- Returns:
truewhen auto precision should tryfp8first.
-
resolveOliveTarget
Resolves Oliveoptimize--device/--provider/ default precision fromproviderPreference()and EP natives (same order asModel.open(Path)).- Returns:
- Olive target;
cpu/int4when no accelerator is present.
-
available
public static boolean available()Returns whether theonnxruntime-genainative library can be loaded.- Returns:
truewhen the FFM bindings initialize successfully.
-
init
public static void init()Forces native library load. Prefer calling this early so missing natives fail fast with a clear exception.On Windows, if an older
onnxruntime.dlllives inSystem32, set "onnxruntime.native.path" and "onnxruntime-genai.native.path" to the pip package directories so the correct DLLs areSystem.loadRESTRICTEDed first.- Throws:
GenAIException- if the native library cannot be loaded.
-
setTelemetry
public static void setTelemetry(boolean enabled) Enables or disables non-essential GenAI telemetry events.- Parameters:
enabled-trueto enable telemetry.
-
setLogBool
Sets a boolean logging option (e.g."enabled","append").- Parameters:
name- option name.value- option value.
-
setLogString
-
isInitialized
public static boolean isInitialized()Returns whether the GenAI library has been initialized in this process.- Returns:
trueif initialized,falseotherwise.
-
shutdown
public static void shutdown()Tears down GenAI globals. Destroy every GenAI object before calling this. Safe to call multiple times or when GenAI was never initialized.After shutdown, the next GenAI API call re-initializes the library.
-