@@ -488,6 +488,30 @@ public List<OrtEpDevice> getEpDevices() throws OrtException {
488
488
return Collections .unmodifiableList (devicesList );
489
489
}
490
490
491
+ /**
492
+ * Checks the supplied model info string against the list of {@link OrtEpDevice}s to see if the
493
+ * model is compatible.
494
+ *
495
+ * @param epDevices The EP-Device tuples to use.
496
+ * @param modelInfo The model info string to check.
497
+ * @return The model compatibility.
498
+ * @throws OrtException If the call failed.
499
+ */
500
+ public OrtCompiledModelCompatibility getModelCompatibilityForEpDevices (
501
+ List <OrtEpDevice > epDevices , String modelInfo ) throws OrtException {
502
+ if (epDevices == null || epDevices .isEmpty ()) {
503
+ throw new IllegalArgumentException ("Must supply at least one OrtEpDevice" );
504
+ }
505
+ long [] deviceHandles = new long [epDevices .size ()];
506
+ for (int i = 0 ; i < epDevices .size (); i ++) {
507
+ deviceHandles [i ] = epDevices .get (i ).getNativeHandle ();
508
+ }
509
+
510
+ int output =
511
+ getModelCompatibilityForEpDevices (OnnxRuntime .ortApiHandle , deviceHandles , modelInfo );
512
+ return OrtCompiledModelCompatibility .mapFromInt (output );
513
+ }
514
+
491
515
/**
492
516
* Creates the native object.
493
517
*
@@ -556,6 +580,18 @@ private static native void unregisterExecutionProviderLibrary(
556
580
*/
557
581
private static native long [] getEpDevices (long apiHandle , long nativeHandle ) throws OrtException ;
558
582
583
+ /**
584
+ * Checks if a model is compatible with the supplied list of EP device handles.
585
+ *
586
+ * @param apiHandle The API handle to use.
587
+ * @param epHandles An array of OrtEpDevice handles.
588
+ * @param modelInfo The model info string.
589
+ * @return An int representing the {@link OrtCompiledModelCompatibility} value.
590
+ * @throws OrtException If the call failed.
591
+ */
592
+ private static native int getModelCompatibilityForEpDevices (
593
+ long apiHandle , long [] epHandles , String modelInfo ) throws OrtException ;
594
+
559
595
/**
560
596
* Closes the OrtEnvironment, frees the handle.
561
597
*
@@ -580,6 +616,59 @@ private static native void setTelemetry(long apiHandle, long nativeHandle, boole
580
616
@ Override
581
617
public void close () {}
582
618
619
+ /** Enum representing a compiled model's compatibility with a set of {@link OrtEpDevice}s. */
620
+ public enum OrtCompiledModelCompatibility {
621
+ /** The EP is not applicable for the model. */
622
+ EP_NOT_APPLICABLE (0 ),
623
+ /** The EP supports the model optimally. */
624
+ EP_SUPPORTED_OPTIMAL (1 ),
625
+ /** The EP supports the model, but the model would perform better if recompiled. */
626
+ EP_SUPPORTED_PREFER_RECOMPILATION (2 ),
627
+ /** The EP does not support the model. */
628
+ EP_UNSUPPORTED (3 );
629
+
630
+ private final int value ;
631
+
632
+ private static final Logger logger =
633
+ Logger .getLogger (OrtCompiledModelCompatibility .class .getName ());
634
+ private static final OrtCompiledModelCompatibility [] values =
635
+ new OrtCompiledModelCompatibility [4 ];
636
+
637
+ static {
638
+ for (OrtCompiledModelCompatibility ot : OrtCompiledModelCompatibility .values ()) {
639
+ values [ot .value ] = ot ;
640
+ }
641
+ }
642
+
643
+ OrtCompiledModelCompatibility (int value ) {
644
+ this .value = value ;
645
+ }
646
+
647
+ /**
648
+ * Gets the native value associated with this model compatibility value.
649
+ *
650
+ * @return The native value.
651
+ */
652
+ public int getValue () {
653
+ return value ;
654
+ }
655
+
656
+ /**
657
+ * Maps from the C API's int enum to the Java enum.
658
+ *
659
+ * @param logLevel The index of the Java enum.
660
+ * @return The Java enum.
661
+ */
662
+ public static OrtCompiledModelCompatibility mapFromInt (int logLevel ) {
663
+ if ((logLevel >= 0 ) && (logLevel < values .length )) {
664
+ return values [logLevel ];
665
+ } else {
666
+ logger .warning ("Unknown model compatibility " + logLevel + " setting to EP_UNSUPPORTED" );
667
+ return EP_UNSUPPORTED ;
668
+ }
669
+ }
670
+ }
671
+
583
672
/**
584
673
* Controls the global thread pools in the environment. Only used if the session is constructed
585
674
* using an options with {@link OrtSession.SessionOptions#disablePerSessionThreads()} set.
0 commit comments