- 
                Notifications
    
You must be signed in to change notification settings  - Fork 3.5k
 
[java] Auto EP and compile model support #25131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Merged
      
      
    
  
     Merged
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            9 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      e2770f5
              
                Java bits for EP selection and compile API.
              
              
                Craigacp 5bc9491
              
                Building out JNI for OrtHardwareDevice and OrtEpDevice.
              
              
                Craigacp 197d245
              
                Finished OrtModelCompilationOptions.
              
              
                Craigacp d553c4f
              
                Simplifying the getEpDevices JNI.
              
              
                Craigacp 1f8c5d5
              
                Fixing EP detection on Windows.
              
              
                Craigacp acea9f1
              
                Fixing shared lib copying and adding more Javadoc.
              
              
                Craigacp fd5044c
              
                Fix spotless errors.
              
              
                Craigacp 252fdfb
              
                Guarding the shared library copy in Java.
              
              
                Craigacp d8bfbed
              
                Fixing javadoc.
              
              
                Craigacp File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| /* | ||
| * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved. | ||
| * Licensed under the MIT License. | ||
| */ | ||
| package ai.onnxruntime; | ||
| 
     | 
||
| import java.util.Map; | ||
| 
     | 
||
| /** A tuple of Execution Provider information and the hardware device. */ | ||
| public final class OrtEpDevice { | ||
| 
     | 
||
| private final long nativeHandle; | ||
| 
     | 
||
| private final String epName; | ||
| private final String epVendor; | ||
| private final Map<String, String> epMetadata; | ||
| private final Map<String, String> epOptions; | ||
| private final OrtHardwareDevice device; | ||
| 
     | 
||
| /** | ||
| * Construct an OrtEpDevice tuple from the native pointer. | ||
| * | ||
| * @param nativeHandle The native pointer. | ||
| */ | ||
| OrtEpDevice(long nativeHandle) { | ||
| this.nativeHandle = nativeHandle; | ||
| this.epName = getName(OnnxRuntime.ortApiHandle, nativeHandle); | ||
| this.epVendor = getVendor(OnnxRuntime.ortApiHandle, nativeHandle); | ||
| String[][] metadata = getMetadata(OnnxRuntime.ortApiHandle, nativeHandle); | ||
| this.epMetadata = OrtUtil.convertToMap(metadata); | ||
| String[][] options = getOptions(OnnxRuntime.ortApiHandle, nativeHandle); | ||
| this.epOptions = OrtUtil.convertToMap(options); | ||
| this.device = new OrtHardwareDevice(getDeviceHandle(OnnxRuntime.ortApiHandle, nativeHandle)); | ||
| } | ||
| 
     | 
||
| /** | ||
| * Return the native pointer. | ||
| * | ||
| * @return The native pointer. | ||
| */ | ||
| long getNativeHandle() { | ||
| return nativeHandle; | ||
| } | ||
| 
     | 
||
| /** | ||
| * Gets the EP name. | ||
| * | ||
| * @return The EP name. | ||
| */ | ||
| public String getName() { | ||
                
      
                  edgchen1 marked this conversation as resolved.
               
          
            Show resolved
            Hide resolved
         | 
||
| return epName; | ||
| } | ||
| 
     | 
||
| /** | ||
| * Gets the vendor name. | ||
| * | ||
| * @return The vendor name. | ||
| */ | ||
| public String getVendor() { | ||
| return epVendor; | ||
| } | ||
| 
     | 
||
| /** | ||
| * Gets an unmodifiable view on the EP metadata. | ||
| * | ||
| * @return The EP metadata. | ||
| */ | ||
| public Map<String, String> getMetadata() { | ||
| return epMetadata; | ||
| } | ||
| 
     | 
||
| /** | ||
| * Gets an unmodifiable view on the EP options. | ||
| * | ||
| * @return The EP options. | ||
| */ | ||
| public Map<String, String> getOptions() { | ||
| return epOptions; | ||
| } | ||
| 
     | 
||
| /** | ||
| * Gets the device information. | ||
| * | ||
| * @return The device information. | ||
| */ | ||
| public OrtHardwareDevice getDevice() { | ||
| return device; | ||
| } | ||
| 
     | 
||
| @Override | ||
| public String toString() { | ||
| return "OrtEpDevice{" | ||
| + "epName='" | ||
| + epName | ||
| + '\'' | ||
| + ", epVendor='" | ||
| + epVendor | ||
| + '\'' | ||
| + ", epMetadata=" | ||
| + epMetadata | ||
| + ", epOptions=" | ||
| + epOptions | ||
| + ", device=" | ||
| + device | ||
| + '}'; | ||
| } | ||
| 
     | 
||
| private static native String getName(long apiHandle, long nativeHandle); | ||
| 
     | 
||
| private static native String getVendor(long apiHandle, long nativeHandle); | ||
| 
     | 
||
| private static native String[][] getMetadata(long apiHandle, long nativeHandle); | ||
| 
     | 
||
| private static native String[][] getOptions(long apiHandle, long nativeHandle); | ||
| 
     | 
||
| private static native long getDeviceHandle(long apiHandle, long nativeHandle); | ||
| } | ||
        
          
          
            4 changes: 2 additions & 2 deletions
          
          4 
        
  ...va/ai/onnxruntime/providers/OrtFlags.java → ...rc/main/java/ai/onnxruntime/OrtFlags.java
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
      
      Oops, something went wrong.
        
    
  
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.