/// <summary> /// Append SNPE or XNNPACK execution provider /// </summary> /// <param name="providerName">Execution provider to add. 'SNPE' or 'XNNPACK' are currently supported.</param> /// <param name="providerOptions">Optional key/value pairs to specify execution provider options.</param> public void AppendExecutionProvider(string providerName, Dictionary <string, string> providerOptions = null) { if (providerName != "SNPE" && providerName != "XNNPACK") { throw new NotSupportedException( "Only SNPE and XNNPACK execution providers can be enabled by this method."); } using (var cleanupList = new DisposableList <IDisposable>()) { string[] ep = { providerName }; // put in array so we can use ConvertNamesToUtf8 for everything var epArray = NativeOnnxValueHelper.ConvertNamesToUtf8(ep, n => n, cleanupList); if (providerOptions == null) { providerOptions = new Dictionary <string, string>(); } var keysArray = NativeOnnxValueHelper.ConvertNamesToUtf8( providerOptions.Keys.ToArray(), n => n, cleanupList); var valuesArray = NativeOnnxValueHelper.ConvertNamesToUtf8( providerOptions.Values.ToArray(), n => n, cleanupList); NativeApiStatus.VerifySuccess(NativeMethods.SessionOptionsAppendExecutionProvider( handle, epArray[0], keysArray, valuesArray, (UIntPtr)providerOptions.Count)); } }
/// <summary> /// Updates the configuration knobs of OrtCUDAProviderOptions that will eventually be used to configure a CUDA EP /// Please refer to the following on different key/value pairs to configure a CUDA EP and their meaning: /// https://www.onnxruntime.ai/docs/reference/execution-providers/CUDA-ExecutionProvider.html /// </summary> /// <param name="providerOptions">key/value pairs used to configure a CUDA Execution Provider</param> public void UpdateOptions(Dictionary <string, string> providerOptions) { using (var cleanupList = new DisposableList <IDisposable>()) { var keysArray = NativeOnnxValueHelper.ConvertNamesToUtf8(providerOptions.Keys.ToArray(), n => n, cleanupList); var valuesArray = NativeOnnxValueHelper.ConvertNamesToUtf8(providerOptions.Values.ToArray(), n => n, cleanupList); NativeApiStatus.VerifySuccess(NativeMethods.OrtUpdateCUDAProviderOptions(handle, keysArray, valuesArray, (UIntPtr)providerOptions.Count)); } }