|
1 | | -using Microsoft.ML.OnnxRuntimeGenAI; |
| 1 | +using Microsoft.ML.OnnxRuntime; |
| 2 | +using Microsoft.ML.OnnxRuntimeGenAI; |
2 | 3 | using System.CommandLine; |
3 | 4 | using System.Reflection; |
4 | 5 | using System.Reflection.Metadata.Ecma335; |
@@ -26,45 +27,41 @@ public static void SetLogger(bool inputs = true, bool outputs = true) |
26 | 27 | Utils.SetLogBool("model_output_values", outputs); |
27 | 28 | } |
28 | 29 |
|
29 | | - /** |
30 | | - * TODO: Uncomment the below snippet to use Utils.RegisterEPLibrary once |
31 | | - * the C# binding to Utils.RegisterEPLibrary is in a stable package release. |
32 | | - */ |
33 | | - |
34 | | - // /// <summary> |
35 | | - // /// Register execution provider if path is provided |
36 | | - // /// </summary> |
37 | | - // /// <param name="ep">Name of execution provider to set</param> |
38 | | - // /// <param name="ep_path">Path to execution provider to set</param> |
39 | | - // /// <returns> |
40 | | - // /// None |
41 | | - // /// </returns> |
42 | | - // public static void RegisterEP(string ep, string ep_path) |
43 | | - // { |
44 | | - // if (string.IsNullOrEmpty(ep_path)) |
45 | | - // { |
46 | | - // return; // No library path specified, skip registration |
47 | | - // } |
48 | | - |
49 | | - // Console.WriteLine($"Registering execution provider: {ep_path}"); |
50 | | - |
51 | | - // if (string.Equals(ep, "cuda", StringComparison.OrdinalIgnoreCase)) |
52 | | - // { |
53 | | - // Utils.RegisterExecutionProviderLibrary("CUDAExecutionProvider", ep_path); |
54 | | - // } |
55 | | - // else if (string.Equals(ep, "NvTensorRtRtx", StringComparison.OrdinalIgnoreCase)) |
56 | | - // { |
57 | | - // Utils.RegisterExecutionProviderLibrary("NvTensorRTRTXExecutionProvider", ep_path); |
58 | | - // } |
59 | | - // else |
60 | | - // { |
61 | | - // Console.WriteLine($"Warning: EP registration not supported for {ep}"); |
62 | | - // Console.WriteLine("Only 'cuda' and 'NvTensorRtRtx' support plug-in libraries."); |
63 | | - // return; |
64 | | - // } |
65 | | - |
66 | | - // Console.WriteLine($"Registered {ep} successfully!"); |
67 | | - // } |
| 30 | + /// <summary> |
| 31 | + /// Register execution provider if path is provided |
| 32 | + /// </summary> |
| 33 | + /// <param name="ep">Name of execution provider to set</param> |
| 34 | + /// <param name="ep_path">Path to execution provider to set</param> |
| 35 | + /// <returns> |
| 36 | + /// None |
| 37 | + /// </returns> |
| 38 | + public static void RegisterEP(string ep, string ep_path) |
| 39 | + { |
| 40 | + if (string.IsNullOrEmpty(ep_path)) |
| 41 | + { |
| 42 | + return; // No library path specified, skip registration |
| 43 | + } |
| 44 | + |
| 45 | + Console.WriteLine($"Registering execution provider: {ep_path}"); |
| 46 | + |
| 47 | + var ortEnv = OrtEnv.Instance(); |
| 48 | + if (string.Equals(ep, "cuda", StringComparison.OrdinalIgnoreCase)) |
| 49 | + { |
| 50 | + ortEnv.RegisterExecutionProviderLibrary("CUDAExecutionProvider", ep_path); |
| 51 | + } |
| 52 | + else if (string.Equals(ep, "NvTensorRtRtx", StringComparison.OrdinalIgnoreCase)) |
| 53 | + { |
| 54 | + ortEnv.RegisterExecutionProviderLibrary("NvTensorRTRTXExecutionProvider", ep_path); |
| 55 | + } |
| 56 | + else |
| 57 | + { |
| 58 | + Console.WriteLine($"Warning: EP registration not supported for {ep}"); |
| 59 | + Console.WriteLine("Only 'cuda' and 'NvTensorRtRtx' support plug-in libraries."); |
| 60 | + return; |
| 61 | + } |
| 62 | + |
| 63 | + Console.WriteLine($"Registered {ep} successfully!"); |
| 64 | + } |
68 | 65 |
|
69 | 66 | /// <summary> |
70 | 67 | /// Get Config object and set EP-specific and search-specific options inside it |
|
0 commit comments