Skip to content

Conversation

@yf711
Copy link
Contributor

@yf711 yf711 commented Oct 21, 2022

Description

  • Set C# OrtEnv log level to be a property (getter/setter equipped)
  • Add C/C++ API about updating ort env with custom log level to support the setter above (Following pybind implementation)
  • Add test case to verify logLevel property's getter & setter
  • Fill missing C apis to C# apilist (this is mandatory if those missing apis are earlier than yours)

Motivation and Context

  • For C++/Python, the log level can be adjusted via OrtEnv, and this feature is missing in C# binding

@yf711 yf711 marked this pull request as ready for review October 21, 2022 20:31
@yf711 yf711 requested a review from chilo-ms October 21, 2022 20:34
*
* \since Version 1.13.
*/
ORT_API2_STATUS(UpdateEnvWithCustomLogLevel, OrtLoggingLevel log_severity_level, _In_ const OrtEnv* ort_env);
Copy link
Contributor

@pranavsharma pranavsharma Oct 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can't really have OrtEnv passed as const when you've an API to update it :-).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing out! That has been fixed

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, add C++ API so users do not have to go to C back and forth.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

C++ API has been added in latest commit as well. Thanks!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One important thing to mention is thread-safety. Typically, we do not update the environment after the creation and any thread or even multiple sessions can use it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One important thing to mention is thread-safety. Typically, we do not update the environment after the creation and any thread or even multiple sessions can use it.

Really appreciate the context you shared. The reason adding this env_update feature is this feature exists in Pybind but missing in c# binding, and we would like to unify the user experience and provide the ability to adjust default logger

This feature reuses the existing design in Pybind:set_default_logger_severity. Do you have any suggestions in order to improve this design?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand. One thing to note, we usually pass the object ptr as a first argument, as you can see in other examples. Please, adjust.

public IntPtr ReleaseKernelInfo;

public IntPtr GetTrainingApi;
public IntPtr SessionOptionsAppendExecutionProvider_CANN;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these CANN related declarations expected to be here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, as all newly added C APIs before mine would also need to be added here, so that the same order could be kept.

I initially learned from this previous commit to add additional APIs to keep order same as C APIs, and this was also mentioned in the code here

public LogLevel GetLogLevel()
{
return currentLogLevel;
}
Copy link
Member

@yuslepukhin yuslepukhin Oct 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is really needed, it should be a property. And you can then combine set/get #Resolved

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for sharing! This has been improved in the latest commit and verified in test case.

Copy link
Member

@yuslepukhin yuslepukhin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🕐

@yf711 yf711 requested a review from yuslepukhin November 4, 2022 16:41
API_IMPL_BEGIN
LoggingManager* default_logging_manager = ort_env->GetLoggingManager();
int severity_level = static_cast<int>(log_severity_level);
default_logging_manager->SetDefaultLoggerSeverity(static_cast<logging::Severity>(severity_level));
Copy link
Member

@yuslepukhin yuslepukhin Nov 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

default_logging_manager->SetDefaultLoggerSeverity(static_castlogging::Severity(severity_level));

Need to look at the thread-safety here #Resolved

Copy link
Member

@yuslepukhin yuslepukhin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@yf711 yf711 merged commit 8b9065a into main Nov 5, 2022
@yf711 yf711 deleted the test_c#_log branch November 5, 2022 04:46
simon-moo pushed a commit to simon-moo/onnxruntime that referenced this pull request Dec 21, 2022
### Description
* Add getter/setter to access and update C# OrtEnv log level
* Add C API about updating ort env with custom log level to support the
setter above (Following [pybind
implementation](https://github.com/microsoft/onnxruntime/blob/952c99304a764328070ac6c07f510deec06dedf4/onnxruntime/python/onnxruntime_pybind_state.cc#L923-L924))
* Add test case to verify getter & setter


### Motivation and Context
* For C++/Python, the log level can be adjusted via OrtEnv, and this
feature is missing in C# binding
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

Successfully merging this pull request may close these issues.

5 participants