microsoft / onnxruntime

ONNX Runtime: cross-platform, high performance ML inferencing and training accelerator
https://onnxruntime.ai
MIT License
14.34k stars 2.87k forks source link

Unable to build C# API for OpenVINO Execution Provider With VS2019 #4945

Open jbrownkramer opened 4 years ago

jbrownkramer commented 4 years ago

Describe the bug Following the instructions at the following URL fails in ways I'll describe in more detail further down: https://github.com/microsoft/onnxruntime/blob/master/docs/execution_providers/OpenVINO-ExecutionProvider.md#csharp-api

Urgency I want to do inference on the Integrated Intel GPU from C#

System information

To Reproduce

git clone --recursive https://github.com/Microsoft/onnxruntime
cd onnxruntime

.\build.bat --config Debug --build --use_openvino GPU_FP16 --cmake_generator "Visual Studio 16 2019" --build_csharp

yields

Error: C:/Users/josh/projects/onnxruntime/build/Windows/Debug is not a directory

Following the baseline CPU build instructions at https://github.com/microsoft/onnxruntime/blob/master/BUILD.md#windows I changed this to

.\build.bat --config RelWithDebInfo --build --use_openvino GPU_FP16 --cmake_generator "Visual Studio 16 2019" --build_csharp

which worked. Following the next line in the OpenVino instructions, I did:

msbuild csharp\OnnxRuntime.CSharp.proj /p:OrtPackageId=Microsoft.ML.OnnxRuntime.Openvino /p:Configuration=Debug /t:CreatePackage

which gave the following error:

FileNotFoundError: [Errno 2] No such file or directory: 'c:\\Users\\josh\\projects\\onnxruntime\\build\\Windows\\Debug\\Debug\\NativeNuget.nuspec'

I then changed this to

msbuild csharp\OnnxRuntime.CSharp.proj /p:OrtPackageId=Microsoft.ML.OnnxRuntime.Openvino /p:Configuration=RelWithDebInfo /t:CreatePackage

which gave the following error:

C:\Program Files\dotnet\sdk\3.1.401\Sdks\NuGet.Build.Tasks.Pack\build\NuGet.Build.Tasks.Pack.targets(198,5): error NU5026: The file 'c:\Users\josh\projects\onnxruntime\csharp\src\Microso
ft.ML.OnnxRuntime\bin\RelWithDebInfo\netstandard1.1\Microsoft.ML.OnnxRuntime.dll' to be packed was not found on disk. [c:\Users\josh\projects\onnxruntime\csharp\src\Microsoft.ML.OnnxRunt
ime\Microsoft.ML.OnnxRuntime.csproj

and that's where I'm stuck.

Expected behavior Creation of a Nuget package.

askhade commented 4 years ago

@jbrownkramer : instead of using the --build_csharp flag please try using --build_nuget instead. You should see the nuget packages (Managed and Native) in \nuget-artifacts

Prerequisites dotnet for building csharp bindings (https://dotnet.microsoft.com/download) nuget.exe for creating nuget package. (https://docs.microsoft.com/en-us/nuget/install-nuget-client-tools#nugetexe-cli) make sure nuget is added to the path.

This flag was added recently. I will update the documentation accordingly.

jbrownkramer commented 4 years ago

Some notes on what I've done since.

I added nuget and added the path.

I started from scratch. This time I couldn't build with the RelWithDebInfo config either. I think what happened was that I had previously done a test build from following the baseline CPU build instructions at https://github.com/microsoft/onnxruntime/blob/master/BUILD.md#windows , which caused a RelWithDebInfo to be created. When I started over, it was no longer there.

I compared the two command line strings and just tried removing the --build flag, which seems to have worked.

However, I then got a message that my version of openvino was unsupported. When I dug into this further, it turns out that CMakeLists.txt references an environment variable called INTEL_OPENVINO_DIR, which isn't set anywhere. I set it to my openvino path, and it seems to have gotten a lot further. It returned with a nonzero exit status. Looking for errors in the very long output, I see

C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.27.29110\include\xmemory(694,1): error C22
20: the following warning is treated as an error (compiling source file C:\Users\josh\projects\onnxruntime\onnxruntime\cor
e\providers\openvino\backend_utils.cc) [C:\Users\josh\projects\onnxruntime\build\Windows\Debug\onnxruntime_providers_openv
ino.vcxproj]
C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.27.29110\include\xmemory(1508): message :
see reference to function template instantiation 'void std::_Default_allocator_traits<_Alloc>::construct<_Ty,size_t&>(_All
oc &,_Objty *const ,size_t &)' being compiled [C:\Users\josh\projects\onnxruntime\build\Windows\Debug\onnxruntime_provider
s_openvino.vcxproj]
          with
          [
              _Alloc=std::allocator<char>,
              _Ty=char,
              _Objty=char
          ] (compiling source file C:\Users\josh\projects\onnxruntime\onnxruntime\core\providers\openvino\backend_utils.cc
  )

I run

msbuild csharp\OnnxRuntime.CSharp.proj /p:OrtPackageId=Microsoft.ML.OnnxRuntime.Openvino /p:Configuration=Debug /t:CreatePackage

and I get

C:\Program Files\dotnet\sdk\3.1.401\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(241,5): error NETSDK1004: Assets file 'c:\Users\josh\projects\onnxruntime\csharp\src\Microsoft.ML.OnnxRuntime\obj\project.assets.json' not found. Run a NuGet package restore to generate this fi
le. [c:\Users\josh\projects\onnxruntime\csharp\src\Microsoft.ML.OnnxRuntime\Microsoft.ML.OnnxRuntime.csproj]
jbrownkramer commented 4 years ago

To be clear, I was using

.\build.bat --config Debug --use_openvino GPU_FP16 --cmake_generator "Visual Studio 16 2019" --build_nuget

I got past the previous issue with

nuget restore csharp\src\Microsoft.ML.OnnxRuntime\Microsoft.ML.OnnxRuntime.csproj

Then I got this error

C:\Program Files\dotnet\sdk\3.1.401\Sdks\NuGet.Build.Tasks.Pack\build\NuGet.Build.Tasks.Pack.targets(198,5): error NU5026: The file 'c:\Users\josh\projects\onnxruntime\csharp\src\Microsoft.ML.OnnxRuntime\bin\Debug\netstandard1.1\Microsoft.ML.OnnxRuntime.dll' to be packed was not found on disk. [c:\Users\j
osh\projects\onnxruntime\csharp\src\Microsoft.ML.OnnxRuntime\Microsoft.ML.OnnxRuntime.csproj]
askhade commented 4 years ago

@jbrownkramer : Can you try building nuget packages for a vanilla onnxruntime build (.i.e without OpenVino). I am running into different issues trying to get the building working with Openvino on windows and therefore am not able to reproduce the issue you are seeing.

Building nuget packages should work on Windows as long as the onnxruntime native build is successful and you have the prereqs (dotnet and nuget) installed on you machine. If onnxruntime native build is successful then the build script will do nuget restore and other necessary steps required to build nuget package.

I would suggest you to start from a clean enlistment and try building nuget package for onnxruntime cpu provider first.

jbrownkramer commented 4 years ago

I was eventually able to build the nuget packages, but they weren't taking advantage of openvino. I opened a different issue here: https://github.com/microsoft/onnxruntime/issues/5011, where a particular build string and fix to a file were suggested. Again, I was able to build, but now I am getting an error that onnxruntime.dll can't be found, despite explicitly copying the DLL into the build directory.

stale[bot] commented 3 years ago

This issue has been automatically marked as stale due to inactivity and will be closed in 7 days if no further activity occurs. If further support is needed, please provide an update and/or more details.

mrsabhar commented 3 years ago

@jbrownkramer Did you able to get success in building nuget with OV?

natelowry commented 2 years ago

This release of the Intel fork worked for me. I just used their provided Nuget packages.

https://github.com/intel/onnxruntime/releases/tag/v4.0