Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion cmake/onnxruntime_providers_vitisai.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,16 @@
"${ONNXRUNTIME_ROOT}/core/providers/shared_library/*.cc"
)
source_group(TREE ${ONNXRUNTIME_ROOT}/core FILES ${onnxruntime_providers_vitisai_cc_srcs})
onnxruntime_add_shared_library(onnxruntime_providers_vitisai ${onnxruntime_providers_vitisai_cc_srcs})
set(onnxruntime_providers_vitisai_all_srcs ${onnxruntime_providers_vitisai_cc_srcs})
if(WIN32)
# Sets the DLL version info on Windows: https://learn.microsoft.com/en-us/windows/win32/menurc/versioninfo-resource
list(APPEND onnxruntime_providers_vitisai_all_srcs "${ONNXRUNTIME_ROOT}/core/providers/vitisai/onnxruntime_providers_vitisai.rc")
endif()
onnxruntime_add_shared_library(onnxruntime_providers_vitisai ${onnxruntime_providers_vitisai_all_srcs})
if(WIN32)
# FILE_NAME preprocessor definition is used in onnxruntime_providers_vitisai.rc
target_compile_definitions(onnxruntime_providers_vitisai PRIVATE FILE_NAME=\"onnxruntime_providers_vitisai.dll\")
endif()
onnxruntime_add_include_to_target(onnxruntime_providers_vitisai ${ONNXRUNTIME_PROVIDERS_SHARED} ${GSL_TARGET} safeint_interface flatbuffers::flatbuffers Boost::mp11)
target_link_libraries(onnxruntime_providers_vitisai PRIVATE ${ONNXRUNTIME_PROVIDERS_SHARED} ${ABSEIL_LIBS})
if(MSVC)
Expand Down
2 changes: 1 addition & 1 deletion cmake/onnxruntime_unittests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -1786,7 +1786,7 @@ endif()
endif()
endif()

if (NOT CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
if (NOT CMAKE_SYSTEM_NAME STREQUAL "Emscripten" AND NOT onnxruntime_CUDA_MINIMAL)

set(custom_op_src_patterns
"${TEST_SRC_DIR}/testdata/custom_op_library/*.h"
Expand Down
65 changes: 65 additions & 0 deletions csharp/src/Microsoft.ML.OnnxRuntime/NativeMethods.shared.cs
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,36 @@ public struct OrtApi
public IntPtr Graph_GetModelMetadata;
public IntPtr GetModelCompatibilityForEpDevices;
public IntPtr CreateExternalInitializerInfo;

// v1.24 APIs
public IntPtr TensorTypeAndShape_HasShape;
public IntPtr KernelInfo_GetConfigEntries;
public IntPtr KernelInfo_GetOperatorDomain;
public IntPtr KernelInfo_GetOperatorType;
public IntPtr KernelInfo_GetOperatorSinceVersion;
public IntPtr GetInteropApi;
public IntPtr SessionGetEpDeviceForOutputs;
public IntPtr GetNumHardwareDevices;
public IntPtr GetHardwareDevices;
public IntPtr GetHardwareDeviceEpIncompatibilityDetails;
public IntPtr DeviceEpIncompatibilityDetails_GetReasonsBitmask;
public IntPtr DeviceEpIncompatibilityDetails_GetNotes;
public IntPtr DeviceEpIncompatibilityDetails_GetErrorCode;
public IntPtr ReleaseDeviceEpIncompatibilityDetails;
public IntPtr GetCompatibilityInfoFromModel;
public IntPtr GetCompatibilityInfoFromModelBytes;
public IntPtr CreateEnvWithOptions;
public IntPtr Session_GetEpGraphAssignmentInfo;
public IntPtr EpAssignedSubgraph_GetEpName;
public IntPtr EpAssignedSubgraph_GetNodes;
public IntPtr EpAssignedNode_GetName;
public IntPtr EpAssignedNode_GetDomain;
public IntPtr EpAssignedNode_GetOperatorType;
public IntPtr RunOptionsSetSyncStream;
public IntPtr GetTensorElementTypeAndShapeDataReference;
// v1.25 APIs
public IntPtr RunOptionsEnableProfiling;
public IntPtr RunOptionsDisableProfiling;
}

internal static class NativeMethods
Expand Down Expand Up @@ -884,6 +914,16 @@ static NativeMethods()
(DOrtCopyTensors)Marshal.GetDelegateForFunctionPointer(
api_.CopyTensors,
typeof(DOrtCopyTensors));

OrtGetCompatibilityInfoFromModel =
(DOrtGetCompatibilityInfoFromModel)Marshal.GetDelegateForFunctionPointer(
api_.GetCompatibilityInfoFromModel,
typeof(DOrtGetCompatibilityInfoFromModel));

OrtGetCompatibilityInfoFromModelBytes =
(DOrtGetCompatibilityInfoFromModelBytes)Marshal.GetDelegateForFunctionPointer(
api_.GetCompatibilityInfoFromModelBytes,
typeof(DOrtGetCompatibilityInfoFromModelBytes));
}

internal class NativeLib
Expand Down Expand Up @@ -3092,6 +3132,31 @@ public delegate IntPtr DOrtEpSelectionDelegate(

public static DOrtReleasePrepackedWeightsContainer OrtReleasePrepackedWeightsContainer;

/// <summary>
/// Extract EP compatibility info from a precompiled model file.
/// </summary>
[UnmanagedFunctionPointer(CallingConvention.Winapi)]
public delegate IntPtr /* OrtStatus* */ DOrtGetCompatibilityInfoFromModel(
byte[] /* const ORTCHAR_T* */ model_path,
byte[] /* const char* */ ep_type,
IntPtr /* OrtAllocator* */ allocator,
out IntPtr /* char** */ compatibility_info);

public static DOrtGetCompatibilityInfoFromModel OrtGetCompatibilityInfoFromModel;

/// <summary>
/// Extract EP compatibility info from precompiled model bytes in memory.
/// </summary>
[UnmanagedFunctionPointer(CallingConvention.Winapi)]
public delegate IntPtr /* OrtStatus* */ DOrtGetCompatibilityInfoFromModelBytes(
byte[] /* const void* */ model_data,
UIntPtr /* size_t */ model_data_length,
byte[] /* const char* */ ep_type,
IntPtr /* OrtAllocator* */ allocator,
out IntPtr /* char** */ compatibility_info);

public static DOrtGetCompatibilityInfoFromModelBytes OrtGetCompatibilityInfoFromModelBytes;

#endregion
} // class NativeMethods

Expand Down
69 changes: 69 additions & 0 deletions csharp/src/Microsoft.ML.OnnxRuntime/OrtEnv.shared.cs
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,75 @@ public OrtCompiledModelCompatibility GetModelCompatibilityForEpDevices(
return (OrtCompiledModelCompatibility)status;
}

/// <summary>
/// Extract EP compatibility info from a precompiled model file.
/// </summary>
/// <remarks>
/// Parses the model file to extract the compatibility info string for a specific execution provider
/// from the model's metadata properties. This is only applicable to models that have been precompiled
/// for an EP. Standard ONNX models do not contain this information.
/// The compatibility info can then be passed to <see cref="GetModelCompatibilityForEpDevices"/> to
/// check if a precompiled model is compatible with the current system.
/// </remarks>
/// <param name="modelPath">Path to the ONNX model file.</param>
/// <param name="epType">The execution provider type string. Use <see cref="OrtEpDevice.EpName"/> to get this value.</param>
/// <returns>The compatibility info string, or null if no compatibility info exists for the specified EP.</returns>
/// <exception cref="ArgumentException">If modelPath or epType is null or empty.</exception>
/// <exception cref="OnnxRuntimeException">If the model file cannot be read or parsed.</exception>
public string GetCompatibilityInfoFromModel(string modelPath, string epType)
{
if (string.IsNullOrEmpty(modelPath))
throw new ArgumentException("modelPath must be non-empty", nameof(modelPath));
if (string.IsNullOrEmpty(epType))
throw new ArgumentException("epType must be non-empty", nameof(epType));

var allocator = OrtAllocator.DefaultInstance;
var pathBytes = NativeOnnxValueHelper.GetPlatformSerializedString(modelPath);
var epTypeUtf8 = NativeOnnxValueHelper.StringToZeroTerminatedUtf8(epType);

NativeApiStatus.VerifySuccess(
NativeMethods.OrtGetCompatibilityInfoFromModel(
pathBytes, epTypeUtf8, allocator.Pointer, out IntPtr compatInfoPtr));

if (compatInfoPtr == IntPtr.Zero)
return null;

return NativeOnnxValueHelper.StringFromNativeUtf8(compatInfoPtr, allocator);
}

/// <summary>
/// Extract EP compatibility info from precompiled model bytes in memory.
/// </summary>
/// <remarks>
/// Same as <see cref="GetCompatibilityInfoFromModel"/> but reads from a memory buffer instead of a file.
/// Useful when precompiled models are loaded from encrypted storage, network, or other non-file sources.
/// </remarks>
/// <param name="modelData">The model data bytes.</param>
/// <param name="epType">The execution provider type string. Use <see cref="OrtEpDevice.EpName"/> to get this value.</param>
/// <returns>The compatibility info string, or null if no compatibility info exists for the specified EP.</returns>
/// <exception cref="ArgumentException">If modelData is null/empty or epType is null or empty.</exception>
/// <exception cref="OnnxRuntimeException">If the model data cannot be parsed.</exception>
public string GetCompatibilityInfoFromModelBytes(byte[] modelData, string epType)
{
if (modelData == null || modelData.Length == 0)
throw new ArgumentException("modelData must be non-empty", nameof(modelData));
if (string.IsNullOrEmpty(epType))
throw new ArgumentException("epType must be non-empty", nameof(epType));

var allocator = OrtAllocator.DefaultInstance;
var epTypeUtf8 = NativeOnnxValueHelper.StringToZeroTerminatedUtf8(epType);

NativeApiStatus.VerifySuccess(
NativeMethods.OrtGetCompatibilityInfoFromModelBytes(
modelData, (UIntPtr)modelData.Length, epTypeUtf8,
allocator.Pointer, out IntPtr compatInfoPtr));

if (compatInfoPtr == IntPtr.Zero)
return null;

return NativeOnnxValueHelper.StringFromNativeUtf8(compatInfoPtr, allocator);
}


/// <summary>
/// Get/Set log level property of OrtEnv instance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ namespace Microsoft.ML.OnnxRuntime.Tests;
using System.Linq;
using Xunit;
using System.Collections.Generic;
using Google.Protobuf;
using Onnx;

public class EpCompatibilityTests
{
Expand All @@ -23,6 +25,35 @@ private IReadOnlyList<OrtEpDevice> GetDevices()
return epDevices;
}

/// <summary>
/// Creates a minimal valid ONNX ModelProto with optional compatibility metadata.
/// </summary>
private static byte[] CreateModelWithCompatibilityMetadata(
Dictionary<string, string> epCompatibilityInfo = null)
{
var modelProto = new ModelProto();
modelProto.IrVersion = (long)Onnx.Version.IrVersion;
modelProto.Graph = new GraphProto { Name = "test_graph" };

var opset = new OperatorSetIdProto();
opset.Domain = "";
opset.Version = 13;
modelProto.OpsetImport.Add(opset);

if (epCompatibilityInfo != null)
{
foreach (var kvp in epCompatibilityInfo)
{
var prop = new StringStringEntryProto();
prop.Key = "ep_compatibility_info." + kvp.Key;
prop.Value = kvp.Value;
modelProto.MetadataProps.Add(prop);
}
}

return modelProto.ToByteArray();
}

[Fact]
public void GetEpCompatibility_InvalidArgs()
{
Expand All @@ -45,5 +76,103 @@ public void GetEpCompatibility_SingleDeviceCpuProvider()
// CPU defaults to not applicable in this scenario
Assert.Equal(OrtCompiledModelCompatibility.EP_NOT_APPLICABLE, status);
}

[Fact]
public void GetCompatibilityInfoFromModel_InvalidArgs()
{
Assert.Throws<ArgumentException>(() => ortEnvInstance.GetCompatibilityInfoFromModel(null, "TestEP"));
Assert.Throws<ArgumentException>(() => ortEnvInstance.GetCompatibilityInfoFromModel("", "TestEP"));
Assert.Throws<ArgumentException>(() => ortEnvInstance.GetCompatibilityInfoFromModel("model.onnx", null));
Assert.Throws<ArgumentException>(() => ortEnvInstance.GetCompatibilityInfoFromModel("model.onnx", ""));
}

[Fact]
public void GetCompatibilityInfoFromModel_FileNotFound()
{
Assert.Throws<OnnxRuntimeException>(
() => ortEnvInstance.GetCompatibilityInfoFromModel("nonexistent_model_path.onnx", "TestEP"));
}

[Fact]
public void GetCompatibilityInfoFromModelBytes_InvalidArgs()
{
Assert.Throws<ArgumentException>(() => ortEnvInstance.GetCompatibilityInfoFromModelBytes(null, "TestEP"));
Assert.Throws<ArgumentException>(() => ortEnvInstance.GetCompatibilityInfoFromModelBytes(new byte[0], "TestEP"));
Assert.Throws<ArgumentException>(() => ortEnvInstance.GetCompatibilityInfoFromModelBytes(new byte[] { 1, 2, 3 }, null));
Assert.Throws<ArgumentException>(() => ortEnvInstance.GetCompatibilityInfoFromModelBytes(new byte[] { 1, 2, 3 }, ""));
}

[Fact]
public void GetCompatibilityInfoFromModel_WithMetadata()
{
const string epType = "TestCompatEP";
const string expectedCompatInfo = "test_compat_v1.0_driver_123";

byte[] modelData = CreateModelWithCompatibilityMetadata(
new Dictionary<string, string> { { epType, expectedCompatInfo } });

string tempModelPath = System.IO.Path.Combine(
System.IO.Path.GetTempPath(),
System.IO.Path.GetRandomFileName() + ".onnx");

System.IO.File.WriteAllBytes(tempModelPath, modelData);

try
{
string result = ortEnvInstance.GetCompatibilityInfoFromModel(tempModelPath, epType);
Assert.NotNull(result);
Assert.Equal(expectedCompatInfo, result);
}
finally
{
if (System.IO.File.Exists(tempModelPath))
{
System.IO.File.Delete(tempModelPath);
}
}
}

[Fact]
public void GetCompatibilityInfoFromModelBytes_InvalidModelData()
{
byte[] invalidData = System.Text.Encoding.UTF8.GetBytes("this is not a valid ONNX model");
Assert.Throws<OnnxRuntimeException>(
() => ortEnvInstance.GetCompatibilityInfoFromModelBytes(invalidData, "TestEP"));
}

[Fact]
public void GetCompatibilityInfoFromModelBytes_WithMetadata()
{
const string epType = "TestCompatEP";
const string expectedCompatInfo = "test_compat_v1.0_driver_123";

byte[] modelData = CreateModelWithCompatibilityMetadata(
new Dictionary<string, string> { { epType, expectedCompatInfo } });

string result = ortEnvInstance.GetCompatibilityInfoFromModelBytes(modelData, epType);
Assert.NotNull(result);
Assert.Equal(expectedCompatInfo, result);
}

[Fact]
public void GetCompatibilityInfoFromModelBytes_NotFound()
{
// Create model with metadata for a different EP
byte[] modelData = CreateModelWithCompatibilityMetadata(
new Dictionary<string, string> { { "DifferentEP", "some_value" } });

string result = ortEnvInstance.GetCompatibilityInfoFromModelBytes(modelData, "NonExistentEP");
Assert.Null(result);
}

[Fact]
public void GetCompatibilityInfoFromModelBytes_NoMetadata()
{
// Create model without any compatibility metadata
byte[] modelData = CreateModelWithCompatibilityMetadata();

string result = ortEnvInstance.GetCompatibilityInfoFromModelBytes(modelData, "AnyEP");
Assert.Null(result);
}
}
#endif
5 changes: 4 additions & 1 deletion js/react_native/android/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.13)
project(OnnxruntimeJSI)
cmake_minimum_required(VERSION 3.9.0)

set(PACKAGE_NAME "onnxruntime-react-native")
set(BUILD_DIR ${CMAKE_SOURCE_DIR}/build)
Expand Down Expand Up @@ -97,3 +97,6 @@ target_link_libraries(
${log-lib} # <-- Logcat logger
android # <-- Android JNI core
)

# 16KB page size support (Android 15+ requirement)
target_link_options(onnxruntimejsi PRIVATE "-Wl,-z,max-page-size=16384")
Loading
Loading