Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Managed API: NativeMethods.OrtSetIntraOpNumThreads Crashes Application #4070

Closed
mejas opened this issue May 28, 2020 · 10 comments
Closed

Managed API: NativeMethods.OrtSetIntraOpNumThreads Crashes Application #4070

mejas opened this issue May 28, 2020 · 10 comments
Assignees

Comments

@mejas
Copy link

mejas commented May 28, 2020

Describe the bug
C# Application crashes without exception when setting SessionOptions.IntraOpNumThreads. This does not happen when building from source.

Urgency
High. This used to work back in 1.2.0

System information

  • Windows 10 1803
  • ONNX Runtime installed from (source or binary): nuget package
  • ONNX Runtime version: 1.3.0
  • Python version: 3.7.8
  • Visual Studio version (if applicable): 16.7 Preview 1.0
  • GCC/Compiler version (if compiling from source): Msbuild 16.7.0.22806
  • CUDA/cuDNN version: N/A
  • GPU model and memory: Intel HD Graphics

To Reproduce

  • Initialize InferenceSession object
  • Set IntraOpNumThreads to 1
  • Application crashes

Expected behavior
Application should not crash and create the InferenceSession object.

Additional context
This happens even when you don't have an ONNX model. See repro steps for procedure.

@snnn
Copy link
Member

snnn commented May 28, 2020

The official package has openmp. When you build from source by yourself I guess you didn't append "--use_openmp" to the build script?

@mejas
Copy link
Author

mejas commented May 28, 2020

The official package has openmp. When you build from source by yourself I guess you didn't append "--use_openmp" to the build script?

I did not append the OpenMP flag to the build script. Is this now a requirement for the runtime?

I used the following for building from source:
.\build.bat --config Release --build_shared_lib --parallel --build-csharp

I do find it odd that 1.2.0 did not have this problem. Upgrading to 1.3.0 was when the issue started to happen.

A little further digging around: using the 1.2.0 onnxruntime.dll does not cause the problem as well.

@snnn
Copy link
Member

snnn commented May 29, 2020

I was trying to explain the difference, why "This does not happen when building from source.".

If you can build it from source with

.\build.bat --config RelWithDebInfo --build_shared_lib --parallel --build-csharp --use_openmp

And repro the bug with newly built binary, it would be easier for us to know why it crashed.

Is this now a requirement for the runtime?

No. It is totally fine to live without it.

@mejas
Copy link
Author

mejas commented May 29, 2020

Thanks for the recommendation. I built from source with the switches you suggested and was able to replicate the crashing behavior.

Exact switch used:
.\build.bat --config RelWithDebInfo --build_shared_lib --parallel --build_csharp --use_openmp --cmake_generator "Visual Studio 16 2019"

Oddly enough there's no exceptions happening and just an explicit crash, but it does look like OpenMP is the culprit.

@pranavsharma
Copy link
Contributor

I used this sample code https://gist.github.com/pranavsharma/66186e986101022a7bb43201cd1e685e and tried it on my machine using the published pkg on Nuget and couldn't replicate. Here's my csproj file https://gist.github.com/pranavsharma/4d7d0b3964e0386295ed6362636452cf and I'm using

Microsoft Visual Studio Community 2019
Version 16.6.0
VisualStudio.16.Release/16.6.0+30114.105
Microsoft .NET Framework
Version 4.8.03752

@mejas
Copy link
Author

mejas commented May 29, 2020

Thanks @pranavsharma
I noticed that line 30 sets InterOpNumThreads and not IntraOpNumThreads
Could you try setting IntraOpNumThreads to 1?

@pranavsharma
Copy link
Contributor

Yes, I can repro.

@mejas
Copy link
Author

mejas commented May 29, 2020

Just to help a bit, I tried debugging deeper by enabling native code debugging in Visual Studio and found the following in the stack before the error was thrown:

image

The file in the stack is abi_session_options.cc

@pranavsharma
Copy link
Contributor

pranavsharma commented May 29, 2020

Btw, when openmp is enabled calling this method has no effect. So if this is blocking you, you can safely comment out the setting of options.IntraOpNumThreads in your C# code. The number of intra op threads are controlled using the openmp settings when openmp is enabled. See release notes https://github.com/microsoft/onnxruntime/releases/tag/v1.3.0.

@pranavsharma pranavsharma self-assigned this May 29, 2020
@mejas
Copy link
Author

mejas commented May 29, 2020

Thanks. I have commented out the code and proceeded with this as a temporary workaround.

pranavsharma added a commit that referenced this issue May 30, 2020
pranavsharma added a commit that referenced this issue Jun 1, 2020
* Fix crash reported in #4070.

* Add newline to warning message

* Add comment for using cout instead of the logger
stevenlix pushed a commit that referenced this issue Jun 14, 2020
* Fix crash reported in #4070.

* Add newline to warning message

* Add comment for using cout instead of the logger
stevenlix added a commit that referenced this issue Jun 15, 2020
* Fix deprecated CentOS link for Linux CI pipeline (#4000)

* Fix Linux_CI_GPU_Dev

* centos6

* Fix crash reported in #4070. (#4091)

* Fix crash reported in #4070.

* Add newline to warning message

* Add comment for using cout instead of the logger

* fix optional input/outputs (#4229)

Co-authored-by: Ryan Lai <[email protected]>
Co-authored-by: Pranav Sharma <[email protected]>
Co-authored-by: Tracy Sharpe <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants