mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-07-29 20:14:01 +00:00
### Description Cherry-picks 26 commits to the release branch. Most cherry-picks are clean merges. Except: 1. When I got conflicts in cgmanifest.json and download-deps.yml, I choose to ignore the conflicts and regenerate the two files 2. There were some conflicts in cmake/deps.txt, onnxruntime_c_api.cc PR list: [js/webgpu] fix Transpose with non-float tensor (#15819) [js/web] fix terser reserved symbols for worker (#15864) [JSEP] fix constructor for OrtDevice (#15805) Bump engine.io from 6.4.1 to 6.4.2 in /js/web (#15799) Bump engine.io from 6.4.0 to 6.4.2 in /onnxruntime/test/wasm (#15798) [wasm] revert emsdk to v3.1.19 (#15793) [wasm/JSEP] add threaded build to artifacts (#15777) [js/web] add target ort.webgpu.min.js (#15780) update ort extensions to 94142d8391c9791ec71c38336436319a2d4ac7a0 (#15688) fix: setting builder optimization level to TRT 8.6 default (#15897) Adust GetVersionString() GetBuildInfoString() signatures and move them to OrtApi (#15921) Fix segfault for multiple GPU run (regression) (#15823) android package fix (#15999) [CoreML EP] Minor changes to allow CoreML EP to handle more nodes and models. (#15993) Adding support for conv fp16 fusion on Resnet50v1 (#15474) update onnx release 1.14 for docker files (#15680) Avoid generating training documentation during packaging (#15795) Update Conv-Add-Relu Fusion Transformation (#15834) Fix symbolic shape infer empty value_info (#15842) NhwcFusedConv: Add before Activation (#15837) use __hmul2 instead of __hmul2_rn (#15852) change the EP device to default OrtDevice() for memoryType equals CPU Input (#15903) Fixing NhwcFusedConv fp16 (#15950) fix topo sort in quantization tool (#16003) [doc] add LeakyRelu to coreml supported ops (#15944) [DML EP] Add frequent upload heap flushing (#15960) Co-authored-by: Yulong Wang Co-authored-by: dependabot[bot] Co-authored-by: Guenther Schmuelling Co-authored-by: Shalva Mist Co-authored-by: Maximilian Müller Co-authored-by: Dmitri Smirnov Co-authored-by: pengwa Co-authored-by: Ashwini Khade Co-authored-by: Edward Chen Co-authored-by: Jian Chen Co-authored-by: liqun Fu Co-authored-by: Baiju Meswani Co-authored-by: Tianlei Wu Co-authored-by: Chen Fu Co-authored-by: Ye Wang Co-authored-by: cao lei Co-authored-by: Yufeng Li Co-authored-by: Rachel Guo Co-authored-by: Patrice Vignola
215 lines
7.4 KiB
C#
215 lines
7.4 KiB
C#
using System;
|
|
using Xunit;
|
|
|
|
|
|
namespace Microsoft.ML.OnnxRuntime.Tests
|
|
{
|
|
/// <summary>
|
|
/// Collection of OrtEnv tests that must be ran sequentially
|
|
/// </summary>
|
|
[Collection("Ort Inference Tests")]
|
|
public class OrtEnvCollectionTest
|
|
{
|
|
[Fact(DisplayName = "EnablingAndDisablingTelemetryEventCollection")]
|
|
public void EnablingAndDisablingTelemetryEventCollection()
|
|
{
|
|
var ortEnvInstance = OrtEnv.Instance();
|
|
ortEnvInstance.DisableTelemetryEvents();
|
|
|
|
// no-op on non-Windows builds
|
|
// may be no-op on certain Windows builds based on build configuration
|
|
|
|
ortEnvInstance.EnableTelemetryEvents();
|
|
}
|
|
}
|
|
|
|
[Collection("Ort Inference Tests")]
|
|
public class OrtEnvGetVersion
|
|
{
|
|
[Fact(DisplayName = "GetVersionString")]
|
|
public void GetVersionString()
|
|
{
|
|
var ortEnvInstance = OrtEnv.Instance();
|
|
string versionString = ortEnvInstance.GetVersionString();
|
|
Assert.False(versionString.Length == 0);
|
|
}
|
|
}
|
|
|
|
[Collection("Ort Inference Tests")]
|
|
public class OrtEnvGetAvailableProviders
|
|
{
|
|
|
|
[Fact(DisplayName = "GetAvailableProviders")]
|
|
public void GetAvailableProviders()
|
|
{
|
|
var ortEnvInstance = OrtEnv.Instance();
|
|
string[] providers = ortEnvInstance.GetAvailableProviders();
|
|
|
|
Assert.True(providers.Length > 0);
|
|
Assert.Equal("CPUExecutionProvider", providers[providers.Length - 1]);
|
|
|
|
#if USE_CUDA
|
|
Assert.True(Array.Exists(providers, provider => provider == "CUDAExecutionProvider"));
|
|
#endif
|
|
#if USE_ROCM
|
|
Assert.True(Array.Exists(providers, provider => provider == "ROCMExecutionProvider"));
|
|
#endif
|
|
}
|
|
}
|
|
|
|
[Collection("Ort Inference Tests")]
|
|
public class OrtEnvWithCustomLogLevel
|
|
{
|
|
|
|
[Fact(DisplayName = "TestUpdatingEnvWithCustomLogLevel")]
|
|
public void TestUpdatingEnvWithCustomLogLevel()
|
|
{
|
|
var ortEnvInstance = OrtEnv.Instance();
|
|
Assert.True(OrtEnv.IsCreated);
|
|
ortEnvInstance.Dispose();
|
|
Assert.False(OrtEnv.IsCreated);
|
|
|
|
// Must be default level of warning
|
|
ortEnvInstance = OrtEnv.Instance();
|
|
ortEnvInstance.Dispose();
|
|
Assert.False(OrtEnv.IsCreated);
|
|
|
|
var envOptions = new EnvironmentCreationOptions
|
|
{
|
|
// Everything else is unpopulated
|
|
logLevel = OrtLoggingLevel.ORT_LOGGING_LEVEL_FATAL
|
|
};
|
|
|
|
ortEnvInstance = OrtEnv.CreateInstanceWithOptions(ref envOptions);
|
|
Assert.True(OrtEnv.IsCreated);
|
|
Assert.Equal(OrtLoggingLevel.ORT_LOGGING_LEVEL_FATAL, ortEnvInstance.EnvLogLevel);
|
|
|
|
ortEnvInstance.Dispose();
|
|
Assert.False(OrtEnv.IsCreated);
|
|
envOptions = new EnvironmentCreationOptions
|
|
{
|
|
// Everything else is unpopulated
|
|
logId = "CSharpOnnxRuntimeTestLogid"
|
|
};
|
|
|
|
ortEnvInstance = OrtEnv.CreateInstanceWithOptions(ref envOptions);
|
|
Assert.Equal(OrtLoggingLevel.ORT_LOGGING_LEVEL_WARNING, ortEnvInstance.EnvLogLevel);
|
|
|
|
// Change and see if this takes effect
|
|
ortEnvInstance.EnvLogLevel = OrtLoggingLevel.ORT_LOGGING_LEVEL_INFO;
|
|
Assert.Equal(OrtLoggingLevel.ORT_LOGGING_LEVEL_INFO, ortEnvInstance.EnvLogLevel);
|
|
}
|
|
}
|
|
|
|
[Collection("Ort Inference Tests")]
|
|
public class OrtEnvWithThreadingOptions
|
|
{
|
|
[Fact(DisplayName = "TestUpdatingEnvWithThreadingOptions")]
|
|
public void TestUpdatingEnvWithThreadingOptions()
|
|
{
|
|
OrtEnv.Instance().Dispose();
|
|
Assert.False(OrtEnv.IsCreated);
|
|
|
|
using (var opt = new OrtThreadingOptions())
|
|
{
|
|
var envOptions = new EnvironmentCreationOptions
|
|
{
|
|
threadOptions = opt
|
|
};
|
|
|
|
// Make sure we start anew
|
|
var env = OrtEnv.CreateInstanceWithOptions(ref envOptions);
|
|
Assert.True(OrtEnv.IsCreated);
|
|
}
|
|
}
|
|
}
|
|
|
|
public class CustomLoggingFunctionTestBase
|
|
{
|
|
// Custom logging constants
|
|
protected static readonly string TestLogId = "CSharpTestLogId";
|
|
protected static readonly IntPtr TestLogParam = (IntPtr)5;
|
|
protected static int LoggingInvokes = 0;
|
|
|
|
protected static void CustomLoggingFunction(IntPtr param,
|
|
OrtLoggingLevel severity,
|
|
string category,
|
|
string logId,
|
|
string codeLocation,
|
|
string message)
|
|
{
|
|
Assert.Equal(TestLogParam, param); // Passing test param
|
|
Assert.False(string.IsNullOrEmpty(codeLocation));
|
|
Assert.False(string.IsNullOrEmpty(message));
|
|
LoggingInvokes++;
|
|
}
|
|
}
|
|
|
|
[Collection("Ort Inference Tests")]
|
|
public class OrtEnvWithCustomLogger : CustomLoggingFunctionTestBase
|
|
{
|
|
|
|
[Fact(DisplayName = "TesEnvWithCustomLogger")]
|
|
public void TesEnvWithCustomLogger()
|
|
{
|
|
// Make sure we start anew
|
|
OrtEnv.Instance().Dispose();
|
|
Assert.False(OrtEnv.IsCreated);
|
|
var envOptions = new EnvironmentCreationOptions
|
|
{
|
|
logId = TestLogId,
|
|
logLevel = OrtLoggingLevel.ORT_LOGGING_LEVEL_VERBOSE,
|
|
loggingFunction = CustomLoggingFunction,
|
|
loggingParam = TestLogParam
|
|
};
|
|
|
|
LoggingInvokes = 0;
|
|
|
|
var env = OrtEnv.CreateInstanceWithOptions(ref envOptions);
|
|
Assert.True(OrtEnv.IsCreated);
|
|
|
|
var model = TestDataLoader.LoadModelFromEmbeddedResource("squeezenet.onnx");
|
|
// Trigger some logging
|
|
// Empty stmt intentional
|
|
using (var session = new InferenceSession(model))
|
|
;
|
|
Assert.True(LoggingInvokes > 0);
|
|
}
|
|
}
|
|
|
|
[Collection("Ort Inference Tests")]
|
|
public class OrtEnvWithCustomLoggerAndThreadindOptions : CustomLoggingFunctionTestBase
|
|
{
|
|
[Fact(DisplayName = "TestEnvWithCustomLoggerAndThredingOptions")]
|
|
public void TestEnvWithCustomLoggerAndThredingOptions()
|
|
{
|
|
OrtEnv.Instance().Dispose();
|
|
Assert.False(OrtEnv.IsCreated);
|
|
|
|
using (var opt = new OrtThreadingOptions())
|
|
{
|
|
var envOptions = new EnvironmentCreationOptions
|
|
{
|
|
logId = TestLogId,
|
|
logLevel = OrtLoggingLevel.ORT_LOGGING_LEVEL_VERBOSE,
|
|
threadOptions = opt,
|
|
loggingFunction = CustomLoggingFunction,
|
|
loggingParam = TestLogParam
|
|
};
|
|
|
|
LoggingInvokes = 0;
|
|
|
|
var env = OrtEnv.CreateInstanceWithOptions(ref envOptions);
|
|
Assert.True(OrtEnv.IsCreated);
|
|
|
|
var model = TestDataLoader.LoadModelFromEmbeddedResource("squeezenet.onnx");
|
|
// Trigger some logging
|
|
// Empty stmt intentional
|
|
using (var session = new InferenceSession(model))
|
|
;
|
|
Assert.True(LoggingInvokes > 0);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|