/// <summary> /// Constructor. /// </summary> /// <param name="onnxFileName"></param> /// <param name="gpuID"></param> /// <param name="batchSize"></param> public NetExecutorONNXRuntime(string onnxFileName, int gpuID) { // if (gpuID < 0 || gpuID > 16) throw new Exception($"Invalid GPU ID { gpuID}"); #if CUDA if (gpuID == -999) // CPU. TO DO: clean this up { Session = new InferenceSession(onnxFileName); } else if (gpuID == -1) { Session = new InferenceSession(onnxFileName, SessionOptions.MakeSessionOptionWithCudaProvider()); } else { #if NOT //Yields error: Unable to find an entry point named 'OrtSessionOptionsAppendExecutionProvider_Tensorrt' in DLL 'onnxruntime'. SessionOptions options = new SessionOptions(); options.AppendExecutionProvider_Tensorrt(gpuID); // options.AppendExecutionProvider_CUDA(); Session = new InferenceSession(onnxFileName, options); #endif Session = new InferenceSession(onnxFileName, SessionOptions.MakeSessionOptionWithCudaProvider(gpuID)); } #else Session = new InferenceSession(onnxFileName); #endif GPUID = gpuID; }
public void TestSessionOptions() { using (SessionOptions opt = new SessionOptions()) { Assert.NotNull(opt); // check default values of the properties Assert.True(opt.EnableSequentialExecution); Assert.True(opt.EnableMemoryPattern); Assert.False(opt.EnableProfiling); Assert.Equal("onnxruntime_profile_", opt.ProfileOutputPathPrefix); Assert.True(opt.EnableCpuMemArena); Assert.Equal("", opt.LogId); Assert.Equal(LogLevel.Verbose, opt.LogVerbosityLevel); Assert.Equal(0, opt.IntraOpNumThreads); Assert.Equal(0, opt.InterOpNumThreads); Assert.Equal(GraphOptimizationLevel.ORT_ENABLE_BASIC, opt.GraphOptimizationLevel); // try setting options opt.EnableSequentialExecution = false; Assert.False(opt.EnableSequentialExecution); opt.EnableMemoryPattern = false; Assert.False(opt.EnableMemoryPattern); opt.EnableProfiling = true; Assert.True(opt.EnableProfiling); Assert.Equal("onnxruntime_profile_", opt.ProfileOutputPathPrefix); opt.ProfileOutputPathPrefix = "Ort_P_"; Assert.Equal("Ort_P_", opt.ProfileOutputPathPrefix); opt.EnableCpuMemArena = false; Assert.False(opt.EnableCpuMemArena); opt.LogId = "MyLogId"; Assert.Equal("MyLogId", opt.LogId); opt.LogVerbosityLevel = LogLevel.Error; Assert.Equal(LogLevel.Error, opt.LogVerbosityLevel); opt.IntraOpNumThreads = 4; Assert.Equal(4, opt.IntraOpNumThreads); opt.InterOpNumThreads = 4; Assert.Equal(4, opt.InterOpNumThreads); opt.GraphOptimizationLevel = GraphOptimizationLevel.ORT_ENABLE_EXTENDED; Assert.Equal(GraphOptimizationLevel.ORT_ENABLE_EXTENDED, opt.GraphOptimizationLevel); Assert.Throws <OnnxRuntimeException>(() => { opt.GraphOptimizationLevel = (GraphOptimizationLevel)10; }); opt.AppendExecutionProvider_CPU(1); #if USE_MKLDNN opt.AppendExecutionProvider_Mkldnn(0); #endif #if USE_CUDA opt.AppendExecutionProvider_CUDA(0); #endif #if USE_NGRAPH opt.AppendExecutionProvider_NGraph("CPU"); //TODO: this API should be refined #endif #if USE_OPENVINO opt.AppendExecutionProvider_OpenVINO(null); //TODO: this won't work, because the native side copies the const char* #endif #if USE_TENSORRT opt.AppendExecutionProvider_Tensorrt(0); #endif #if USE_NNAPI opt.AppendExecutionProvider_Nnapi(); #endif } }