/// <summary> /// A helper method to construct a SessionOptions object for TensorRT execution. /// Use only if CUDA/TensorRT are installed and you have the onnxruntime package specific to this Execution Provider. /// </summary> /// <param name="deviceId"></param> /// <returns>A SessionsOptions() object configured for execution on deviceId</returns> public static SessionOptions MakeSessionOptionWithTensorrtProvider(int deviceId = 0) { CheckTensorrtExecutionProviderDLLs(); SessionOptions options = new SessionOptions(); try { options.AppendExecutionProvider_Tensorrt(deviceId); options.AppendExecutionProvider_CUDA(deviceId); return(options); } catch (Exception) { options.Dispose(); throw; } }
/// <summary> /// A helper method to construct a SessionOptions object for TensorRT execution provider. /// Use only if CUDA/TensorRT are installed and you have the onnxruntime package specific to this Execution Provider. /// </summary> /// <param name="trtProviderOptions">TensorRT EP provider options</param> /// <returns>A SessionsOptions() object configured for execution on provider options</returns> public static SessionOptions MakeSessionOptionWithTensorrtProvider(OrtTensorRTProviderOptions trtProviderOptions) { CheckTensorrtExecutionProviderDLLs(); SessionOptions options = new SessionOptions(); try { // Make sure that CUDA EP uses the same device id as TensorRT EP. options.AppendExecutionProvider_Tensorrt(trtProviderOptions); options.AppendExecutionProvider_CUDA(trtProviderOptions.GetDeviceId()); return(options); } catch (Exception) { options.Dispose(); throw; } }