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

Expose build information in dynamic lib #15643

Merged
merged 11 commits into from
Apr 29, 2023

Conversation

guoyuhong
Copy link
Contributor

@guoyuhong guoyuhong commented Apr 22, 2023

Description

  1. Add Build Info API to onnx.
  2. Fix compile error while building onnxruntime_benchmark in MacOs.

Motivation and Context

  1. When Onnxruntime lib is serving online, we need a way to detect how this lib is built. This PR helps the developer to get the build information using strings such as git branch, git commit id, build type and cmake cxx flags, which is showed as follows.

image

image

If the build env has no git, there will be no git related infor:

image

  1. Fix the following compile error while building benchmark in MacOs.
    image

@guoyuhong
Copy link
Contributor Author

@microsoft-github-policy-service agree

@@ -1229,6 +1229,15 @@ if (onnxruntime_USE_VITISAI)
endif()
endif()

execute_process(COMMAND git log -1 --format=%h
Copy link
Member

Choose a reason for hiding this comment

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

Some of our build environments do not have git. So this would not work.

Copy link
Contributor Author

@guoyuhong guoyuhong Apr 24, 2023

Choose a reason for hiding this comment

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

@snnn It does not matter whether the build envs have git or not. The cmake command won't fail. Instead, it will output to the variable ORT_GIT_COMMIT & ORT_GIT_BRANCH with an empty string. To make this clearer, I added a comment here and explicitly change the empty string to "Not-Available". An example is showed below:

image

Copy link
Member

Choose a reason for hiding this comment

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

But it will be very confusing that users find our APIs has a function "GetBuildInfoString" but it always returns empty? Most users do not build onnxruntime from source. They use our prebuilt packages from nuget.org or the github release page.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@snnn I have reverted the change related to git in cmake/onnxruntime_config.h.in. For GetBuildInfoString in envs that has no git, it will returns the build type and cxx flags as follows. If the env has git, it will contain more information. Is it better?
I have also reverted the change in tuning_context_impl.h since the commit id requires git.
image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@snnn Do you have more comments on this PR?

snnn
snnn previously requested changes Apr 24, 2023
Copy link
Member

@snnn snnn left a comment

Choose a reason for hiding this comment

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

No git.

}

Status TuningResultsValidator::ValidateOrtGitCommit(const std::string& value) const {
// TODO:
ORT_UNUSED_PARAMETER(value);
ORT_RETURN_IF(value != ORT_GIT_COMMIT, "onnxruntime git commit mismatch");
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@snnn As you said there could be build envs that have no git, is it better to revert this change for ValidateOrtGitCommit ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Never mind, reverted.

@@ -1229,6 +1229,15 @@ if (onnxruntime_USE_VITISAI)
endif()
endif()

execute_process(COMMAND git log -1 --format=%h
Copy link
Contributor Author

@guoyuhong guoyuhong Apr 24, 2023

Choose a reason for hiding this comment

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

@snnn It does not matter whether the build envs have git or not. The cmake command won't fail. Instead, it will output to the variable ORT_GIT_COMMIT & ORT_GIT_BRANCH with an empty string. To make this clearer, I added a comment here and explicitly change the empty string to "Not-Available". An example is showed below:

image

/// git commit id, build type(Debug/Release/RelWithDebInfo) and cmake cpp flags.
/// </summary>
/// <returns>string</returns>
std::string GetBuildInfoString();
Copy link
Member

Choose a reason for hiding this comment

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

It would be helpful to make it available in the python bindings as well. Any test to check its value?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a good point. I will take a look at how to add the python binding and the test to cover.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@xadupre I have added the build info to python bindings. The figure below shows the effect by some temporary code.
image

@snnn
Copy link
Member

snnn commented Apr 26, 2023

All API changes need to be reviewed by him.

pranavsharma
pranavsharma previously approved these changes Apr 26, 2023
@@ -1229,6 +1229,19 @@ if (onnxruntime_USE_VITISAI)
endif()
endif()

set(ORT_BUILD_INFO "ORT Build Info: ")
find_package(Git)
Copy link
Member

Choose a reason for hiding this comment

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

All ONNX Runtime's build pipelines are hosted on Azure DevOps, which already expose this information through environment variables. https://learn.microsoft.com/en-us/azure/devops/pipelines/build/variables?view=azure-devops&tabs=yaml . The name of the env var is: "BUILD_SOURCEVERSION".
cmake can read env vars:
https://cmake.org/cmake/help/latest/variable/ENV.html

So we can add an if there to test the variable exists or not first. Then only run "find_package(Git)" when the env doesn't exist.

You don't have to make this enhancement for us. I just want to speak it out.

Copy link
Member

Choose a reason for hiding this comment

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

If from the beginning we were very strict on this, we won't see such an issue: #15678

Copy link
Contributor Author

@guoyuhong guoyuhong Apr 27, 2023

Choose a reason for hiding this comment

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

If from the beginning we were very strict on this, we won't see such an issue: #15678

By this, you mean the ORTCHAR_T* problem, right? Yes, I have changed const char * to const ORTCHAR_T *

@@ -619,7 +619,8 @@ struct OrtApiBase {
* older than the version created with this header file.
*/
const OrtApi*(ORT_API_CALL* GetApi)(uint32_t version)NO_EXCEPTION;
const char*(ORT_API_CALL* GetVersionString)(void)NO_EXCEPTION; ///< Returns a null terminated string of the version of the Onnxruntime library (eg: "1.8.1")
const char*(ORT_API_CALL* GetVersionString)(void)NO_EXCEPTION; ///< Returns a null terminated string of the version of the Onnxruntime library (eg: "1.8.1")
Copy link
Member

Choose a reason for hiding this comment

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

In general we should use const ORTCHAR_T* instead of const char*, because on Windows usually we prefer to use wide char.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. GetVersionString is originally defined using char *. I will change both.

@snnn
Copy link
Member

snnn commented Apr 27, 2023

LGTM.

I hope the "const char*" could be changed to "const ORTCHAR_T*" to avoid confusion.

@HectorSVC
Copy link
Contributor

/azp run Linux CPU CI Pipeline, Linux CPU Minimal Build E2E CI Pipeline, Linux GPU CI Pipeline, Linux GPU TensorRT CI Pipeline, Linux OpenVINO CI Pipeline, Linux QNN CI Pipeline, MacOS CI Pipeline, ONNX Runtime Web CI Pipeline, Windows ARM64 QNN CI Pipeline

@azure-pipelines
Copy link

Azure Pipelines successfully started running 9 pipeline(s).

@HectorSVC
Copy link
Contributor

/azp run Windows CPU CI Pipeline, Windows GPU CI Pipeline, Windows GPU TensorRT CI Pipeline, onnxruntime-binary-size-checks-ci-pipeline, orttraining-linux-ci-pipeline, orttraining-linux-gpu-ci-pipeline, orttraining-ortmodule-distributed

@azure-pipelines
Copy link

Azure Pipelines successfully started running 7 pipeline(s).

@linkerzhang
Copy link
Contributor

Ahahaha, a good try to communicae with Microsoft ORT team. Antgroup will try to contribute more back to ORT based on what we did during last years. ORT rocks!

@HectorSVC
Copy link
Contributor

/azp run Linux CPU CI Pipeline, Linux CPU Minimal Build E2E CI Pipeline, Linux GPU CI Pipeline, Linux GPU TensorRT CI Pipeline, Linux OpenVINO CI Pipeline, Linux QNN CI Pipeline, MacOS CI Pipeline, ONNX Runtime Web CI Pipeline, Windows ARM64 QNN CI Pipeline

@azure-pipelines
Copy link

Azure Pipelines successfully started running 7 pipeline(s).

@snnn
Copy link
Member

snnn commented Apr 28, 2023

/azp run Windows CPU CI Pipeline, Windows GPU CI Pipeline, Windows GPU TensorRT CI Pipeline, onnxruntime-binary-size-checks-ci-pipeline, orttraining-linux-ci-pipeline, orttraining-linux-gpu-ci-pipeline, orttraining-ortmodule-distributed

@snnn
Copy link
Member

snnn commented Apr 28, 2023

/azp run Linux CPU CI Pipeline, Linux CPU Minimal Build E2E CI Pipeline, Linux GPU CI Pipeline, Linux GPU TensorRT CI Pipeline, Linux OpenVINO CI Pipeline, Linux QNN CI Pipeline, MacOS CI Pipeline, ONNX Runtime Web CI Pipeline, Windows ARM64 QNN CI Pipeline

@azure-pipelines
Copy link

Azure Pipelines successfully started running 7 pipeline(s).

@azure-pipelines
Copy link

Azure Pipelines successfully started running 9 pipeline(s).

assert(version != NULL);
#ifdef _WIN32
size_t len = wcslen(version);
jstring versionStr = (*jniEnv)->NewString(jniEnv, (const jchar*)version, len);
Copy link
Member

Choose a reason for hiding this comment

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

If I remember correctly, Java use UTF-16-BE while most Windows use UTF-16-LE. @Craigacp, is it true?

Copy link
Contributor

Choose a reason for hiding this comment

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

We don't transform the output of jstring->GetStringChars to change UTF-16 endianness on Windows, and it can load & save things to those paths correctly. So I would expect it to be the same on platforms that we currently test in the CI. If it's the same on all platforms is beyond my knowledge of Windows. It should be straightforward to modify https://github.com/microsoft/onnxruntime/blob/main/java/src/test/java/ai/onnxruntime/InferenceTest.java#L74 to test that the output is correct. I haven't modified that test to check the string because it'll need updating every time the version number is bumped so it seems like it would fail a bunch of pipelines.

@snnn
Copy link
Member

snnn commented Apr 28, 2023

/azp run Linux CPU CI Pipeline, Linux CPU Minimal Build E2E CI Pipeline, Linux GPU CI Pipeline, Linux GPU TensorRT CI Pipeline, Linux OpenVINO CI Pipeline, Linux QNN CI Pipeline, MacOS CI Pipeline, ONNX Runtime Web CI Pipeline, Windows ARM64 QNN CI Pipeline

@snnn
Copy link
Member

snnn commented Apr 28, 2023

/azp run Windows CPU CI Pipeline, Windows GPU CI Pipeline, Windows GPU TensorRT CI Pipeline, onnxruntime-binary-size-checks-ci-pipeline, orttraining-linux-ci-pipeline, orttraining-linux-gpu-ci-pipeline, orttraining-ortmodule-distributed

@azure-pipelines
Copy link

Azure Pipelines successfully started running 9 pipeline(s).

@azure-pipelines
Copy link

Azure Pipelines successfully started running 7 pipeline(s).

@snnn
Copy link
Member

snnn commented Apr 29, 2023

/azp run Windows CPU CI Pipeline, Windows GPU CI Pipeline, Windows GPU TensorRT CI Pipeline, onnxruntime-binary-size-checks-ci-pipeline, orttraining-linux-ci-pipeline, orttraining-linux-gpu-ci-pipeline, orttraining-ortmodule-distributed

@snnn
Copy link
Member

snnn commented Apr 29, 2023

/azp run Linux CPU CI Pipeline, Linux CPU Minimal Build E2E CI Pipeline, Linux GPU CI Pipeline, Linux GPU TensorRT CI Pipeline, Linux OpenVINO CI Pipeline, Linux QNN CI Pipeline, MacOS CI Pipeline, ONNX Runtime Web CI Pipeline, Windows ARM64 QNN CI Pipeline

@azure-pipelines
Copy link

Azure Pipelines successfully started running 7 pipeline(s).

@azure-pipelines
Copy link

Azure Pipelines successfully started running 9 pipeline(s).

@HectorSVC HectorSVC merged commit 41dcf0d into microsoft:main Apr 29, 2023
@guoyuhong guoyuhong deleted the gyh_build_info branch April 29, 2023 12:20
@guoyuhong
Copy link
Contributor Author

Thanks to @snnn @HectorSVC for your patience. :-)

@snnn
Copy link
Member

snnn commented May 1, 2023

Happy holidays!

ShukantPal pushed a commit to ShukantPal/onnxruntime that referenced this pull request May 7, 2023
### Description
<!-- Describe your changes. -->
1. Add Build Info API to onnx.
2. Fix compile error while building onnxruntime_benchmark in MacOs.


### Motivation and Context
<!-- - Why is this change required? What problem does it solve?
- If it fixes an open issue, please link to the issue here. -->
1. When Onnxruntime lib is serving online, we need a way to detect how
this lib is built. This PR helps the developer to get the build
information using `strings` such as git branch, git commit id, build
type and cmake cxx flags, which is showed as follows.


![image](https://user-images.githubusercontent.com/19584326/233794371-b2f95a2c-27fb-4709-a6dd-bf4bb12b0b5b.png)


![image](https://user-images.githubusercontent.com/19584326/233794360-f96f5d2e-332c-405c-83f1-370ccc2b86f8.png)

If the build env has no git, there will be no git related infor:


![image](https://user-images.githubusercontent.com/19584326/234558596-298c1b01-9a90-41bf-9372-7259a8f8e5be.png)


3. Fix the following compile error while building benchmark in MacOs.

![image](https://user-images.githubusercontent.com/19584326/233793571-c261ac1f-47b2-434d-a293-7e9edc6c8a66.png)

---------

Co-authored-by: Yuhong Guo <yuhong.gyh@antgroup.com>
@yuslepukhin
Copy link
Member

What is the reason why simple version information is being returned as ORTTCHAR instead of UTF-8 as all other strings inside ORT? That typedef was introduced for paths, otherwise all strings are expected to contain UTF-8. It is just makes coding so much more complicated for what essentially is a stupid version string.

yuslepukhin added a commit that referenced this pull request May 13, 2023
…m to OrtApi (#15921)

### Description

This PR partially reverts changes introduced in
#15643

We make two API return std::string always in UTF-8.

We also move the entry points from OrtApiBase to OrtApi to make them
versioned.

### Motivation and Context

`GetVersionString` always returns x.y.z numbers that are not subject to
internationalization.
`GetBuildInfoString` can hold international chars, but UTF-8 should be
fine to contain those.
We prefix them with u8"" in case the compiler default charset is not
UTF-8.
Furthermore, creating platform dependent APIs is discouraged.
`ORTCHAR_T` is platform dependent and was created for paths only.
On non-unix platforms would still produce `std::string` that can only
contain UTF-8

The API was introduced after the latest release, and can still be
adjusted.
@guoyuhong
Copy link
Contributor Author

@yuslepukhin Sorry for the inconvenience. I just followed the comment from @snnn , and not expected that would bring so much trouble. I learned that "We define all strings as UTF-8 internally, except Windows paths.". Thanks.

prathikr pushed a commit that referenced this pull request May 16, 2023
…m to OrtApi (#15921)

### Description

This PR partially reverts changes introduced in
#15643

We make two API return std::string always in UTF-8.

We also move the entry points from OrtApiBase to OrtApi to make them
versioned.

### Motivation and Context

`GetVersionString` always returns x.y.z numbers that are not subject to
internationalization.
`GetBuildInfoString` can hold international chars, but UTF-8 should be
fine to contain those.
We prefix them with u8"" in case the compiler default charset is not
UTF-8.
Furthermore, creating platform dependent APIs is discouraged.
`ORTCHAR_T` is platform dependent and was created for paths only.
On non-unix platforms would still produce `std::string` that can only
contain UTF-8

The API was introduced after the latest release, and can still be
adjusted.
snnn pushed a commit that referenced this pull request May 19, 2023
…m to OrtApi (#15921)

This PR partially reverts changes introduced in
#15643

We make two API return std::string always in UTF-8.

We also move the entry points from OrtApiBase to OrtApi to make them
versioned.

`GetVersionString` always returns x.y.z numbers that are not subject to
internationalization.
`GetBuildInfoString` can hold international chars, but UTF-8 should be
fine to contain those.
We prefix them with u8"" in case the compiler default charset is not
UTF-8.
Furthermore, creating platform dependent APIs is discouraged.
`ORTCHAR_T` is platform dependent and was created for paths only.
On non-unix platforms would still produce `std::string` that can only
contain UTF-8

The API was introduced after the latest release, and can still be
adjusted.
snnn pushed a commit that referenced this pull request May 19, 2023
…m to OrtApi (#15921)

This PR partially reverts changes introduced in
#15643

We make two API return std::string always in UTF-8.

We also move the entry points from OrtApiBase to OrtApi to make them
versioned.

`GetVersionString` always returns x.y.z numbers that are not subject to
internationalization.
`GetBuildInfoString` can hold international chars, but UTF-8 should be
fine to contain those.
We prefix them with u8"" in case the compiler default charset is not
UTF-8.
Furthermore, creating platform dependent APIs is discouraged.
`ORTCHAR_T` is platform dependent and was created for paths only.
On non-unix platforms would still produce `std::string` that can only
contain UTF-8

The API was introduced after the latest release, and can still be
adjusted.
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.

None yet

8 participants