mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-07-01 03:45:06 +00:00
Add dll probe path so that the right DirectML.dll is loaded while running C# tests (#5104)
This commit is contained in:
parent
5618b9dddc
commit
782ccff207
1 changed files with 31 additions and 4 deletions
|
|
@ -97,7 +97,17 @@ namespace Microsoft.ML.OnnxRuntime.Tests
|
|||
opt.AppendExecutionProvider_CUDA(0);
|
||||
#endif
|
||||
#if USE_DML
|
||||
// Explicitly set dll probe path so that the (potentially) stale system DirectML.dll
|
||||
// doesn't get loaded by the test process when it is eventually delay loaded by onnruntime.dll
|
||||
// The managed tests binary path already contains the right DirectML.dll, so use that
|
||||
|
||||
var directml_dll_path = AppDomain.CurrentDomain.BaseDirectory;
|
||||
SetDllDirectory(directml_dll_path);
|
||||
opt.AppendExecutionProvider_DML(0);
|
||||
|
||||
// Restore the default dll search order
|
||||
SetDllDirectory(null);
|
||||
|
||||
#endif
|
||||
#if USE_NGRAPH
|
||||
opt.AppendExecutionProvider_NGraph("CPU"); //TODO: this API should be refined
|
||||
|
|
@ -119,6 +129,13 @@ namespace Microsoft.ML.OnnxRuntime.Tests
|
|||
}
|
||||
}
|
||||
|
||||
// Use to set dll probe path so that the right dll(s) is loaded by the test process
|
||||
// Invoke only to specify Windows specific EPs' dll locations explicitly
|
||||
[DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
|
||||
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
static extern bool SetDllDirectory(string lpPathName);
|
||||
|
||||
[Fact]
|
||||
public void TestRunOptions()
|
||||
{
|
||||
|
|
@ -1594,7 +1611,7 @@ namespace Microsoft.ML.OnnxRuntime.Tests
|
|||
|
||||
Assert.Equal(2, modelMetadata.CustomMetadataMap.Keys.Count);
|
||||
Assert.Equal("dummy_value", modelMetadata.CustomMetadataMap["dummy_key"]);
|
||||
Assert.Equal("{\"session_options\": {\"inter_op_num_threads\": 5, \"intra_op_num_threads\": 2, \"graph_optimization_level\": 99, \"enable_profiling\": 1}}",
|
||||
Assert.Equal("{\"session_options\": {\"inter_op_num_threads\": 5, \"intra_op_num_threads\": 2, \"graph_optimization_level\": 99, \"enable_profiling\": 1}}",
|
||||
modelMetadata.CustomMetadataMap["ort_config"]);
|
||||
|
||||
|
||||
|
|
@ -2119,6 +2136,13 @@ namespace Microsoft.ML.OnnxRuntime.Tests
|
|||
{
|
||||
string modelPath = Path.Combine(Directory.GetCurrentDirectory(), "squeezenet.onnx");
|
||||
#if USE_DML
|
||||
// Explicitly set dll probe path so that the (potentially) stale system DirectML.dll
|
||||
// doesn't get loaded by the test process when it is eventually delay loaded by onnruntime.dll
|
||||
// The managed tests binary path already contains the right DirectML.dll, so use that
|
||||
|
||||
var directml_dll_path = AppDomain.CurrentDomain.BaseDirectory;
|
||||
SetDllDirectory(directml_dll_path);
|
||||
|
||||
using (var option = new SessionOptions())
|
||||
{
|
||||
if (!deviceId.HasValue)
|
||||
|
|
@ -2130,6 +2154,9 @@ namespace Microsoft.ML.OnnxRuntime.Tests
|
|||
{
|
||||
option.AppendExecutionProvider_DML(deviceId.Value);
|
||||
}
|
||||
|
||||
// Restore the default dll search order
|
||||
SetDllDirectory(null);
|
||||
#elif USE_CUDA
|
||||
using (var option = (deviceId.HasValue) ?
|
||||
SessionOptions.MakeSessionOptionWithCudaProvider(deviceId.Value) :
|
||||
|
|
@ -2140,7 +2167,7 @@ namespace Microsoft.ML.OnnxRuntime.Tests
|
|||
option.AppendExecutionProvider_CPU(1);
|
||||
}
|
||||
#else
|
||||
using (var option = new SessionOptions())
|
||||
using (var option = new SessionOptions())
|
||||
{
|
||||
option.AppendExecutionProvider_CPU(1);
|
||||
#endif
|
||||
|
|
@ -2215,7 +2242,7 @@ namespace Microsoft.ML.OnnxRuntime.Tests
|
|||
public DisposableListTest() { }
|
||||
public DisposableListTest(int count) : base(count) { }
|
||||
|
||||
#region IDisposable Support
|
||||
#region IDisposable Support
|
||||
private bool disposedValue = false; // To detect redundant calls
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
|
|
@ -2248,6 +2275,6 @@ namespace Microsoft.ML.OnnxRuntime.Tests
|
|||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
#endregion
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue